Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix getting birthday reminders about related contacts #2254

Merged
merged 2 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Enhancements:

Fixes:

* Fix getting birthday reminders about related contacts
* Fix default temperature scale setting
* Fix API methods for Occupation object
* Fix activity date viewed as one day before the event happened
Expand Down
27 changes: 17 additions & 10 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1412,10 +1412,12 @@ public function removeSpecialDate($occasion)
*/
public function getRelationshipNatureWith(self $otherContact)
{
return Relationship::where('account_id', $this->account_id)
->where('contact_is', $this->id)
->where('of_contact', $otherContact->id)
->first();
return Relationship::where([
'account_id' => $this->account_id,
'contact_is' => $this->id,
'of_contact' => $otherContact->id,
])
->first();
}

/**
Expand Down Expand Up @@ -1454,11 +1456,12 @@ public function deleteEverything()
*/
public function getBirthdayRemindersAboutRelatedContacts()
{
$reminders = collect();
$relationships = $this->relationships->filter(function ($item) {
return ! is_null($item->ofContact->birthday_special_date_id);
return ! is_null($item->ofContact) &&
! is_null($item->ofContact->birthday_special_date_id);
});

$reminders = collect();
foreach ($relationships as $relationship) {
$reminder = Reminder::where('account_id', $this->account_id)
->find($relationship->ofContact->birthdate->reminder_id);
Expand All @@ -1477,12 +1480,16 @@ public function getBirthdayRemindersAboutRelatedContacts()
*/
public function getRelatedRealContact()
{
$account = $this;
$contact = $this;

return self::setEagerLoads([])->where('account_id', $this->account_id)
->where('id', function ($query) use ($account) {
$query->select('of_contact')->from('relationships')->where('account_id', $account->account_id)
->where('contact_is', $account->id);
->where('id', function ($query) use ($contact) {
$query->select('of_contact')
->from('relationships')
->where([
'account_id' => $contact->account_id,
'contact_is' => $contact->id,
]);
})
->first();
}
Expand Down