hasPermission($project)) { throw new RuntimeException("You do not have permission to access this page."); } $page_title = $project->name; $customer = $project->getCustomer(); Core::addBreadcrumb("/account", "Account"); Core::addBreadcrumb("/account/projects", "Projects"); Core::addBreadcrumb("/account/projects?customer_id=$customer->id", "$customer->name Projects"); Core::addBreadcrumb("/account/projects/$project->id", $page_title); Core::addScript("public/js/app-project.js"); Core::addScript("public/js/markerclusterer.js"); $action = http::value("action", "string"); $target_project_id = http::value("target_project_id"); $test_ids_json = http::value("test_ids_json", "string"); if($action) { $test_ids = json_decode($test_ids_json); if(!is_array($test_ids)) { $test_ids = []; } switch($action) { case "move-tests": $target_project = Project::get($target_project_id); if(!$target_project) { throw new RuntimeException("Target project not found."); } if($target_project->template_id !== $project->template_id) { throw new RuntimeException("Target project template is not the same as this project."); } $source_tests = Test::query(["id" => $test_ids, "project_id" => $id, "status" => Constraint::notEquals(Test::STATUS_CANCELLED)]); $source_test_count = count($source_tests); $expected_test_count = count($test_ids); if($source_test_count !== $expected_test_count) { throw new RuntimeException("Tests do not match number of IDs submitted. $source_test_count $expected_test_count"); } $location_ids = []; foreach($source_tests as $source_test) { $location_ids[] = $source_test->location_id; } $conflicting_tests = Test::query(["location_id" => $location_ids, "project_id" => $target_project_id, "status" => Constraint::notEquals(Test::STATUS_CANCELLED)]); $conflicting_test_count = count($conflicting_tests); if($conflicting_test_count > 0) { $location_names = []; foreach($conflicting_tests as $conflicting_test) { $location_names[] = $conflicting_test->getLocation()->name; } throw new RuntimeException(__("%d conflicting test(s) were found in the target project. Locations: %s", $conflicting_test_count, implode(", ", $location_names))); } // OK at this point foreach($source_tests as $source_test) { $source_test->project_id = $target_project_id; $source_test->commit(); } Core::addAlert("success", __("Tests moved successfully.")); break; case "unassign": $tests = Test::query(["id" => $test_ids, "project_id" => $id, "status" => Test::STATUS_ASSIGNED]); foreach($tests as $test) { $test->unassign(); } Core::addAlert("success", __("Tests unassigned successfully.")); break; default: throw new RuntimeException(__("Invalid action.")); } } $completed_percentage = $project->getCompletedPercentage(); $locations = $customer->getLocations(); $tests = $project->getTests(); usort($tests, static function(Test $a, Test $b) { return $a->status <=> $b->status; }); $created_test_count = count($tests); $completed_test_count = count(array_filter($tests, static function(Test $test) { return $test->isCompleted(); })); $pass_count = count(array_filter($tests, static function(Test $test) { return $test->isPass(); })); $fail_count = count(array_filter($tests, static function(Test $test) { return $test->isFail(); })); $pass_fail_count = $pass_count + $fail_count; $pass_percentage = 0; $fail_percentage = 0; if($pass_fail_count) { $pass_percentage = number_format(($pass_count / $pass_fail_count) * 100, 1); $fail_percentage = 100 - $pass_percentage; } $min_lat = $min_lng = 180; $max_lat = $max_lng = -180; foreach($locations as $location) { if($location->latitude < $min_lat) $min_lat = $location->latitude; if($location->latitude > $max_lat) $max_lat = $location->latitude; if($location->longitude < $min_lng) $min_lng = $location->longitude; if($location->longitude > $max_lng) $max_lng = $location->longitude; } $latitude = ($min_lat + $max_lat) / 2; $longitude = ($min_lng + $max_lng) / 2; $latitude = 51.3555177; $longitude = -1.1743197; $deadline_date = explode(" ", $project->dts_deadline)[0]; View::includeOnce("header", compact("page_title")); View::include("project", compact("project", "tests", "latitude", "longitude", "completed_percentage", "pass_count", "fail_count", "pass_fail_count", "pass_percentage", "fail_percentage", "customer", "locations", "deadline_date", "created_test_count", "completed_test_count")); View::include("modal_assign_tester"); View::includeOnce("footer");