1
0

users.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. $nvp = [];
  23. if($id !== null) $nvp["id"] = $id;
  24. if(strlen($first_name) > 0) $nvp["first_name"] = ((new Constraint("CONTAINS"))->setValues($first_name));
  25. if(strlen($last_name) > 0) $nvp["last_name"] = ((new Constraint("CONTAINS"))->setValues($last_name));
  26. if(strlen($email) > 0) $nvp["email"] = $email;
  27. if($level !== null) $nvp["level"] = $level;
  28. if(!$archived) $nvp["archived"] = 0;
  29. $filter_count = null;
  30. if($nvp) {
  31. $filter_count = count(array_keys($nvp));
  32. }
  33. if(!$archived) {
  34. $filter_count--;
  35. }
  36. else {
  37. $filter_count++;
  38. }
  39. if($filter_count === 0) {
  40. $filter_count = null;
  41. }
  42. if(empty($nvp)) {
  43. $nvp["level"] = (new Constraint("NOT_EQUALS"))->setValues(User::LEVEL_REGISTERED);
  44. }
  45. $sort = http::value("sort");
  46. switch($sort) {
  47. case "score":
  48. $query_options = ["sort" => "score", "order" => "desc"];
  49. break;
  50. default:
  51. $sort = "newest";
  52. $query_options = ["sort" => "id", "order" => "desc"];
  53. break;
  54. }
  55. $users = User::query($nvp, $query_options);
  56. $pagination_object = Util::getPaginationObject($users);
  57. Core::$page = $pagination_object->page;
  58. Core::$page_count = $pagination_object->pageCount;
  59. $users = array_slice($users, $pagination_object->offset, $pagination_object->pageSize);
  60. View::includeOnce("header", compact("page_title"));
  61. View::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "archived", "email", "level", "customer_id", "location_id", "sort", "sorts"));
  62. View::includeOnce("modal_page_jump");
  63. View::includeOnce("modals/user_export");
  64. View::includeOnce("footer");