Fix when no hubs are found. #392
This commit is contained in:
parent
b3b46bca7b
commit
b66ebf7eeb
2 changed files with 60 additions and 15 deletions
|
|
@ -164,3 +164,8 @@ api_version_check:
|
|||
path: /api/version_check
|
||||
controller: App\Controller\APIController::versionCheck
|
||||
methods: [GET]
|
||||
|
||||
api_schedule_option_status:
|
||||
path: /api/schedule_option_status
|
||||
controller: App\Controller\APIController::scheduleOptionStatus
|
||||
methods: [GET]
|
||||
|
|
|
|||
|
|
@ -2687,6 +2687,42 @@ class APIController extends Controller implements LoggedController
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function scheduleOptionStatus(Request $req)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// TODO: end of ECQ, have this return true
|
||||
$schedule_choice = true;
|
||||
|
||||
// TODO: remove the time check after ECQ
|
||||
// get current time
|
||||
$current_time = time();
|
||||
$start_advance_order_time = strtotime('17:00');
|
||||
$end_advance_order_time = strtotime('08:00');
|
||||
//$start_advance_order_time = strtotime('08:00');
|
||||
//$end_advance_order_time = strtotime('17:00');
|
||||
|
||||
error_log(date('Y-m-d H:i:s', $current_time));
|
||||
error_log(date('Y-m-d H:i:s', $start_advance_order_time));
|
||||
error_log(date('Y-m-d H:i:s', $end_advance_order_time));
|
||||
|
||||
if (($current_time > $start_advance_order_time) &&
|
||||
($current_time < $end_advance_order_time))
|
||||
$schedule_choice = false;
|
||||
|
||||
$data = [
|
||||
'display_schedule_choice' => $schedule_choice,
|
||||
];
|
||||
$res->setData($data);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function findCustomerByNumber($number)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
|
@ -2888,6 +2924,7 @@ class APIController extends Controller implements LoggedController
|
|||
{
|
||||
// get the nearest 10 hubs
|
||||
$hub_data = [];
|
||||
$nearest_hubs_with_distance = [];
|
||||
$hubs = $map_tools->getClosestOpenHubs($coordinates, 10);
|
||||
|
||||
foreach ($hubs as $hub)
|
||||
|
|
@ -2899,26 +2936,29 @@ class APIController extends Controller implements LoggedController
|
|||
$nearest = null;
|
||||
$slot_found = false;
|
||||
// find the nearest hub
|
||||
foreach ($nearest_hubs_with_distance as $nhd)
|
||||
if (!empty($nearest_hubs_with_distance))
|
||||
{
|
||||
if (empty($nearest))
|
||||
$nearest = $nhd;
|
||||
else
|
||||
foreach ($nearest_hubs_with_distance as $nhd)
|
||||
{
|
||||
if ($nhd['distance'] < $nearest['distance'])
|
||||
$nearest = $nhd;
|
||||
if (empty($nearest))
|
||||
$nearest = $nhd;
|
||||
else
|
||||
{
|
||||
if ($nhd['distance'] < $nearest['distance'])
|
||||
$nearest = $nhd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get slots of nearest hub
|
||||
if ($nearest != null)
|
||||
{
|
||||
$hub_slots = $this->getHubRiderSlots($nearest['hub'], $em);
|
||||
// get slots of nearest hub
|
||||
if ($nearest != null)
|
||||
{
|
||||
$hub_slots = $this->getHubRiderSlots($nearest['hub'], $em);
|
||||
|
||||
$hub_data = [
|
||||
'hub' => $nearest['hub'],
|
||||
'slots' => $hub_slots,
|
||||
];
|
||||
$hub_data = [
|
||||
'hub' => $nearest['hub'],
|
||||
'slots' => $hub_slots,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $hub_data;
|
||||
|
|
|
|||
Loading…
Reference in a new issue