diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9fdd58a2..17aac2d9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4306,9 +4306,11 @@ class APIController extends Controller implements LoggedController // get the slots of hub $hub_slots = $this->getHubRiderSlots($hub, $em); + $slots = $hub_slots['slot_data']; + $hub_data = [ 'hub' => $hub, - 'slots' => $hub_slots, + 'slots' => $slots, ]; return $hub_data; } @@ -4328,6 +4330,8 @@ 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. + // then check if hub has available slots. If not, get next nearest hub. foreach ($nearest_hubs_with_distance as $nhd) { if (empty($nearest)) @@ -4479,12 +4483,17 @@ class APIController extends Controller implements LoggedController protected function generateHubSlots($rider_slots, $slots) { $data = []; + $total_rslots = 0; + $total_unavailable_rslots = 0; foreach ($rider_slots as $day_id => $rslot) { $data[$day_id] = []; foreach ($rslot as $slot_id => $avail_slots) { + // increment total rider slots + $total_rslots++; + $slot_data = [ 'id' => $slot_id, 'label' => $slots[$slot_id], @@ -4493,14 +4502,27 @@ class APIController extends Controller implements LoggedController // mark unavailable ones if ($avail_slots <= 0) + { // increment total number of unavailable slots + $total_unavailable_rslots++; $slot_data['available'] = false; + } // add to day data $data[$day_id][] = $slot_data; } } - return $data; + // check if hub has available slots + $hub_unavailable = false; + if ($total_rslots == $total_unavailable_rslots) + $hub_unavailable = true; + + $hs_data = [ + 'flag_hub_available' => $hub_unavailable, + 'slot_data' => $data, + ]; + + return $hs_data; } protected function getTimeFromSlot($slot_id)