diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 403b3f96..c0dcd377 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -5,6 +5,7 @@ use Engelsystem\Models\User\State; use Engelsystem\Models\User\User; use Engelsystem\ShiftCalendarRenderer; use Engelsystem\ShiftsFilter; +use Illuminate\Database\Eloquent\Collection; /** * Route user actions. @@ -267,15 +268,16 @@ function users_list_controller() $order_by = 'name'; if ($request->has('OrderBy') && in_array($request->input('OrderBy'), [ 'name', - 'last_name', 'first_name', + 'last_name', 'dect', - 'email', - 'shirt_size', 'arrived', + 'got_voucher', + 'freeloads', 'active', 'force_active', 'got_shirt', + 'shirt_size', 'planned_arrival_date', 'planned_departure_date', 'last_login_at', @@ -283,15 +285,24 @@ function users_list_controller() $order_by = $request->input('OrderBy'); } - /** @var User[] $users */ + /** @var User[]|Collection $users */ $users = User::with(['contact', 'personalData', 'state']) - ->orderBy($order_by) ->orderBy('name') ->get(); foreach ($users as $user) { $user->setAttribute('freeloads', count(ShiftEntries_freeloaded_by_user($user->id))); } + $users = $users->sortBy(function (User $user) use ($order_by) { + $userData = $user->toArray(); + $data = []; + array_walk_recursive($userData, function ($value, $key) use (&$data) { + $data[$key] = $value; + }); + + return isset($data[$order_by]) ? $data[$order_by] : null; + }); + return [ __('All users'), Users_view( diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 4cf28e29..df06bf02 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -231,7 +231,7 @@ function Users_view( } $user_table_headers['arrived'] = Users_table_header_link('arrived', __('Arrived'), $order_by); $user_table_headers['got_voucher'] = Users_table_header_link('got_voucher', __('Voucher'), $order_by); - $user_table_headers['freeloads'] = __('Freeloads'); + $user_table_headers['freeloads'] = Users_table_header_link('freeloads', __('Freeloads'), $order_by); $user_table_headers['active'] = Users_table_header_link('active', __('Active'), $order_by); $user_table_headers['force_active'] = Users_table_header_link('force_active', __('Forced'), $order_by); $user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by);