From b7c5f5dafe2edd38e56d7b3a2e0b6ad35851e069 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:07:26 +0000 Subject: [PATCH] Add checking for hub slots. #651 --- src/Controller/APIController.php | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 17aac2d9..5d6b16d2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -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,20 +4339,26 @@ class APIController extends Controller implements LoggedController else { if ($nhd['distance'] < $nearest['distance']) - $nearest = $nhd; + { + // 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' => $nhd['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + } + } } } - - // get slots of nearest hub - if ($nearest != null) - { - $hub_slots = $this->getHubRiderSlots($nearest['hub'], $em); - - $hub_data = [ - 'hub' => $nearest['hub'], - 'slots' => $hub_slots, - ]; - } } 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,