Move retrieval of env variable to the geofence service. #271
This commit is contained in:
parent
e169766efd
commit
f6dce241ac
4 changed files with 29 additions and 26 deletions
|
|
@ -44,4 +44,4 @@ POLICY_MOBILE=insertmobilepolicyidhere
|
||||||
OTP_MODE=settotestorrandom
|
OTP_MODE=settotestorrandom
|
||||||
|
|
||||||
# geofence
|
# geofence
|
||||||
GEOFENCE=settotrueorfalse
|
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"
|
||||||
|
|
|
||||||
|
|
@ -840,14 +840,6 @@ class APIController extends Controller
|
||||||
$lat = $req->request->get('lat');
|
$lat = $req->request->get('lat');
|
||||||
|
|
||||||
// geofence
|
// geofence
|
||||||
// check if geofence is on
|
|
||||||
$dotenv = new Dotenv();
|
|
||||||
$dotenv->loadEnv(__DIR__.'/../../.env');
|
|
||||||
|
|
||||||
$geo_flag = $_ENV['GEOFENCE'];
|
|
||||||
|
|
||||||
if ($geo_flag == 'true')
|
|
||||||
{
|
|
||||||
$is_covered = $geo->isCovered($long, $lat);
|
$is_covered = $geo->isCovered($long, $lat);
|
||||||
if (!$is_covered)
|
if (!$is_covered)
|
||||||
{
|
{
|
||||||
|
|
@ -856,7 +848,6 @@ class APIController extends Controller
|
||||||
->setErrorMessage('Oops! Our service is limited to some areas in Laguna and Baguio, and 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 Laguna and Baguio, and Metro Manila 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,13 +11,18 @@ 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)
|
||||||
|
{
|
||||||
|
// check if geofence is enabled
|
||||||
|
if ($this->geofence_flag == 'true')
|
||||||
{
|
{
|
||||||
// see if the point is in any of the polygons
|
// 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')
|
$query = $this->em->createQuery('SELECT count(s) from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true')
|
||||||
|
|
@ -32,4 +37,7 @@ class GeofenceTracker
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue