tests.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. $page_title = "Tests";
  3. Core::addBreadcrumb("/account", "Account");
  4. Core::addBreadcrumb("/account/tests", $page_title);
  5. $user = Core::$user;
  6. // Pagination
  7. $page_size = 25;
  8. $page = http::value("page", "int");
  9. if($page <= 1) $page = 1;
  10. Core::$page = $page;
  11. // Admin / Super Admin
  12. if($user->level >= User::LEVEL_ADMIN) {
  13. $status = http::value("status", "int");
  14. $customer_id = http::value("customer_id", "int");
  15. $project_id = http::value("project_id", "int");
  16. $location_id = http::value("location_id", "int");
  17. $test_id = http::value("test_id", "int");
  18. $location_internal_id = http::value("location_internal_id", "int");
  19. $pass = http::value("pass", "int");
  20. $nvp = [];
  21. if($status) $nvp["status"] = $status;
  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. if(!$filter_count) $filter_count = "";
  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. $test_count = count($tests);
  53. $page_count = ceil($test_count / $page_size);
  54. if($page_count <= 1) $page_count = 1;
  55. Core::$page_count = $page_count;
  56. $offset = ($page - 1) * $page_size;
  57. $tests = array_slice($tests, $offset, $page_size);
  58. $testers = User::load(array_column($tests, "tester_id"));
  59. $projects = Project::load(array_column($tests, "project_id"));
  60. $customers = Customer::query([], ["sort" => "name"]);
  61. usort($projects, function($a, $b) {
  62. return $a->name <=> $b->name;
  63. });
  64. $item_number_first = $offset + 1;
  65. $item_number_last = $offset + $page_size;
  66. if($item_number_last > $test_count) $item_number_last = $test_count;
  67. $pagination_string = "Showing $item_number_first-$item_number_last of $test_count tests";
  68. $sorts = [
  69. "status" => "Status",
  70. "updated" => "Update",
  71. "due" => "Due",
  72. ];
  73. View::includeOnce("header", compact("page_title"));
  74. View::include("test_list", compact("tests", "test_count", "sort", "sorts", "pagination_string", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
  75. }
  76. // HQ / Venue (view completed tests)
  77. else if($user->level >= User::LEVEL_VENUE) {
  78. //$testers = User::load(array_column($tests, "tester_id"));
  79. View::includeOnce("header", compact("page_title"));
  80. View::include("test_list_venue", compact("tests"));
  81. }
  82. // Tester
  83. else if($user->level == User::LEVEL_TESTER) {
  84. $tests = $user->getPendingTests();
  85. $testers = User::load(array_column($tests, "tester_id"));
  86. View::includeOnce("header", compact("page_title"));
  87. View::include("test_list_assigned", compact("tests"));
  88. }
  89. View::includeOnce("modal_page_jump");
  90. View::includeOnce("footer");
  91. ?>