diff --git a/application/libraries/Availability.php b/application/libraries/Availability.php index 8d741838..41360f00 100644 --- a/application/libraries/Availability.php +++ b/application/libraries/Availability.php @@ -39,6 +39,7 @@ class Availability { $this->CI->load->model('secretaries_model'); $this->CI->load->model('settings_model'); $this->CI->load->model('unavailabilities_model'); + $this->CI->load->model('blocked_periods_model'); $this->CI->load->library('ics_file'); } @@ -57,6 +58,11 @@ class Availability { */ public function get_available_hours(string $date, array $service, array $provider, int $exclude_appointment_id = NULL): array { + if ($this->CI->blocked_periods_model->is_entire_date_blocked($date)) + { + return []; + } + if ($service['attendants_number'] > 1) { $available_hours = $this->consider_multiple_attendants($date, $service, $provider, $exclude_appointment_id); @@ -117,6 +123,7 @@ class Availability { array_merge( $this->CI->appointments_model->get($where), $this->CI->unavailabilities_model->get($where), + $this->CI->blocked_periods_model->get_for_period($date, $date) ) ); @@ -396,8 +403,11 @@ class Availability { ] ]; + $blocked_periods = $this->CI->blocked_periods_model->get_for_period($date, $date); + $periods = $this->remove_breaks($date, $periods, $date_working_plan['breaks']); $periods = $this->remove_unavailability_events($periods, $unavailability_events); + $periods = $this->remove_unavailability_events($periods, $blocked_periods); $hours = []; diff --git a/application/models/Blocked_periods_model.php b/application/models/Blocked_periods_model.php index 92b8931e..b7cdc9a9 100644 --- a/application/models/Blocked_periods_model.php +++ b/application/models/Blocked_periods_model.php @@ -402,4 +402,21 @@ class Blocked_periods_model extends EA_Model { ->get() ->result_array(); } + + /** + * Check if a date is blocked by a blocked period. + * + * @param string $date + * + * @return bool + */ + public function is_entire_date_blocked(string $date): bool + { + return $this + ->query() + ->where('DATE(start_datetime) <=', $date) + ->where('DATE(end_datetime) >=', $date) + ->get() + ->num_rows() > 1; + } }