1
0

tests.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. $filter_count_offset = 0;
  16. $nvp = [];
  17. if(strlen($status) > 0) $nvp["status"] = $status;
  18. else {
  19. $nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
  20. $filter_count_offset--;
  21. }
  22. if($project_id) $nvp["project_id"] = $project_id;
  23. else if($customer_id) {
  24. $projects = Project::query(["customer_id" => $customer_id]);
  25. $nvp["project_id"] = array_column($projects, "id");
  26. }
  27. if($location_id) $nvp["location_id"] = $location_id;
  28. else if($location_internal_id) {
  29. $locations = Location::query(["internal_id" => $location_internal_id]);
  30. if($locations) {
  31. $nvp["location_id"] = array_column($locations, "id");
  32. }
  33. }
  34. if($test_id) $nvp["id"] = $test_id;
  35. if(strlen($pass) > 0) $nvp["pass"] = $pass;
  36. $filter_count = count($nvp);
  37. $filter_count += $filter_count_offset;
  38. if(!$filter_count) $filter_count = "";
  39. $sort = http::value("sort");
  40. switch($sort) {
  41. case "updated":
  42. $query_options = ["sort" => "dts_updated", "order" => "desc"];
  43. break;
  44. case "due":
  45. $query_options = ["sort" => "dts_due", "order" => "desc"];
  46. break;
  47. default:
  48. $sort = "status";
  49. $query_options = ["sort" => "status", "order" => "asc"];
  50. break;
  51. }
  52. $tests = Test::query($nvp, $query_options);
  53. $pagination_object = Util::getPaginationObject($tests);
  54. $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
  55. $testers = User::load(array_column($tests, "tester_id"));
  56. $projects = Project::load(array_column($tests, "project_id"));
  57. $customers = Customer::query([], ["sort" => "name"]);
  58. usort($projects, function($a, $b) {
  59. return $a->name <=> $b->name;
  60. });
  61. $sorts = [
  62. "status" => "Status",
  63. "updated" => "Update",
  64. "due" => "Due",
  65. ];
  66. View::includeOnce("header", compact("page_title"));
  67. View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
  68. }
  69. // HQ / Venue (view completed tests)
  70. else if($user->level >= User::LEVEL_VENUE) {
  71. //$testers = User::load(array_column($tests, "tester_id"));
  72. View::includeOnce("header", compact("page_title"));
  73. View::include("test_list_venue", compact("tests"));
  74. }
  75. // Tester
  76. else if($user->level == User::LEVEL_TESTER) {
  77. $tests = $user->getPendingTests();
  78. $testers = User::load(array_column($tests, "tester_id"));
  79. View::includeOnce("header", compact("page_title"));
  80. View::include("test_list_assigned", compact("tests"));
  81. }
  82. View::includeOnce("modal_page_jump");
  83. View::includeOnce("footer");
  84. ?>