|
|
@@ -20,17 +20,58 @@ if($submit) {
|
|
|
|
|
|
$locations = $customer->getLocations();
|
|
|
|
|
|
- $filename = str_replace("-", "_", Util::slug($customer->name));
|
|
|
+ $tests = Test::query([
|
|
|
+ "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
|
|
|
+ "location_id" => array_column($locations, "id")
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $location_test_array = [];
|
|
|
+ foreach($tests as $test) {
|
|
|
+ $exists = isset($location_test_array[$test->location_id]);
|
|
|
+ if(!$exists) {
|
|
|
+ $location_test_array[$test->location_id] = $test;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $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");
|
|
|
|
|
|
- $icon = null;
|
|
|
- if(file_exists("public/img/markers/$filename.png")) {
|
|
|
- $icon = "/img/markers/$filename.png";
|
|
|
+ if($unix_start_current > $unix_start_existing) {
|
|
|
+ $location_test_array[$test->location_id] = $test;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
foreach($locations as $location) {
|
|
|
- $output[] = [
|
|
|
+
|
|
|
+ $test = $location_test_array[$location->id] ?? false;
|
|
|
+
|
|
|
+ $customer_slug = str_replace("-", "_", Util::slug($customer->name));
|
|
|
+
|
|
|
+ $icon = null;
|
|
|
+ $icon_file = "{$customer_slug}_none.png";
|
|
|
+
|
|
|
+ if($test) {
|
|
|
+ if(is_null($test->pass)) {
|
|
|
+ $icon_file = "{$customer_slug}_pending.png";
|
|
|
+ }
|
|
|
+ else if($test->pass) {
|
|
|
+ $icon_file = "{$customer_slug}_pass.png";
|
|
|
+ }
|
|
|
+ else if(!$test->pass) {
|
|
|
+ $icon_file = "{$customer_slug}_fail.png";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if($icon_file && file_exists("public/img/markers/$icon_file")) {
|
|
|
+ $icon = $icon_file;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
"id" => (int) $location->id,
|
|
|
"internalId" => $location->internal_id,
|
|
|
"name" => $location->name,
|
|
|
@@ -38,6 +79,8 @@ if($submit) {
|
|
|
"longitude" => (float) $location->longitude,
|
|
|
"icon" => $icon
|
|
|
];
|
|
|
+
|
|
|
+ $output[] = $data;
|
|
|
}
|
|
|
|
|
|
JSON::success([
|