tests.php 3.8 KB

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