users.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. if(Core::$user->level == User::LEVEL_SUPERADMIN) {
  3. $page_title = "Users";
  4. }
  5. else {
  6. $page_title = "Testers";
  7. }
  8. Core::addBreadcrumb("/account", "Account");
  9. Core::addBreadcrumb("/account/users", $page_title);
  10. $sorts = [
  11. "newest" => "Newest",
  12. "score" => "Score",
  13. ];
  14. $id = http::value("id", "int");
  15. $first_name = http::value("first_name", "trim");
  16. $last_name = http::value("last_name", "trim");
  17. $archived = Http::value("archived", "int") ?? 0;
  18. $email = http::value("email", "trim");
  19. $level = http::value("level", "int");
  20. $customer_id = http::value("customer_id", "int");
  21. $location_id = http::value("location_id", "int");
  22. $has_driving_licence = HTTP::value("has_driving_licence", "int");
  23. $has_car = HTTP::value("has_car", "int");
  24. $nvp = [];
  25. if($id !== null) $nvp["id"] = $id;
  26. if(strlen($first_name) > 0) $nvp["first_name"] = ((new Constraint("CONTAINS"))->setValues($first_name));
  27. if(strlen($last_name) > 0) $nvp["last_name"] = ((new Constraint("CONTAINS"))->setValues($last_name));
  28. if(strlen($email) > 0) $nvp["email"] = $email;
  29. if($level !== null) $nvp["level"] = $level;
  30. if(!$archived) $nvp["archived"] = 0;
  31. if($has_driving_licence) $nvp["has_driving_licence"] = 1;
  32. if($has_car) $nvp["has_car"] = 1;
  33. $filter_count = null;
  34. if($nvp) {
  35. $filter_count = count(array_keys($nvp));
  36. }
  37. if(!$archived) {
  38. $filter_count--;
  39. }
  40. else {
  41. $filter_count++;
  42. }
  43. if($filter_count === 0) {
  44. $filter_count = null;
  45. }
  46. if(empty($nvp)) {
  47. $nvp["level"] = (new Constraint("NOT_EQUALS"))->setValues(User::LEVEL_REGISTERED);
  48. }
  49. $sort = http::value("sort");
  50. switch($sort) {
  51. case "score":
  52. $query_options = ["sort" => "score", "order" => "desc"];
  53. break;
  54. default:
  55. $sort = "newest";
  56. $query_options = ["sort" => "id", "order" => "desc"];
  57. break;
  58. }
  59. $users = User::query($nvp, $query_options);
  60. $pagination_object = Util::getPaginationObject($users);
  61. Core::$page = $pagination_object->page;
  62. Core::$page_count = $pagination_object->pageCount;
  63. $users = array_slice($users, $pagination_object->offset, $pagination_object->pageSize);
  64. View::includeOnce("header", compact("page_title"));
  65. View::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "archived", "email", "level", "customer_id", "location_id", "has_driving_licence", "has_car", "sort", "sorts"));
  66. View::includeOnce("modal_page_jump");
  67. View::includeOnce("modals/user_export");
  68. View::includeOnce("footer");