diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 45022f09..050d1bc5 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1015,7 +1015,7 @@ class APIController extends Controller implements LoggedController } else { - $nearest_hub = $this->findAdvanceNearestHub($jo, $request_time, $em, $map_tools); + $nearest_hub = $this->findAdvanceNearestHub($jo, $request_time_in_int, $em, $map_tools); } if (!empty($nearest_hub)) @@ -2731,40 +2731,88 @@ class APIController extends Controller implements LoggedController { // get time schedule $date_schedule = $advance_jo->getDateSchedule(); - $time_schedule = $date_schedule->format('H'); + $time_schedule = $date_schedule->format('H:i'); - switch ($time_schedule) { - case '8': - $hub_rider_slots[0]--; - break; - case '9': - $hub_rider_slots[1]--; - break; - case '10': - $hub_rider_slots[2]--; - break; - case '11': - $hub_rider_slots[3]--; - break; - case '12': - $hub_rider_slots[4]--; - break; - case '13': - $hub_rider_slots[5]--; - break; - case '14': - $hub_rider_slots[6]--; - break; - case '15': - $hub_rider_slots[7]--; - break; - default: - error_log('Does not fit in any time slot.'); + $hour_schedule = $date_schedule->format('H'); + $minute_schedule = $date_schedule->format('i'); + + // check minutes. for now, if not 00, take up current slot and next one + // if hour fits in the last slot but minutes is not 00, move to the next available hub + // TODO: need to add custom minutes threshold + if ($minute_schedule != '00') + { + switch($hour_schedule) { + case '8': + $hub_rider_slots[0]--; + $hub_rider_slots[1]--; + break; + case '9': + $hub_rider_slots[1]--; + $hub_rider_slots[2]--; + break; + case '10': + $hub_rider_slots[2]--; + $hub_rider_slots[3]--; + break; + case '11': + $hub_rider_slots[3]--; + $hub_rider_slots[4]--; + break; + case '12': + $hub_rider_slots[4]--; + $hub_rider_slots[5]--; + break; + case '13': + $hub_rider_slots[5]--; + $hub_rider_slots[6]--; + break; + case '14': + $hub_rider_slots[6]--; + $hub_rider_slots[7]--; + break; + case '15': + error_log('No slots for the day'); + break; + default: + error_log('Does not fit in any time slot. ' . $time_schedule); + } } + else + { + switch ($hour_schedule) { + case '8': + $hub_rider_slots[0]--; + break; + case '9': + $hub_rider_slots[1]--; + break; + case '10': + $hub_rider_slots[2]--; + break; + case '11': + $hub_rider_slots[3]--; + break; + case '12': + $hub_rider_slots[4]--; + break; + case '13': + $hub_rider_slots[5]--; + break; + case '14': + $hub_rider_slots[6]--; + break; + case '15': + $hub_rider_slots[7]--; + break; + default: + error_log('Does not fit in any time slot.' . $time_schedule); + } + } + } // find first free slot - foreach ($hub_rider_slots as $index=>$rider_slot) + foreach ($hub_rider_slots as $index => $rider_slot) { if ($rider_slot > 0) { @@ -2808,9 +2856,6 @@ class APIController extends Controller implements LoggedController break; } } - return $results; - } - }