in app/Http/Controllers/ContactsController.php [241:321]
public function show(Contact $contact)
{
// make sure we don't display a partial contact
if ($contact->is_partial) {
$realContact = $contact->getRelatedRealContact();
if (is_null($realContact)) {
return redirect()->route('people.index')
->withErrors(trans('people.people_not_found'));
}
return redirect()->route('people.show', $realContact);
}
$contact->load(['notes' => function ($query) {
$query->orderBy('updated_at', 'desc');
}]);
UpdateLastConsultedDate::dispatch($contact);
$relationships = $contact->relationships;
// get love relationship type
$loveRelationships = $relationships->filter(function ($item) {
return $item->relationshipType->relationshipTypeGroup->name == 'love';
});
// get family relationship type
$familyRelationships = $relationships->filter(function ($item) {
return $item->relationshipType->relationshipTypeGroup->name == 'family';
});
// get friend relationship type
$friendRelationships = $relationships->filter(function ($item) {
return $item->relationshipType->relationshipTypeGroup->name == 'friend';
});
// get work relationship type
$workRelationships = $relationships->filter(function ($item) {
return $item->relationshipType->relationshipTypeGroup->name == 'work';
});
// reminders
$reminders = $contact->activeReminders;
$relevantRemindersFromRelatedContacts = $contact->getBirthdayRemindersAboutRelatedContacts();
$reminders = $reminders->merge($relevantRemindersFromRelatedContacts);
// now we need to sort the reminders by next date they will be triggered
foreach ($reminders as $reminder) {
$next_expected_date = $reminder->calculateNextExpectedDateOnTimezone();
$reminder->next_expected_date_human_readable = DateHelper::getShortDate($next_expected_date);
$reminder->next_expected_date = DateHelper::getDate($next_expected_date);
}
$reminders = $reminders->sortBy('next_expected_date');
// list of active features
$modules = $contact->account->modules()->active()->get();
// add `---` at the top of the dropdowns
$days = DateHelper::getListOfDays();
$days->prepend([
'id' => 0,
'name' => '---',
]);
$months = DateHelper::getListOfMonths();
$months->prepend([
'id' => 0,
'name' => '---',
]);
$hasReachedAccountStorageLimit = StorageHelper::hasReachedAccountStorageLimit($contact->account);
$accountHasLimitations = AccountHelper::hasLimitations($contact->account);
return view('people.profile')
->withHasReachedAccountStorageLimit($hasReachedAccountStorageLimit)
->withAccountHasLimitations($accountHasLimitations)
->withLoveRelationships($loveRelationships)
->withFamilyRelationships($familyRelationships)
->withFriendRelationships($friendRelationships)
->withWorkRelationships($workRelationships)
->withReminders($reminders)
->withModules($modules)
->withContact($contact)
->withWeather($contact->getWeather())
->withDays($days)
->withMonths($months)
->withYears(DateHelper::getListOfYears());
}