Add blacklist checking in geofence service. #685
This commit is contained in:
parent
738cd74522
commit
ab20d27c33
1 changed files with 44 additions and 7 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue