tests_admin_list.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. $status = http::value("status", "int");
  3. $customer_id = http::value("customer_id", "int");
  4. $project_id = http::value("project_id", "int");
  5. $location_id = http::value("location_id", "int");
  6. $test_id = http::value("test_id", "int");
  7. $location_internal_id = http::value("location_internal_id", "int");
  8. $pass = http::value("pass", "int");
  9. $custom = http::value("custom");
  10. $filter_count_offset = 0;
  11. $nvp = [];
  12. if(strlen($status) > 0) $nvp["status"] = $status;
  13. else {
  14. $nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
  15. $filter_count_offset--;
  16. }
  17. if($project_id) $nvp["project_id"] = $project_id;
  18. else if($customer_id) {
  19. $projects = Project::query(["customer_id" => $customer_id]);
  20. $nvp["project_id"] = array_column($projects, "id");
  21. }
  22. if($location_id) $nvp["location_id"] = $location_id;
  23. else if($location_internal_id) {
  24. $locations = Location::query(["internal_id" => $location_internal_id]);
  25. if($locations) {
  26. $nvp["location_id"] = array_column($locations, "id");
  27. }
  28. }
  29. if($test_id) $nvp["id"] = $test_id;
  30. if(strlen($pass) > 0) $nvp["pass"] = $pass;
  31. $filter_count = count($nvp);
  32. $sort = http::value("sort");
  33. switch($sort) {
  34. case "updated":
  35. $query_options = ["sort" => "dts_updated", "order" => "desc"];
  36. break;
  37. case "due":
  38. $query_options = ["sort" => "dts_due", "order" => "asc"];
  39. break;
  40. default:
  41. $sort = "status";
  42. $query_options = ["sort" => "status", "order" => "asc"];
  43. break;
  44. }
  45. $tests = Test::query($nvp, $query_options);
  46. $projects = Project::load(array_column($tests, "project_id"));
  47. switch($custom) {
  48. case "overdue_project":
  49. $tests = array_filter($tests, function($test) {
  50. if($test->status == Test::STATUS_CANCELLED) return false;
  51. $project = $test->getProject();
  52. $unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
  53. return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
  54. });
  55. $filter_count++;
  56. break;
  57. case "overdue_test":
  58. $tests = array_filter($tests, function($test) {
  59. if($test->status == Test::STATUS_CANCELLED) return false;
  60. if(is_null($test->dts_due)) return false;
  61. $unix_due = Util::getUnixTimeFromUTC($test->dts_due);
  62. return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
  63. });
  64. $filter_count++;
  65. break;
  66. }
  67. $filter_count += $filter_count_offset;
  68. if(!$filter_count) $filter_count = "";
  69. $pagination_object = Util::getPaginationObject($tests);
  70. $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
  71. $testers = User::load(array_column($tests, "tester_id"));
  72. $customers = Customer::query([], ["sort" => "name"]);
  73. usort($projects, function($a, $b) {
  74. return $a->name <=> $b->name;
  75. });
  76. $sorts = [
  77. "status" => "Status",
  78. "updated" => "Update",
  79. "due" => "Due",
  80. ];
  81. View::includeOnce("header", compact("page_title"));
  82. 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"));
  83. ?>