Skip to content

Commit

Permalink
Apply the blocked periods to the booking page availability (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Nov 17, 2023
1 parent f06dc3a commit f040404
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions application/libraries/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct()
$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');
}
Expand All @@ -57,6 +58,11 @@ public function __construct()
*/
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);
Expand Down Expand Up @@ -117,6 +123,7 @@ protected function get_available_periods(string $date, array $provider, int $exc
array_merge(
$this->CI->appointments_model->get($where),
$this->CI->unavailabilities_model->get($where),
$this->CI->blocked_periods_model->get_for_period($date, $date)
)
);

Expand Down Expand Up @@ -396,8 +403,11 @@ protected function consider_multiple_attendants(
]
];

$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 = [];

Expand Down
17 changes: 17 additions & 0 deletions application/models/Blocked_periods_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,21 @@ public function get_for_period(string $start_date, string $end_date): array
->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;
}
}

0 comments on commit f040404

Please sign in to comment.