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();
|
||||
|
||||
// get closest outlets
|
||||
$outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10);
|
||||
$outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10, date("H:i:s"));
|
||||
|
||||
$params['outlets'] = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class MapTools
|
|||
'destinations' => $dests_value,
|
||||
];
|
||||
|
||||
error_log(print_r($gmaps_params, true));
|
||||
//error_log(print_r($gmaps_params, true));
|
||||
|
||||
|
||||
// query google maps api
|
||||
|
|
@ -57,13 +57,19 @@ class MapTools
|
|||
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
|
||||
$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('lng', $point->getLongitude())
|
||||
->setMaxResults($limit);
|
||||
->setParameter('lng', $point->getLongitude());
|
||||
|
||||
if ($time) {
|
||||
$query->setParameter('time', $time);
|
||||
}
|
||||
|
||||
$query->setMaxResults($limit);
|
||||
|
||||
// error_log($query->getSql());
|
||||
$result = $query->getResult();
|
||||
|
||||
|
|
@ -71,7 +77,7 @@ class MapTools
|
|||
$final_data = [];
|
||||
foreach ($result as $row)
|
||||
{
|
||||
error_log($row[0]->getName() . ' - ' . $row['dist']);
|
||||
//error_log($row[0]->getName() . ' - ' . $row['dist']);
|
||||
$outlets[] = $row[0];
|
||||
$final_data[] = [
|
||||
'outlet' => $row[0],
|
||||
|
|
@ -84,7 +90,7 @@ class MapTools
|
|||
// get actual distance details with eta from google maps api
|
||||
$raw_res = $this->mapGetDistances($point, $outlets);
|
||||
$res = json_decode($raw_res, true);
|
||||
error_log(print_r($res, true));
|
||||
//error_log(print_r($res, true));
|
||||
|
||||
// check if status is ok
|
||||
if ($res['status'] != 'OK')
|
||||
|
|
|
|||
Loading…
Reference in a new issue