Add checking for hub slots. #651

This commit is contained in:
Korina Cordero 2022-03-24 05:07:26 +00:00
parent d8f5b7833d
commit b7c5f5dafe

View file

@ -4330,7 +4330,7 @@ class APIController extends Controller implements LoggedController
// find the nearest hub
if (!empty($nearest_hubs_with_distance))
{
// TODO: get slots of nearest hub right after getting nearest hub.
// get slots of nearest hub right after getting nearest hub.
// then check if hub has available slots. If not, get next nearest hub.
foreach ($nearest_hubs_with_distance as $nhd)
{
@ -4339,21 +4339,27 @@ class APIController extends Controller implements LoggedController
else
{
if ($nhd['distance'] < $nearest['distance'])
$nearest = $nhd;
}
}
// get slots of nearest hub
if ($nearest != null)
{
$hub_slots = $this->getHubRiderSlots($nearest['hub'], $em);
// get the slots for nearest which is nhd right now
$hub_slots = $this->getHubRiderSlots($nhd['hub'], $em);
$flag_hub_available = $hub_slots['flag_hub_available'];
// if hub is available, set hub to nearest
if ($flag_hub_available == true)
{
$nearest = $nhd;
// temporarily set hub_data to nearest
$hub_data = [
'hub' => $nearest['hub'],
'slots' => $hub_slots,
'hub' => $nhd['hub'],
'slots' => $hub_slots['slot_data'],
];
}
}
}
}
}
return $hub_data;
@ -4477,6 +4483,8 @@ class APIController extends Controller implements LoggedController
$hub_slots = $this->generateHubSlots($hub_rider_slots, $slots);
error_log(print_r($hub_slots, true));
return $hub_slots;
}
@ -4513,9 +4521,11 @@ class APIController extends Controller implements LoggedController
}
// check if hub has available slots
$hub_unavailable = false;
$hub_available = true;
error_log('total rider slots ' . $total_rslots);
error_log('total unavailable slots ' . $total_unavailable_slots);
if ($total_rslots == $total_unavailable_rslots)
$hub_unavailable = true;
$hub_available = false;
$hs_data = [
'flag_hub_available' => $hub_unavailable,