tests.php 3.0 KB

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