Filter nearest outlets by open and close times
This commit is contained in:
parent
f125d50778
commit
2b4c289ba9
2 changed files with 14 additions and 8 deletions
|
|
@ -261,7 +261,7 @@ class JobOrderController extends BaseController
|
||||||
$params['statuses'] = JOStatus::getCollection();
|
$params['statuses'] = JOStatus::getCollection();
|
||||||
|
|
||||||
// get closest outlets
|
// get closest outlets
|
||||||
$outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10);
|
$outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10, date("H:i:s"));
|
||||||
|
|
||||||
$params['outlets'] = [];
|
$params['outlets'] = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class MapTools
|
||||||
'destinations' => $dests_value,
|
'destinations' => $dests_value,
|
||||||
];
|
];
|
||||||
|
|
||||||
error_log(print_r($gmaps_params, true));
|
//error_log(print_r($gmaps_params, true));
|
||||||
|
|
||||||
|
|
||||||
// query google maps api
|
// query google maps api
|
||||||
|
|
@ -57,13 +57,19 @@ class MapTools
|
||||||
return $res->getBody();
|
return $res->getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClosestOutlets(Point $point, $limit)
|
public function getClosestOutlets(Point $point, $limit, $time = false)
|
||||||
{
|
{
|
||||||
// get closest outlets based on st_distance function from db
|
// get closest outlets based on st_distance function from db
|
||||||
$query = $this->em->createQuery('SELECT o, st_distance(o.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Outlet o ORDER BY dist')
|
$query = $this->em->createQuery('SELECT o, st_distance(o.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Outlet o' . ($time ? ' WHERE :time BETWEEN o.time_open AND o.time_close' : '') . ' ORDER BY dist')
|
||||||
->setParameter('lat', $point->getLatitude())
|
->setParameter('lat', $point->getLatitude())
|
||||||
->setParameter('lng', $point->getLongitude())
|
->setParameter('lng', $point->getLongitude());
|
||||||
->setMaxResults($limit);
|
|
||||||
|
if ($time) {
|
||||||
|
$query->setParameter('time', $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->setMaxResults($limit);
|
||||||
|
|
||||||
// error_log($query->getSql());
|
// error_log($query->getSql());
|
||||||
$result = $query->getResult();
|
$result = $query->getResult();
|
||||||
|
|
||||||
|
|
@ -71,7 +77,7 @@ class MapTools
|
||||||
$final_data = [];
|
$final_data = [];
|
||||||
foreach ($result as $row)
|
foreach ($result as $row)
|
||||||
{
|
{
|
||||||
error_log($row[0]->getName() . ' - ' . $row['dist']);
|
//error_log($row[0]->getName() . ' - ' . $row['dist']);
|
||||||
$outlets[] = $row[0];
|
$outlets[] = $row[0];
|
||||||
$final_data[] = [
|
$final_data[] = [
|
||||||
'outlet' => $row[0],
|
'outlet' => $row[0],
|
||||||
|
|
@ -84,7 +90,7 @@ class MapTools
|
||||||
// get actual distance details with eta from google maps api
|
// get actual distance details with eta from google maps api
|
||||||
$raw_res = $this->mapGetDistances($point, $outlets);
|
$raw_res = $this->mapGetDistances($point, $outlets);
|
||||||
$res = json_decode($raw_res, true);
|
$res = json_decode($raw_res, true);
|
||||||
error_log(print_r($res, true));
|
//error_log(print_r($res, true));
|
||||||
|
|
||||||
// check if status is ok
|
// check if status is ok
|
||||||
if ($res['status'] != 'OK')
|
if ($res['status'] != 'OK')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue