belongsTo(Account::class); } /** * Get the contact record associated with the activity. * * @return BelongsToMany */ public function contacts() { return $this->belongsToMany(Contact::class); } /** * Get the activity type record associated with the activity. * * @return BelongsTo */ public function type() { return $this->belongsTo(ActivityType::class, 'activity_type_id'); } /** * Return the markdown parsed body. * * @return string|null */ public function getParsedContentAttribute() { if (is_null($this->description)) { return; } return (new Parsedown())->text($this->description); } /** * Get the summary for this activity. * * @return string or null */ public function getSummary() { return $this->summary; } /** * Get the description for this activity. * * @return string or null */ public function getDescription() { return $this->description; } /** * Get the key of the title of the activity. * * @return string or null */ public function getTitle() { return $this->type ? $this->type->key : null; } /** * Get all the contacts this activity is associated with. */ public function getContactsForAPI() { $attendees = collect([]); foreach ($this->contacts as $contact) { if ($contact->account_id !== $this->account_id) { // This should not be possible! continue; } $attendees->push(new ContactShortResource($contact)); } return $attendees; } /** * Gets the information about the activity for the journal. * @return array */ public function getInfoForJournalEntry() { return [ 'type' => 'activity', 'id' => $this->id, 'activity_type' => (! is_null($this->type) ? $this->type->name : null), 'summary' => $this->summary, 'description' => $this->description, 'day' => $this->date_it_happened->day, 'day_name' => mb_convert_case(DateHelper::getShortDay($this->date_it_happened), MB_CASE_TITLE, 'UTF-8'), 'month' => $this->date_it_happened->month, 'month_name' => mb_convert_case(DateHelper::getShortMonth($this->date_it_happened), MB_CASE_UPPER, 'UTF-8'), 'year' => $this->date_it_happened->year, 'attendees' => $this->getContactsForAPI(), ]; } }