|
@@ -4,6 +4,8 @@
|
|
|
* @var string $action
|
|
* @var string $action
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+use Helpers\LocationHelper;
|
|
|
|
|
+
|
|
|
$date_format = "/^2\d{3}-[01]\d-[0-3]\d$/";
|
|
$date_format = "/^2\d{3}-[01]\d-[0-3]\d$/";
|
|
|
|
|
|
|
|
JSON::header();
|
|
JSON::header();
|
|
@@ -20,18 +22,6 @@ if($submit) {
|
|
|
// Gets all locations for a customer
|
|
// Gets all locations for a customer
|
|
|
case "get-customer-locations": {
|
|
case "get-customer-locations": {
|
|
|
|
|
|
|
|
- // Initialise Results
|
|
|
|
|
- $results = [];
|
|
|
|
|
-
|
|
|
|
|
- $init_result = static function(Location $location): object {
|
|
|
|
|
- return (object) [
|
|
|
|
|
- "location" => $location,
|
|
|
|
|
- "latestTest" => null,
|
|
|
|
|
- "testerId" => null,
|
|
|
|
|
- "testCount" => 0
|
|
|
|
|
- ];
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
// Input
|
|
// Input
|
|
|
$customer_id = http::value("customer_id", "int");
|
|
$customer_id = http::value("customer_id", "int");
|
|
|
|
|
|
|
@@ -40,27 +30,19 @@ if($submit) {
|
|
|
|
|
|
|
|
// Get customer
|
|
// Get customer
|
|
|
$customer = Customer::get($customer_id);
|
|
$customer = Customer::get($customer_id);
|
|
|
- if(!$customer) throw new RuntimeException("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]);
|
|
|
|
|
|
|
|
- foreach($locations as $location) {
|
|
|
|
|
- $results[$location->id] = $init_result($location);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Get tests
|
|
|
|
|
- $nvp = [
|
|
|
|
|
- "status" => Constraint::notEquals(Test::STATUS_CANCELLED),
|
|
|
|
|
- "location_id" => array_column($locations, "id")
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ $output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
|
|
|
|
|
|
|
|
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;
|
|
$min_dts = $min_date;
|
|
|
$max_dts = $max_date;
|
|
$max_dts = $max_date;
|
|
|
-
|
|
|
|
|
- $nvp["dts_start"] = Constraint::between($min_dts, $max_dts);
|
|
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
throw new RuntimeException("Invalid dates submitted.");
|
|
throw new RuntimeException("Invalid dates submitted.");
|
|
@@ -68,137 +50,6 @@ if($submit) {
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
[$min_dts, $max_dts] = $customer->getYearCycleDates();
|
|
[$min_dts, $max_dts] = $customer->getYearCycleDates();
|
|
|
- $nvp["dts_start"] = Constraint::between($min_dts, $max_dts);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $tests = Test::query($nvp);
|
|
|
|
|
-
|
|
|
|
|
- foreach($tests as $test) {
|
|
|
|
|
-
|
|
|
|
|
- $result = $results[$test->location_id];
|
|
|
|
|
- $result->testCount++;
|
|
|
|
|
-
|
|
|
|
|
- $assign_test = false;
|
|
|
|
|
- if($result->latestTest === null) {
|
|
|
|
|
- $assign_test = true;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- /** @var Test $existing */
|
|
|
|
|
- $existing = $result->latestTest;
|
|
|
|
|
-
|
|
|
|
|
- $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) {
|
|
|
|
|
- $assign_test = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($assign_test) {
|
|
|
|
|
- $result->latestTest = $test;
|
|
|
|
|
- $result->testerId = $test->tester_id;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $tester_ids = array_column($results, "testerId");
|
|
|
|
|
- User::load($tester_ids);
|
|
|
|
|
-
|
|
|
|
|
- $output = [];
|
|
|
|
|
-
|
|
|
|
|
- foreach($results as $result) {
|
|
|
|
|
-
|
|
|
|
|
- /** @var Location $location */
|
|
|
|
|
- $location = $result->location;
|
|
|
|
|
-
|
|
|
|
|
- /** @var Test $test */
|
|
|
|
|
- $test = $result->latestTest;
|
|
|
|
|
-
|
|
|
|
|
- $customer_slug = Util::slug($customer->name, "_");
|
|
|
|
|
-
|
|
|
|
|
- /** @var User $tester */
|
|
|
|
|
- $tester = null;
|
|
|
|
|
- $formatted_start_dts = null;
|
|
|
|
|
- $formatted_due_dts = null;
|
|
|
|
|
-
|
|
|
|
|
- $icon = null;
|
|
|
|
|
- $icon_file = "{$customer_slug}_none.png";
|
|
|
|
|
-
|
|
|
|
|
- $past_due = false;
|
|
|
|
|
-
|
|
|
|
|
- if($test) {
|
|
|
|
|
-
|
|
|
|
|
- $tester = $test->getTester();
|
|
|
|
|
-
|
|
|
|
|
- if($test->dts_start !== null) {
|
|
|
|
|
- $unix_start = strtotime($test->dts_start);
|
|
|
|
|
- $formatted_start_dts = date("d/m/Y H:i", $unix_start);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($test->isPending()) {
|
|
|
|
|
- $icon_file = "{$customer_slug}_pending.png";
|
|
|
|
|
-
|
|
|
|
|
- $unix_due = null;
|
|
|
|
|
- if($test->dts_due !== null) {
|
|
|
|
|
- $unix_due = strtotime($test->dts_due);
|
|
|
|
|
- $formatted_due_dts = date("d/m/Y H:i", $unix_due);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($tester && $unix_due && time() > $unix_due) {
|
|
|
|
|
- $icon_file = "{$customer_slug}_past_due.png";
|
|
|
|
|
- $past_due = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if($test->pass) {
|
|
|
|
|
- $icon_file = "{$customer_slug}_pass.png";
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- $icon_file = "{$customer_slug}_fail.png";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($location->do_not_test) {
|
|
|
|
|
- $icon_file = "do_not_test.png";
|
|
|
|
|
- }
|
|
|
|
|
- if($location->closed) {
|
|
|
|
|
- $icon_file = "closed.png";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(file_exists("public/img/markers/$icon_file")) {
|
|
|
|
|
- $icon = $icon_file;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $data = [
|
|
|
|
|
- "id" => (int) $location->id,
|
|
|
|
|
- "internalId" => $location->internal_id,
|
|
|
|
|
- "name" => $location->name,
|
|
|
|
|
- "latitude" => (float) $location->latitude,
|
|
|
|
|
- "longitude" => (float) $location->longitude,
|
|
|
|
|
- "icon" => $icon,
|
|
|
|
|
- "test" => null,
|
|
|
|
|
- "doNotTest" => (bool) $location->do_not_test,
|
|
|
|
|
- "closed" => (bool) $location->closed,
|
|
|
|
|
- "archived" => $location->isArchived(),
|
|
|
|
|
- "testCount" => $result->testCount
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- if($test) {
|
|
|
|
|
- $data["test"] = [
|
|
|
|
|
- "id" => $test->id,
|
|
|
|
|
- "formattedStartDts" => $formatted_start_dts,
|
|
|
|
|
- "formattedDueDts" => $formatted_due_dts,
|
|
|
|
|
- "tester" => null,
|
|
|
|
|
- "pastDue" => $past_due,
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- if($tester) {
|
|
|
|
|
- $data["test"]["tester"] = [
|
|
|
|
|
- "id" => $tester->id,
|
|
|
|
|
- "name" => $tester->getDisplayName(),
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $output[] = $data;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
JSON::success([
|
|
JSON::success([
|
|
@@ -207,7 +58,6 @@ if($submit) {
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Gets all locations for a project
|
|
// Gets all locations for a project
|