From 6fe70d07239177f446a90902c0f832cdc634af8d Mon Sep 17 00:00:00 2001 From: alext Date: Mon, 23 Apr 2018 15:58:04 +0200 Subject: [PATCH] Unavailable dates generation must take into concern the appointment edit mode of the booking page (#433). --- src/application/controllers/Appointments.php | 31 ++++++++++++++++++-- src/assets/js/frontend_book_api.js | 6 +++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/application/controllers/Appointments.php b/src/application/controllers/Appointments.php index 30b8e1ad..76f0ce6f 100755 --- a/src/application/controllers/Appointments.php +++ b/src/application/controllers/Appointments.php @@ -609,12 +609,34 @@ class Appointments extends CI_Controller { $selected_date = new DateTime($selected_date_string); $number_of_days_in_month = (int)$selected_date->format('t'); $unavailable_dates = []; + $manage_mode = filter_var($this->input->get('manage_mode'), FILTER_VALIDATE_BOOLEAN); + + $exclude_appointments = ($_REQUEST['manage_mode'] === 'true') + ? [$_REQUEST['appointment_id']] + : []; // Handle the "Any Provider" case. if ($provider_id === ANY_PROVIDER) { $provider_id = $this->_search_any_provider($service_id, $selected_date_string); + if ($provider_id === null) { + $current_date = new DateTime($selected_date_string); + $current_date->add(new DateInterval('P1D')); + + do + { + $provider_id = $this->_search_any_provider($service_id, $current_date->format('Y-m-d H:i:s')); + + if ($provider_id) + { + break; + } + + $current_date->add(new DateInterval('P1D')); + } while ((int)$current_date->format('d') <= $number_of_days_in_month); + } + if ($provider_id === NULL) { // No provider is available in the selected date. @@ -653,10 +675,10 @@ class Appointments extends CI_Controller { $empty_periods = $this->_get_provider_available_time_periods($provider_id, $service_id, - $current_date->format('Y-m-d')); + $current_date->format('Y-m-d'), $exclude_appointments); $available_hours = $this->_calculate_available_hours($empty_periods, $current_date->format('Y-m-d'), - $service['duration'], FALSE, $service['availabilities_type']); + $service['duration'], $manage_mode, $service['availabilities_type']); if ($service['attendants_number'] > 1) { @@ -871,6 +893,11 @@ class Appointments extends CI_Controller { $remove_current_period = TRUE; } + if ($break_start == $period_start && $break_end == $period_end) + { + $remove_current_period = TRUE; + } + if ($remove_current_period) { unset($periods[$key]); diff --git a/src/assets/js/frontend_book_api.js b/src/assets/js/frontend_book_api.js index 4e08835d..1b96e0e8 100755 --- a/src/assets/js/frontend_book_api.js +++ b/src/assets/js/frontend_book_api.js @@ -207,12 +207,16 @@ window.FrontendBookApi = window.FrontendBookApi || {}; return; } + var appointmentId = FrontendBook.manageMode ? GlobalVariables.appointmentData.id : undefined; + var url = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_unavailable_dates'; var data = { provider_id: providerId, service_id: serviceId, selected_date: encodeURIComponent(selectedDateString), - csrfToken: GlobalVariables.csrfToken + csrfToken: GlobalVariables.csrfToken, + manage_mode: FrontendBook.manageMode, + appointment_id: appointmentId }; $.ajax({