tests.php 2.7 KB

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