|
|
@@ -1,8 +1,16 @@
|
|
|
-<?php
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @var int $id
|
|
|
+ */
|
|
|
|
|
|
$project = Project::get($id);
|
|
|
-if(!$project) throw new Exception("Project not found.");
|
|
|
-if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this page.");
|
|
|
+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;
|
|
|
|
|
|
@@ -16,25 +24,82 @@ 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");
|
|
|
+$location_ids_json = http::value("location_ids_json", "string");
|
|
|
+
|
|
|
+if($action) {
|
|
|
+ switch($action) {
|
|
|
+ case "move-tests":
|
|
|
+
|
|
|
+ $location_ids = json_decode($location_ids_json);
|
|
|
+ if(!is_array($location_ids)) {
|
|
|
+ $location_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(["location_id" => $location_ids, "project_id" => $id]);
|
|
|
+
|
|
|
+ $source_test_count = count($source_tests);
|
|
|
+ $expected_test_count = count($location_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");
|
|
|
+ }
|
|
|
+
|
|
|
+ $conflicting_tests = Test::query(["location_id" => $location_ids, "project_id" => $target_project_id]);
|
|
|
+ $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, function($a, $b) {
|
|
|
+usort($tests, static function(Test $a, Test $b) {
|
|
|
return $a->status <=> $b->status;
|
|
|
});
|
|
|
|
|
|
$created_test_count = count($tests);
|
|
|
|
|
|
-$pending_verification_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_PENDING_VERIFICATION; });
|
|
|
-$pending_verification_test_count = count($pending_verification_tests);
|
|
|
+$completed_test_count = count(array_filter($tests, static function(Test $test) {
|
|
|
+ return $test->isCompleted();
|
|
|
+}));
|
|
|
|
|
|
-$completed_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_COMPLETED; });
|
|
|
-$completed_test_count = count($completed_tests);
|
|
|
-
|
|
|
-$pass_count = count(array_filter($tests, function($test) { return $test->isPass(); }));
|
|
|
-$fail_count = count(array_filter($tests, function($test) { return $test->isFail(); }));
|
|
|
+$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;
|
|
|
@@ -66,5 +131,3 @@ 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");
|
|
|
-
|
|
|
-?>
|