|
|
@@ -1,4 +1,6 @@
|
|
|
-<?php
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
+
|
|
|
+$date_format = "/^2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9]$/";
|
|
|
|
|
|
JSON::header();
|
|
|
|
|
|
@@ -14,32 +16,39 @@ if($submit) {
|
|
|
// Gets all locations for a customer
|
|
|
case "get-customer-locations": {
|
|
|
|
|
|
+ // Input
|
|
|
$customer_id = http::value("customer_id", "int");
|
|
|
+
|
|
|
+ $min_date = http::value("min_date");
|
|
|
+ $max_date = http::value("max_date");
|
|
|
+
|
|
|
+ // Get customer
|
|
|
$customer = Customer::get($customer_id);
|
|
|
if(!$customer) throw new Exception("Customer not found.");
|
|
|
|
|
|
+ // Get locations
|
|
|
$locations = $customer->getLocations();
|
|
|
|
|
|
- $min_date = http::value("min_date");
|
|
|
- $max_date = http::value("max_date");
|
|
|
-
|
|
|
+ // Get tests
|
|
|
$nvp = [
|
|
|
"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
|
|
|
"location_id" => array_column($locations, "id")
|
|
|
];
|
|
|
|
|
|
- $date_format = "/^2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9]$/";
|
|
|
+ if($min_date && $max_date) {
|
|
|
+ if(preg_match($date_format, $min_date) && preg_match($date_format, $max_date)) {
|
|
|
+ $min_dts = "{$min_date}";
|
|
|
+ $max_dts = "{$max_date}";
|
|
|
|
|
|
- if($min_date && preg_match($date_format, $min_date)) {
|
|
|
- $min_dts = "{$min_date} 00:00:00";
|
|
|
- $nvp["dts_start"] = (new Constraint("MORE_THAN_OR_EQUAL"))->setValues($min_dts);
|
|
|
+ $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if($max_date && preg_match($date_format, $max_date)) {
|
|
|
- $max_dts = "{$max_date} 23:59:59";
|
|
|
- $nvp["dts_start"] = (new Constraint("LESS_THAN_OR_EQUAL"))->setValues($max_dts);
|
|
|
+ else {
|
|
|
+ list($min_dts, $max_dts) = $customer->getYearCycleDates();
|
|
|
+ $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
$tests = Test::query($nvp);
|
|
|
|
|
|
$location_test_array = [];
|
|
|
@@ -49,6 +58,7 @@ if($submit) {
|
|
|
$location_test_array[$test->location_id] = $test;
|
|
|
}
|
|
|
else {
|
|
|
+ /** @var Test $existing */
|
|
|
$existing = $location_test_array[$test->location_id];
|
|
|
|
|
|
$unix_start_existing = is_null($existing->dts_start) ? 0 : strtotime($existing->dts_start . " UTC");
|
|
|
@@ -71,6 +81,7 @@ if($submit) {
|
|
|
|
|
|
$customer_slug = str_replace("-", "_", Util::slug($customer->name));
|
|
|
|
|
|
+ /** @var User $tester */
|
|
|
$tester = null;
|
|
|
$formatted_start_dts = null;
|
|
|
$formatted_due_dts = null;
|
|
|
@@ -110,7 +121,6 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if($icon_file && file_exists("public/img/markers/$icon_file")) {
|
|
|
$icon = $icon_file;
|
|
|
}
|
|
|
@@ -148,7 +158,8 @@ if($submit) {
|
|
|
}
|
|
|
|
|
|
JSON::success([
|
|
|
- "locations" => $output
|
|
|
+ "locations" => $output,
|
|
|
+ "testPeriod" => sprintf("%s to %s", $min_dts, $max_dts)
|
|
|
]);
|
|
|
|
|
|
break;
|
|
|
@@ -252,4 +263,3 @@ if($submit) {
|
|
|
|
|
|
JSON::fail("Invalid request.");
|
|
|
|
|
|
-?>
|