resq/src/Service/HubFilteringGeoChecker.php
2021-07-29 06:40:07 +00:00

44 lines
1.1 KiB
PHP

<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use App\Entity\HubFilterArea;
class HubFilteringGeoChecker
{
protected $em;
protected $geofence_flag;
public function __construct(EntityManagerInterface $em, $geofence_flag)
{
$this->em = $em;
$this->geofence_flag = $geofence_flag;
}
public function isCovered($long, $lat)
{
// 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\HubFilterArea 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;
}
return true;
}
}