Skip to content

Commit

Permalink
fix: correct ordering of contacts based on preferred displaying of na…
Browse files Browse the repository at this point in the history
…mes (#6962)

Co-authored-by: Alexis Saettler <[email protected]>
  • Loading branch information
SecurID and asbiin authored Oct 28, 2023
1 parent 1b351e4 commit a46e92b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

use function Safe\preg_replace;

class ContactController extends Controller
{
public function index(Request $request, Vault $vault)
{
$contacts = $vault->contacts()
->where('listed', true);

$column_to_order = preg_replace('/^%([a-z_]+)%.*$/', '$1', Auth::user()->name_order);

switch (Auth::user()->contact_sort_order) {
case User::CONTACT_SORT_ORDER_ASC:
$contacts = $contacts->orderBy('last_name', 'asc');
$contacts = $contacts->orderBy($column_to_order, 'asc');
break;
case User::CONTACT_SORT_ORDER_DESC:
$contacts = $contacts->orderBy('last_name', 'desc');
$contacts = $contacts->orderBy($column_to_order, 'desc');
break;
default:
$contacts = $contacts->orderBy('last_updated_at', 'desc');
Expand Down

0 comments on commit a46e92b

Please sign in to comment.