tests.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. $project_id = http::value("project_id", "int");
  15. $location_id = http::value("location_id", "int");
  16. $test_id = http::value("test_id", "int");
  17. $location_internal_id = http::value("location_internal_id", "int");
  18. $pass = http::value("pass", "int");
  19. $nvp = [];
  20. if($status) $nvp["status"] = $status;
  21. if($project_id) $nvp["project_id"] = $project_id;
  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. if(!$filter_count) $filter_count = "";
  33. $sort = http::value("sort");
  34. switch($sort) {
  35. case "updated":
  36. $query_options = ["sort" => "dts_updated", "order" => "desc"];
  37. break;
  38. case "due":
  39. $query_options = ["sort" => "dts_due", "order" => "desc"];
  40. break;
  41. default:
  42. $sort = "status";
  43. $query_options = ["sort" => "status", "order" => "asc"];
  44. break;
  45. }
  46. $tests = Test::query($nvp, $query_options);
  47. $test_count = count($tests);
  48. $page_count = ceil($test_count / $page_size);
  49. if($page_count <= 1) $page_count = 1;
  50. Core::$page_count = $page_count;
  51. $offset = ($page - 1) * $page_size;
  52. $tests = array_slice($tests, $offset, $page_size);
  53. $testers = User::load(array_column($tests, "tester_id"));
  54. $projects = Project::load(array_column($tests, "project_id"));
  55. usort($projects, function($a, $b) {
  56. return $a->name <=> $b->name;
  57. });
  58. $item_number_first = $offset + 1;
  59. $item_number_last = $offset + $page_size;
  60. if($item_number_last > $test_count) $item_number_last = $test_count;
  61. $pagination_string = "Showing $item_number_first-$item_number_last of $test_count tests";
  62. $sorts = [
  63. "status" => "Status",
  64. "updated" => "Update",
  65. "due" => "Due",
  66. ];
  67. View::includeOnce("header", compact("page_title"));
  68. View::include("test_list", compact("tests", "test_count", "sort", "sorts", "pagination_string", "projects", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
  69. }
  70. // HQ / Venue (view completed tests)
  71. else if($user->level >= User::LEVEL_VENUE) {
  72. //$testers = User::load(array_column($tests, "tester_id"));
  73. View::includeOnce("header", compact("page_title"));
  74. View::include("test_list_venue", compact("tests"));
  75. }
  76. // Tester
  77. else if($user->level == User::LEVEL_TESTER) {
  78. $tests = $user->getPendingTests();
  79. $testers = User::load(array_column($tests, "tester_id"));
  80. View::includeOnce("header", compact("page_title"));
  81. View::include("test_list_assigned", compact("tests"));
  82. }
  83. View::includeOnce("modal_page_jump");
  84. View::includeOnce("footer");
  85. ?>