From 8c836bf10cd70df7e5478c41824a753943f1dd5a Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 21 Nov 2020 22:16:53 +0200 Subject: [PATCH] Multiple attendant number generation must take into consideration the working plan exceptions --- application/libraries/Availability.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/application/libraries/Availability.php b/application/libraries/Availability.php index 4a4e2b96..744a36bb 100644 --- a/application/libraries/Availability.php +++ b/application/libraries/Availability.php @@ -342,22 +342,29 @@ class Availability { ]); $working_plan = json_decode($provider['settings']['working_plan'], TRUE); + $working_plan_exceptions = json_decode($provider['settings']['working_plan_exceptions'], TRUE); $working_day = strtolower(date('l', strtotime($date))); - $working_hours = $working_plan[$working_day]; + $date_working_plan = $working_plan[$working_day]; - if ( ! $working_hours) + // Search if the $date is an custom availability period added outside the normal working plan. + if (isset($working_plan_exceptions[$date])) + { + $date_working_plan = $working_plan_exceptions[$date]; + } + + if ( ! $date_working_plan) { return []; } $periods = [ [ - 'start' => new DateTime($date . ' ' . $working_hours['start']), - 'end' => new DateTime($date . ' ' . $working_hours['end']) + 'start' => new DateTime($date . ' ' . $date_working_plan['start']), + 'end' => new DateTime($date . ' ' . $date_working_plan['end']) ] ]; - $periods = $this->remove_breaks($date, $periods, $working_hours['breaks']); + $periods = $this->remove_breaks($date, $periods, $date_working_plan['breaks']); $periods = $this->remove_unavailability_events($periods, $unavailability_events); $hours = [];