|
@@ -41,6 +41,7 @@ switch($action) {
|
|
|
|
|
|
|
|
if(!$address) throw new Exception("Cannot find address.");
|
|
if(!$address) throw new Exception("Cannot find address.");
|
|
|
|
|
|
|
|
|
|
+ // Get locations according to bounds
|
|
|
$bounds = Geolocation::getBounds($address->getGeolocation(), $max_distance);
|
|
$bounds = Geolocation::getBounds($address->getGeolocation(), $max_distance);
|
|
|
|
|
|
|
|
list($min_lat, $min_lng) = $bounds->southWest;
|
|
list($min_lat, $min_lng) = $bounds->southWest;
|
|
@@ -52,32 +53,102 @@ switch($action) {
|
|
|
"closed" => 0
|
|
"closed" => 0
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+ // Get customers
|
|
|
$customers = Customer::load(array_column($locations, "customer_id"));
|
|
$customers = Customer::load(array_column($locations, "customer_id"));
|
|
|
|
|
|
|
|
|
|
+ // Sort locations by distance
|
|
|
usort($locations, function($a, $b) use ($address) {
|
|
usort($locations, function($a, $b) use ($address) {
|
|
|
return
|
|
return
|
|
|
Geolocation::getDistance($address->getGeolocation(), $a->getGeolocation())
|
|
Geolocation::getDistance($address->getGeolocation(), $a->getGeolocation())
|
|
|
<=>
|
|
<=>
|
|
|
Geolocation::getDistance($address->getGeolocation(), $b->getGeolocation());
|
|
Geolocation::getDistance($address->getGeolocation(), $b->getGeolocation());
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ // Get tests
|
|
|
|
|
+ $tests = Test::query([
|
|
|
|
|
+ "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
|
|
|
|
|
+ "location_id" => array_column($locations, "id")
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
- foreach($locations as $location) {
|
|
|
|
|
|
|
+ $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");
|
|
|
|
|
|
|
|
|
|
+ if($unix_start_current > $unix_start_existing) {
|
|
|
|
|
+ $location_test_array[$test->location_id] = $test;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Start output
|
|
|
|
|
+ foreach($locations as $location) {
|
|
|
|
|
+
|
|
|
|
|
+ // Filter by distance
|
|
|
$distance = Geolocation::getDistance($address->getGeolocation(), $location->getGeolocation());
|
|
$distance = Geolocation::getDistance($address->getGeolocation(), $location->getGeolocation());
|
|
|
if($distance > $max_distance) continue;
|
|
if($distance > $max_distance) continue;
|
|
|
|
|
|
|
|
- $customer = $location->getCustomer();
|
|
|
|
|
|
|
+ // Get test
|
|
|
|
|
+ $test = $location_test_array[$location->id] ?? false;
|
|
|
|
|
|
|
|
|
|
+ // Get customer
|
|
|
|
|
+ $customer = $location->getCustomer();
|
|
|
$customer_slug = str_replace("-", "_", Util::slug($customer->name));
|
|
$customer_slug = str_replace("-", "_", Util::slug($customer->name));
|
|
|
|
|
|
|
|
|
|
+ // Test
|
|
|
|
|
+ $tester = null;
|
|
|
|
|
+ $formatted_start_dts = null;
|
|
|
|
|
+ $formatted_due_dts = null;
|
|
|
|
|
+ $past_due = false;
|
|
|
|
|
+
|
|
|
|
|
+ // Icon
|
|
|
$icon = null;
|
|
$icon = null;
|
|
|
- $icon_file = "{$customer_slug}.png";
|
|
|
|
|
|
|
+ $icon_file = "{$customer_slug}_none.png";
|
|
|
|
|
+
|
|
|
|
|
+ // Process test
|
|
|
|
|
+ if($test) {
|
|
|
|
|
+ $tester = $test->getTester();
|
|
|
|
|
+
|
|
|
|
|
+ if(!is_null($test->dts_start)) {
|
|
|
|
|
+ $unix_start = strtotime($test->dts_start);
|
|
|
|
|
+ $formatted_start_dts = date("d/m/Y H:i", $unix_start);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(is_null($test->pass)) {
|
|
|
|
|
+ $icon_file = "{$customer_slug}_pending.png";
|
|
|
|
|
+
|
|
|
|
|
+ // Has due date
|
|
|
|
|
+ if(!is_null($test->dts_due)) {
|
|
|
|
|
+ $unix_due = strtotime($test->dts_due);
|
|
|
|
|
+ $formatted_due_dts = date("d/m/Y H:i", $unix_due);
|
|
|
|
|
+
|
|
|
|
|
+ if($tester && time() > $unix_due) {
|
|
|
|
|
+ $icon_file = "{$customer_slug}_past_due.png";
|
|
|
|
|
+ $past_due = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ 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")) {
|
|
if($icon_file && file_exists("public/img/markers/$icon_file")) {
|
|
|
$icon = $icon_file;
|
|
$icon = $icon_file;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $output[] = [
|
|
|
|
|
|
|
+ $data = [
|
|
|
"id" => (int) $location->id,
|
|
"id" => (int) $location->id,
|
|
|
"internalId" => (int) $location->internal_id,
|
|
"internalId" => (int) $location->internal_id,
|
|
|
"name" => $location->name,
|
|
"name" => $location->name,
|
|
@@ -86,7 +157,27 @@ switch($action) {
|
|
|
"latitude" => (double) $location->latitude,
|
|
"latitude" => (double) $location->latitude,
|
|
|
"longitude" => (double) $location->longitude,
|
|
"longitude" => (double) $location->longitude,
|
|
|
"icon" => $icon,
|
|
"icon" => $icon,
|
|
|
|
|
+ "test" => null,
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
|
|
+ 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([
|