43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\SupportedArea;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
|
|
|
class GeofenceTracker
|
|
{
|
|
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\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;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|