Add blacklist checking in geofence service. #685

This commit is contained in:
Korina Cordero 2022-06-13 09:48:53 +00:00
parent 738cd74522
commit ab20d27c33

View file

@ -3,6 +3,7 @@
namespace App\Service; namespace App\Service;
use App\Entity\SupportedArea; use App\Entity\SupportedArea;
use App\Entity\BlacklistArea;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -24,20 +25,56 @@ class GeofenceTracker
// check if geofence is enabled // check if geofence is enabled
if ($this->geofence_flag == 'true') if ($this->geofence_flag == 'true')
{ {
// see if the point is in any of the polygons // see if the point is in whitelist
$query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true') $in_whitelist = $this->checkWhitelist($long, $lat);
->setParameter('long', $long)
->setParameter('lat', $lat);
// number of polygons that contain the point if ($in_whitelist)
$count = $query->getSingleScalarResult(); {
// 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 true;
}
return false; return false;
} }
return true; 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;
}
} }