From 850218665c7bd7c56c91dfe585ea5f67bc236516 Mon Sep 17 00:00:00 2001 From: Cliff Ingham Date: Wed, 23 Sep 2020 10:08:59 -0400 Subject: [PATCH] Show nearby tickets Nearby tickets are within a bounding box of 0.0002 latitude I think this is roughly 10 meters radius Updates #376 --- crm/blocks/html/locations/locationInfo.inc | 12 ++++++++++++ crm/src/Application/Models/TicketTable.php | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crm/blocks/html/locations/locationInfo.inc b/crm/blocks/html/locations/locationInfo.inc index 79ad42d5..5d751424 100644 --- a/crm/blocks/html/locations/locationInfo.inc +++ b/crm/blocks/html/locations/locationInfo.inc @@ -61,6 +61,7 @@ if ($this->location || ($this->ticket->getLatitude() && $this->ticket->getLongit $t = $this->ticket ? 1 : 0; + // Other tickets at this location if ($tickets) { $block = new Block('tickets/ticketList.inc', [ 'ticketList' => $tickets, @@ -71,6 +72,17 @@ if ($this->location || ($this->ticket->getLatitude() && $this->ticket->getLongit if ($this->ticket) { $block->filterTicket = $this->ticket; } echo $block->render('html', $this->template); } + + // Other nearby tickets + if ($this->ticket->getLatitude() && $this->ticket->getLongitude()) { + $bbox = TicketTable::nearbyBoundingBox($this->ticket->getLatitude(), $this->ticket->getLongitude()); + $tickets = $table->find(['bbox'=>implode(',', $bbox)]); + + $block->ticketList = $tickets; + $block->title = 'Nearby tickets'; + $block->fields = ['status', 'enteredDate', 'location']; + echo $block->render('html', $this->template); + } echo " "; diff --git a/crm/src/Application/Models/TicketTable.php b/crm/src/Application/Models/TicketTable.php index 927f1ae5..5b2cbfaf 100644 --- a/crm/src/Application/Models/TicketTable.php +++ b/crm/src/Application/Models/TicketTable.php @@ -160,4 +160,17 @@ public static function isValidSearch($request) )) ? true : false; } + /** + * Prepares a bounding box for finding nearby tickets + * @see self::find() + */ + public static function nearbyBoundingBox(float $lat, float $lon): array + { + return [ + $lat - 0.0001, + $lon - 0.0001, + $lat + 0.0001, + $lon + 0.0001 + ]; + } }