From 9550e1e46c2873c85a478ec70b94417d463917dd Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 9 May 2020 21:39:53 +0800 Subject: [PATCH] Fix getClosestOpenHubs bug #403 --- src/Service/MapTools.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Service/MapTools.php b/src/Service/MapTools.php index b60130a0..e1eac52e 100644 --- a/src/Service/MapTools.php +++ b/src/Service/MapTools.php @@ -158,13 +158,17 @@ class MapTools public function getClosestOpenHubs(Point $point, $limit, $time = false) { // get closest hubs based on st_distance function from db - $query = $this->em->createQuery('SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h' . ($time ? ' WHERE h.status_open = true AND :time BETWEEN h.time_open AND h.time_close' : '') . ' ORDER BY dist') + $query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h WHERE h.status_open = true'; + if ($time) + $query_string .= ' AND :time BETWEEN h.time_open AND h.time_close'; + $query_string .= ' ORDER BY dist'; + + $query = $this->em->createQuery($query_string) ->setParameter('lat', $point->getLatitude()) ->setParameter('lng', $point->getLongitude()); - if ($time) { + if ($time) $query->setParameter('time', $time); - } $query->setMaxResults($limit);