| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- /**
- * @var int $id
- */
- $project = Project::get($id);
- if(!$project) {
- throw new RuntimeException("Project not found.");
- }
- if(!Core::$user->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) {
- switch($action) {
- case "move-tests":
- $test_ids = json_decode($test_ids_json);
- if(!is_array($test_ids)) {
- $test_ids = [];
- }
- $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) {
- throw new RuntimeException(__("%d conflicting test(s) for a location was found in the target project. Please remove from the target project and try again.", $conflicting_test_count));
- }
- // 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;
- 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");
|