| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- $page_title = "Tests";
- Core::addBreadcrumb("/account", "Account");
- Core::addBreadcrumb("/account/tests", $page_title);
- $user = Core::$user;
- // Admin / Super Admin
- if($user->level >= User::LEVEL_ADMIN) {
- $status = http::value("status", "int");
- $customer_id = http::value("customer_id", "int");
- $project_id = http::value("project_id", "int");
- $location_id = http::value("location_id", "int");
- $test_id = http::value("test_id", "int");
- $location_internal_id = http::value("location_internal_id", "int");
- $pass = http::value("pass", "int");
- $custom = http::value("custom");
- $filter_count_offset = 0;
- $nvp = [];
- if(strlen($status) > 0) $nvp["status"] = $status;
- else {
- $nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
- $filter_count_offset--;
- }
- if($project_id) $nvp["project_id"] = $project_id;
- else if($customer_id) {
- $projects = Project::query(["customer_id" => $customer_id]);
- $nvp["project_id"] = array_column($projects, "id");
- }
- if($location_id) $nvp["location_id"] = $location_id;
- else if($location_internal_id) {
- $locations = Location::query(["internal_id" => $location_internal_id]);
- if($locations) {
- $nvp["location_id"] = array_column($locations, "id");
- }
- }
- if($test_id) $nvp["id"] = $test_id;
- if(strlen($pass) > 0) $nvp["pass"] = $pass;
- $filter_count = count($nvp);
- $sort = http::value("sort");
- switch($sort) {
- case "updated":
- $query_options = ["sort" => "dts_updated", "order" => "desc"];
- break;
- case "due":
- $query_options = ["sort" => "dts_due", "order" => "desc"];
- break;
- default:
- $sort = "status";
- $query_options = ["sort" => "status", "order" => "asc"];
- break;
- }
- $tests = Test::query($nvp, $query_options);
- $projects = Project::load(array_column($tests, "project_id"));
- switch($custom) {
- case "overdue_project":
- $tests = array_filter($tests, function($test) {
- if($test->status == Test::STATUS_CANCELLED) return false;
- $project = $test->getProject();
- $unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
- return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
- });
- $filter_count++;
- break;
- case "overdue_test":
- $tests = array_filter($tests, function($test) {
- if($test->status == Test::STATUS_CANCELLED) return false;
- if(is_null($test->dts_due)) return false;
- $unix_due = Util::getUnixTimeFromUTC($test->dts_due);
- return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
- });
- $filter_count++;
- break;
- }
- $filter_count += $filter_count_offset;
- if(!$filter_count) $filter_count = "";
- $pagination_object = Util::getPaginationObject($tests);
- $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
- $testers = User::load(array_column($tests, "tester_id"));
- $customers = Customer::query([], ["sort" => "name"]);
- usort($projects, function($a, $b) {
- return $a->name <=> $b->name;
- });
- $sorts = [
- "status" => "Status",
- "updated" => "Update",
- "due" => "Due",
- ];
- View::includeOnce("header", compact("page_title"));
- View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "custom", "test_id", "filter_count", "status"));
- }
- // HQ / Venue (view completed tests)
- else if($user->level >= User::LEVEL_VENUE) {
- //$testers = User::load(array_column($tests, "tester_id"));
- View::includeOnce("header", compact("page_title"));
- View::include("test_list_venue", compact("tests"));
- }
- // Tester
- else if($user->level == User::LEVEL_TESTER) {
- $tests = $user->getPendingTests();
- $testers = User::load(array_column($tests, "tester_id"));
- View::includeOnce("header", compact("page_title"));
- View::include("test_list_assigned", compact("tests"));
- }
- View::includeOnce("modal_page_jump");
- View::includeOnce("footer");
- ?>
|