tests.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. $page_title = "Tests";
  3. Core::addBreadcrumb("/account", "Account");
  4. Core::addBreadcrumb("/account/tests", $page_title);
  5. $user = Core::$user;
  6. // Pagination
  7. $page_size = 25;
  8. $page = http::value("page", "int");
  9. if($page <= 1) $page = 1;
  10. Core::$page = $page;
  11. // Admin / Super Admin
  12. if($user->level >= User::LEVEL_ADMIN) {
  13. $status = http::value("status", "int");
  14. $customer_id = http::value("customer_id", "int");
  15. $project_id = http::value("project_id", "int");
  16. $location_id = http::value("location_id", "int");
  17. $test_id = http::value("test_id", "int");
  18. $location_internal_id = http::value("location_internal_id", "int");
  19. $pass = http::value("pass", "int");
  20. $nvp = [];
  21. if(strlen($status) > 0) $nvp["status"] = $status;
  22. else {
  23. $nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
  24. }
  25. if($project_id) $nvp["project_id"] = $project_id;
  26. else if($customer_id) {
  27. $projects = Project::query(["customer_id" => $customer_id]);
  28. $nvp["project_id"] = array_column($projects, "id");
  29. }
  30. if($location_id) $nvp["location_id"] = $location_id;
  31. else if($location_internal_id) {
  32. $locations = Location::query(["internal_id" => $location_internal_id]);
  33. if($locations) {
  34. $nvp["location_id"] = array_column($locations, "id");
  35. }
  36. }
  37. if($test_id) $nvp["id"] = $test_id;
  38. if(strlen($pass) > 0) $nvp["pass"] = $pass;
  39. $filter_count = count($nvp);
  40. if(!$filter_count) $filter_count = "";
  41. $sort = http::value("sort");
  42. switch($sort) {
  43. case "updated":
  44. $query_options = ["sort" => "dts_updated", "order" => "desc"];
  45. break;
  46. case "due":
  47. $query_options = ["sort" => "dts_due", "order" => "desc"];
  48. break;
  49. default:
  50. $sort = "status";
  51. $query_options = ["sort" => "status", "order" => "asc"];
  52. break;
  53. }
  54. $tests = Test::query($nvp, $query_options);
  55. $test_count = count($tests);
  56. $page_count = ceil($test_count / $page_size);
  57. if($page_count <= 1) $page_count = 1;
  58. Core::$page_count = $page_count;
  59. $offset = ($page - 1) * $page_size;
  60. $tests = array_slice($tests, $offset, $page_size);
  61. $testers = User::load(array_column($tests, "tester_id"));
  62. $projects = Project::load(array_column($tests, "project_id"));
  63. $customers = Customer::query([], ["sort" => "name"]);
  64. usort($projects, function($a, $b) {
  65. return $a->name <=> $b->name;
  66. });
  67. $item_number_first = $offset + 1;
  68. $item_number_last = $offset + $page_size;
  69. if($item_number_last > $test_count) $item_number_last = $test_count;
  70. $pagination_string = "Showing $item_number_first-$item_number_last of $test_count tests";
  71. $sorts = [
  72. "status" => "Status",
  73. "updated" => "Update",
  74. "due" => "Due",
  75. ];
  76. View::includeOnce("header", compact("page_title"));
  77. View::include("test_list", compact("tests", "test_count", "sort", "sorts", "pagination_string", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
  78. }
  79. // HQ / Venue (view completed tests)
  80. else if($user->level >= User::LEVEL_VENUE) {
  81. //$testers = User::load(array_column($tests, "tester_id"));
  82. View::includeOnce("header", compact("page_title"));
  83. View::include("test_list_venue", compact("tests"));
  84. }
  85. // Tester
  86. else if($user->level == User::LEVEL_TESTER) {
  87. $tests = $user->getPendingTests();
  88. $testers = User::load(array_column($tests, "tester_id"));
  89. View::includeOnce("header", compact("page_title"));
  90. View::include("test_list_assigned", compact("tests"));
  91. }
  92. View::includeOnce("modal_page_jump");
  93. View::includeOnce("footer");
  94. ?>