tests.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $nvp = [];
  18. if($status) $nvp["status"] = $status;
  19. if($project_id) $nvp["project_id"] = $project_id;
  20. if($location_id) $nvp["location_id"] = $location_id;
  21. if($test_id) $nvp["id"] = $test_id;
  22. $filter_count = count($nvp);
  23. if(!$filter_count) $filter_count = "";
  24. $tests = Test::query($nvp, ["sort" => "status"]);
  25. $test_count = count($tests);
  26. $page_count = ceil($test_count / $page_size);
  27. if($page_count <= 1) $page_count = 1;
  28. Core::$page_count = $page_count;
  29. $offset = ($page - 1) * $page_size;
  30. $tests = array_slice($tests, $offset, $page_size);
  31. $testers = User::load(array_column($tests, "tester_id"));
  32. $projects = Project::load(array_column($tests, "project_id"));
  33. usort($projects, function($a, $b) {
  34. return $a->name <=> $b->name;
  35. });
  36. $item_number_first = $offset + 1;
  37. $item_number_last = $offset + $page_size;
  38. if($item_number_last > $test_count) $item_number_last = $test_count;
  39. $pagination_string = "Showing $item_number_first-$item_number_last of $test_count tests";
  40. View::includeOnce("header", compact("page_title"));
  41. View::include("test_list", compact("tests", "test_count", "pagination_string", "projects", "project_id", "location_id", "test_id", "filter_count", "status"));
  42. }
  43. // HQ / Venue (view completed tests)
  44. else if($user->level >= User::LEVEL_VENUE) {
  45. //$testers = User::load(array_column($tests, "tester_id"));
  46. View::includeOnce("header", compact("page_title"));
  47. View::include("test_list_completed", compact("tests"));
  48. }
  49. // Tester
  50. else if($user->level == User::LEVEL_TESTER) {
  51. $tests = $user->getPendingTests();
  52. $testers = User::load(array_column($tests, "tester_id"));
  53. View::includeOnce("header", compact("page_title"));
  54. View::include("test_list_assigned", compact("tests"));
  55. }
  56. View::includeOnce("modal_page_jump");
  57. View::includeOnce("footer");
  58. ?>