Merge branch '271-fix-geofence-issue' into 'master'
Resolve "Fix geofence issue" Closes #271 See merge request jankstudio/resq!318
This commit is contained in:
commit
2c606b7a13
4 changed files with 26 additions and 14 deletions
|
|
@ -42,3 +42,6 @@ POLICY_MOBILE=insertmobilepolicyidhere
|
||||||
|
|
||||||
# OTP
|
# OTP
|
||||||
OTP_MODE=settotestorrandom
|
OTP_MODE=settotestorrandom
|
||||||
|
|
||||||
|
# geofence
|
||||||
|
GEOFENCE_ENABLE=settotrueorfalse
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,10 @@ services:
|
||||||
$password: "%env(REDIS_CLIENT_PASSWORD)%"
|
$password: "%env(REDIS_CLIENT_PASSWORD)%"
|
||||||
$env_flag: "dev"
|
$env_flag: "dev"
|
||||||
|
|
||||||
|
App\Service\GeofenceTracker:
|
||||||
|
arguments:
|
||||||
|
$geofence_flag: "%env(GEOFENCE_ENABLE)%"
|
||||||
|
|
||||||
Catalyst\APIBundle\Security\APIKeyUserProvider:
|
Catalyst\APIBundle\Security\APIKeyUserProvider:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
|
|
|
||||||
|
|
@ -839,18 +839,15 @@ class APIController extends Controller
|
||||||
$long = $req->request->get('long');
|
$long = $req->request->get('long');
|
||||||
$lat = $req->request->get('lat');
|
$lat = $req->request->get('lat');
|
||||||
|
|
||||||
/*
|
|
||||||
// geofence
|
// geofence
|
||||||
$is_covered = $geo->isCovered($long, $lat);
|
$is_covered = $geo->isCovered($long, $lat);
|
||||||
if (!$is_covered)
|
if (!$is_covered)
|
||||||
{
|
{
|
||||||
// TODO: put geofence error message in config file somewhere
|
// TODO: put geofence error message in config file somewhere
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Oops! Our service is limited to Metro Manila only. We will update you as soon as we are able to cover your area');
|
->setErrorMessage('Oops! Our service is limited to some areas in Metro Manila, Laguna, and Baguio only. We will update you as soon as we are able to cover your area');
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
$jo = new JobOrder();
|
$jo = new JobOrder();
|
||||||
$jo->setSource(TransactionOrigin::MOBILE_APP)
|
$jo->setSource(TransactionOrigin::MOBILE_APP)
|
||||||
|
|
|
||||||
|
|
@ -11,25 +11,33 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
class GeofenceTracker
|
class GeofenceTracker
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $geofence_flag;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, $geofence_flag)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->geofence_flag = $geofence_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCovered($long, $lat)
|
public function isCovered($long, $lat)
|
||||||
{
|
{
|
||||||
// see if the point is in any of the polygons
|
// check if geofence is enabled
|
||||||
$query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true')
|
if ($this->geofence_flag == 'true')
|
||||||
->setParameter('long', $long)
|
{
|
||||||
->setParameter('lat', $lat);
|
// 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
|
// number of polygons that contain the point
|
||||||
$count = $query->getSingleScalarResult();
|
$count = $query->getSingleScalarResult();
|
||||||
|
|
||||||
if ($count > 0)
|
if ($count > 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue