|
@@ -4,7 +4,7 @@
|
|
|
* @var string $action
|
|
* @var string $action
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-$date_format = "/^2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9]$/";
|
|
|
|
|
|
|
+$date_format = "/^2\d{3}-[01]\d-[0-3]\d$/";
|
|
|
|
|
|
|
|
JSON::header();
|
|
JSON::header();
|
|
|
|
|
|
|
@@ -28,31 +28,33 @@ if($submit) {
|
|
|
|
|
|
|
|
// Get customer
|
|
// Get customer
|
|
|
$customer = Customer::get($customer_id);
|
|
$customer = Customer::get($customer_id);
|
|
|
- if(!$customer) throw new Exception("Customer not found.");
|
|
|
|
|
|
|
+ if(!$customer) throw new RuntimeException("Customer not found.");
|
|
|
|
|
|
|
|
// Get locations
|
|
// Get locations
|
|
|
$locations = $customer->getLocations(["archived" => 0]);
|
|
$locations = $customer->getLocations(["archived" => 0]);
|
|
|
|
|
|
|
|
// Get tests
|
|
// Get tests
|
|
|
$nvp = [
|
|
$nvp = [
|
|
|
- "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
|
|
|
|
|
|
|
+ "status" => Constraint::notEquals(Test::STATUS_CANCELLED),
|
|
|
"location_id" => array_column($locations, "id")
|
|
"location_id" => array_column($locations, "id")
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
if($min_date && $max_date) {
|
|
if($min_date && $max_date) {
|
|
|
if(preg_match($date_format, $min_date) && preg_match($date_format, $max_date)) {
|
|
if(preg_match($date_format, $min_date) && preg_match($date_format, $max_date)) {
|
|
|
- $min_dts = "{$min_date}";
|
|
|
|
|
- $max_dts = "{$max_date}";
|
|
|
|
|
|
|
+ $min_dts = $min_date;
|
|
|
|
|
+ $max_dts = $max_date;
|
|
|
|
|
|
|
|
- $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
|
|
|
|
|
|
|
+ $nvp["dts_start"] = Constraint::between($min_dts, $max_dts);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ throw new RuntimeException("Invalid dates submitted.");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- list($min_dts, $max_dts) = $customer->getYearCycleDates();
|
|
|
|
|
- $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
|
|
|
|
|
|
|
+ [$min_dts, $max_dts] = $customer->getYearCycleDates();
|
|
|
|
|
+ $nvp["dts_start"] = Constraint::between($min_dts, $max_dts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
$tests = Test::query($nvp);
|
|
$tests = Test::query($nvp);
|
|
|
|
|
|
|
|
$location_test_array = [];
|
|
$location_test_array = [];
|
|
@@ -65,8 +67,8 @@ if($submit) {
|
|
|
/** @var Test $existing */
|
|
/** @var Test $existing */
|
|
|
$existing = $location_test_array[$test->location_id];
|
|
$existing = $location_test_array[$test->location_id];
|
|
|
|
|
|
|
|
- $unix_start_existing = is_null($existing->dts_start) ? 0 : strtotime($existing->dts_start . " UTC");
|
|
|
|
|
- $unix_start_current = is_null($test->dts_start) ? 0 : strtotime($test->dts_start . " UTC");
|
|
|
|
|
|
|
+ $unix_start_existing = ($existing->dts_start === null) ? 0 : strtotime($existing->dts_start . " UTC");
|
|
|
|
|
+ $unix_start_current = ($test->dts_start === null) ? 0 : strtotime($test->dts_start . " UTC");
|
|
|
|
|
|
|
|
if($unix_start_current > $unix_start_existing) {
|
|
if($unix_start_current > $unix_start_existing) {
|
|
|
$location_test_array[$test->location_id] = $test;
|
|
$location_test_array[$test->location_id] = $test;
|
|
@@ -99,20 +101,21 @@ if($submit) {
|
|
|
|
|
|
|
|
$tester = $test->getTester();
|
|
$tester = $test->getTester();
|
|
|
|
|
|
|
|
- if(!is_null($test->dts_start)) {
|
|
|
|
|
|
|
+ if($test->dts_start !== null) {
|
|
|
$unix_start = strtotime($test->dts_start);
|
|
$unix_start = strtotime($test->dts_start);
|
|
|
$formatted_start_dts = date("d/m/Y H:i", $unix_start);
|
|
$formatted_start_dts = date("d/m/Y H:i", $unix_start);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(is_null($test->pass)) {
|
|
|
|
|
|
|
+ if($test->pass === null) {
|
|
|
$icon_file = "{$customer_slug}_pending.png";
|
|
$icon_file = "{$customer_slug}_pending.png";
|
|
|
|
|
|
|
|
- if(!is_null($test->dts_due)) {
|
|
|
|
|
|
|
+ $unix_due = null;
|
|
|
|
|
+ if($test->dts_due !== null) {
|
|
|
$unix_due = strtotime($test->dts_due);
|
|
$unix_due = strtotime($test->dts_due);
|
|
|
$formatted_due_dts = date("d/m/Y H:i", $unix_due);
|
|
$formatted_due_dts = date("d/m/Y H:i", $unix_due);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($tester && $test->dts_due && time() > $unix_due) {
|
|
|
|
|
|
|
+ if($tester && $unix_due && time() > $unix_due) {
|
|
|
$icon_file = "{$customer_slug}_past_due.png";
|
|
$icon_file = "{$customer_slug}_past_due.png";
|
|
|
$past_due = true;
|
|
$past_due = true;
|
|
|
}
|
|
}
|
|
@@ -120,7 +123,7 @@ if($submit) {
|
|
|
else if($test->pass) {
|
|
else if($test->pass) {
|
|
|
$icon_file = "{$customer_slug}_pass.png";
|
|
$icon_file = "{$customer_slug}_pass.png";
|
|
|
}
|
|
}
|
|
|
- else if(!$test->pass) {
|
|
|
|
|
|
|
+ else {
|
|
|
$icon_file = "{$customer_slug}_fail.png";
|
|
$icon_file = "{$customer_slug}_fail.png";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -132,7 +135,7 @@ if($submit) {
|
|
|
$icon_file = "closed.png";
|
|
$icon_file = "closed.png";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if($icon_file && file_exists("public/img/markers/$icon_file")) {
|
|
|
|
|
|
|
+ if(file_exists("public/img/markers/$icon_file")) {
|
|
|
$icon = $icon_file;
|
|
$icon = $icon_file;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -183,7 +186,7 @@ if($submit) {
|
|
|
|
|
|
|
|
$project_id = http::value("project_id", "int");
|
|
$project_id = http::value("project_id", "int");
|
|
|
$project = Project::get($project_id);
|
|
$project = Project::get($project_id);
|
|
|
- if(!$project) throw new Exception("Project not found.");
|
|
|
|
|
|
|
+ if(!$project) throw new RuntimeException("Project not found.");
|
|
|
|
|
|
|
|
$customer = $project->getCustomer();
|
|
$customer = $project->getCustomer();
|
|
|
$tests = $project->getTests();
|
|
$tests = $project->getTests();
|
|
@@ -193,7 +196,7 @@ if($submit) {
|
|
|
$location_tests = [];
|
|
$location_tests = [];
|
|
|
|
|
|
|
|
foreach($tests as $test) {
|
|
foreach($tests as $test) {
|
|
|
- if($test->status == Test::STATUS_CANCELLED) continue;
|
|
|
|
|
|
|
+ if($test->isCancelled()) continue;
|
|
|
$location_tests[$test->location_id] = $test;
|
|
$location_tests[$test->location_id] = $test;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -251,7 +254,7 @@ if($submit) {
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- usort($output, function($a, $b) {
|
|
|
|
|
|
|
+ usort($output, static function(object $a, object $b): int {
|
|
|
return $a->status <=> $b->status;
|
|
return $a->status <=> $b->status;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -264,7 +267,7 @@ if($submit) {
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
|
- throw new Exception("Invalid request.");
|
|
|
|
|
|
|
+ throw new RuntimeException("Invalid request.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|