Skip to content

Commit

Permalink
feat: order introductions contact list by first and last name (#5102)
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly authored Jan 1, 2022
1 parent 8295be3 commit 6ff0738
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Contacts/IntroductionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function edit(Contact $contact)
$contacts = $contact->siblingContacts()
->real()
->active()
->orderByUserPreference()
->paginate(20);

$introducer = $contact->getIntroducer();
Expand Down
45 changes: 45 additions & 0 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,51 @@ public function scopeAddressBook($query, int $accountId = null, string $addressB
return $query->where('address_book_id', $addressBook ? $addressBook->id : null);
}

/**
* Get contacts ordered by user preferences.
*
* @param Builder $query
* @return Builder
*/
public function scopeOrderByUserPreference(Builder $query): Builder
{
switch (Auth::user()->name_order) {
case 'firstname_lastname':
$query = $query->orderBy('first_name')
->orderBy('last_name');
break;
case 'firstname_lastname_nickname':
$query = $query->orderBy('first_name')
->orderBy('last_name')
->orderBy('nickname');
break;
case 'firstname_nickname_lastname':
$query = $query->orderBy('first_name')
->orderBy('nickname')
->orderBy('last_name');
break;
case 'nickname':
$query = $query->orderBy('nickname');
break;
case 'lastname_firstname':
$query = $query->orderBy('last_name')
->orderby('first_name');
break;
case 'lastname_firstname_nickname':
$query = $query->orderBy('last_name')
->orderby('first_name')
->orderby('nickname');
break;
case 'lastname_nickname_firstname':
$query = $query->orderBy('last_name')
->orderby('nickname')
->orderby('first_name');
break;
}

return $query;
}

/**
* Mutator first_name.
* Get the first name of the contact.
Expand Down

0 comments on commit 6ff0738

Please sign in to comment.