1
0

tests_admin_list.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. // Batch Action
  3. $submit = http::value("submit");
  4. if($submit) {
  5. try {
  6. Core::validateCSRFToken($submit);
  7. $test_ids = http::value("test_ids", "int");
  8. $batch_action = http::value("batch_action");
  9. $tests = Test::load($test_ids);
  10. $test_count = count($tests);
  11. switch($batch_action) {
  12. case "unassign":
  13. $test_unassigned_count = 0;
  14. foreach($tests as $test) {
  15. $success = $test->unassignTester();
  16. $test_unassigned_count += $success;
  17. }
  18. Core::addAlert("success", "$test_unassigned_count of $test_count test(s) unassigned successfully.");
  19. break;
  20. default:
  21. throw new Exception("Invalid action.");
  22. }
  23. HTTP::redirect($_SERVER["REQUEST_URI"]);
  24. }
  25. catch(Exception $e) {
  26. Core::addAlert("danger", $e->getMessage());
  27. }
  28. }
  29. // Batch Action End
  30. $status = http::value("status", "int");
  31. $customer_id = http::value("customer_id", "int");
  32. $project_id = http::value("project_id", "int");
  33. $location_id = http::value("location_id", "int");
  34. $test_id = http::value("test_id", "int");
  35. $location_internal_id = http::value("location_internal_id", "int");
  36. $pass = http::value("pass", "int");
  37. $custom = http::value("custom");
  38. $filter_count_offset = 0;
  39. $nvp = [];
  40. if(strlen($status) > 0) $nvp["status"] = $status;
  41. else {
  42. $nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
  43. $filter_count_offset--;
  44. }
  45. if($project_id) $nvp["project_id"] = $project_id;
  46. else if($customer_id) {
  47. $projects = Project::query(["customer_id" => $customer_id]);
  48. $nvp["project_id"] = array_column($projects, "id");
  49. }
  50. if($location_id) $nvp["location_id"] = $location_id;
  51. else if($location_internal_id) {
  52. $locations = Location::query(["internal_id" => $location_internal_id]);
  53. if($locations) {
  54. $nvp["location_id"] = array_column($locations, "id");
  55. }
  56. }
  57. if($test_id) $nvp["id"] = $test_id;
  58. if(strlen($pass) > 0) $nvp["pass"] = $pass;
  59. $filter_count = count($nvp);
  60. $sort = http::value("sort");
  61. switch($sort) {
  62. case "updated":
  63. $query_options = ["sort" => "dts_updated", "order" => "desc"];
  64. break;
  65. case "due":
  66. $query_options = ["sort" => "dts_due", "order" => "asc"];
  67. break;
  68. default:
  69. $sort = "status";
  70. $query_options = ["sort" => "status", "order" => "asc"];
  71. break;
  72. }
  73. $tests = Test::query($nvp, $query_options);
  74. $projects = Project::load(array_column($tests, "project_id"));
  75. switch($custom) {
  76. case "overdue_project":
  77. $tests = array_filter($tests, function($test) {
  78. if($test->status == Test::STATUS_CANCELLED) return false;
  79. $project = $test->getProject();
  80. $unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
  81. return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
  82. });
  83. $filter_count++;
  84. break;
  85. case "overdue_test":
  86. $tests = array_filter($tests, function($test) {
  87. if($test->status == Test::STATUS_CANCELLED) return false;
  88. if(is_null($test->dts_due)) return false;
  89. $unix_due = Util::getUnixTimeFromUTC($test->dts_due);
  90. return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
  91. });
  92. $filter_count++;
  93. break;
  94. }
  95. $filter_count += $filter_count_offset;
  96. if(!$filter_count) $filter_count = "";
  97. $pagination_object = Util::getPaginationObject($tests);
  98. $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
  99. $testers = User::load(array_column($tests, "tester_id"));
  100. $customers = Customer::query([], ["sort" => "name"]);
  101. usort($projects, function($a, $b) {
  102. return $a->name <=> $b->name;
  103. });
  104. $sorts = [
  105. "status" => "Status",
  106. "updated" => "Update",
  107. "due" => "Due",
  108. ];
  109. View::includeOnce("header", compact("page_title"));
  110. 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"));
  111. ?>