From ab20d27c33fbee32a26039e1b732c4b0503af5c8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 13 Jun 2022 09:48:53 +0000 Subject: [PATCH] Add blacklist checking in geofence service. #685 --- src/Service/GeofenceTracker.php | 51 ++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/Service/GeofenceTracker.php b/src/Service/GeofenceTracker.php index 5acc7564..fbe11e47 100644 --- a/src/Service/GeofenceTracker.php +++ b/src/Service/GeofenceTracker.php @@ -3,6 +3,7 @@ namespace App\Service; use App\Entity\SupportedArea; +use App\Entity\BlacklistArea; use Doctrine\ORM\EntityManagerInterface; @@ -24,20 +25,56 @@ class GeofenceTracker // check if geofence is enabled if ($this->geofence_flag == 'true') { - // see if the point is in any of the polygons - $query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true') - ->setParameter('long', $long) - ->setParameter('lat', $lat); + // see if the point is in whitelist + $in_whitelist = $this->checkWhitelist($long, $lat); - // number of polygons that contain the point - $count = $query->getSingleScalarResult(); + if ($in_whitelist) + { + // point is in whitelist + // check if point is in blacklist + $in_blacklist = $this->checkBlacklist($long, $lat); + + if ($in_blacklist) + return false; - if ($count > 0) return true; + } return false; } return true; } + + protected function checkWhitelist($long, $lat) + { + // check if point is in the whitelist + $query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s + WHERE st_contains(s.coverage_area, point(:long, :lat)) = true') + ->setParameter('long', $long) + ->setParameter('lat', $lat); + + // number of polygons that contain the point + $count = $query->getSingleScalarResult(); + + if ($count > 0) + return true; + + return false; + } + + protected function checkBlacklist($long, $lat) + { + $query = $this->em->createQuery('SELECT count(s) from App\Entity\BlacklistArea s + WHERE st_contains(s.coverage_area, point(:long, :lat)) = true') + ->setParameter('long', $long) + ->setParameter('lat', $lat); + + $count = $query->getSingleScalarResult(); + + if ($count > 0) + return true; + + return false; + } }