tests.php 3.0 KB

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