Corrected conditions when fetching events that start or end outside the displayed period of time for back-end calendar page.

This commit is contained in:
alext 2018-02-02 14:49:06 +01:00
parent 71b847135a
commit ea53955f71

View file

@ -199,12 +199,16 @@ class Backend_api extends CI_Controller {
}
// Get appointments
$where_clause = [
$where_id => $this->input->post('record_id'),
'DATE(start_datetime) >=' => $this->input->post('start_date'),
'DATE(start_datetime) <=' => date('Y-m-d', strtotime($this->input->post('end_date') . ' +1 day')),
'is_unavailable' => FALSE
];
$record_id = $this->db->escape($_POST['record_id']);
$start_date = $this->db->escape($_POST['start_date']);
$end_date = $this->db->escape(date('Y-m-d', strtotime($_POST['end_date'] . ' +1 day')));
$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND is_unavailable = 0
';
$response['appointments'] = $this->appointments_model->get_batch($where_clause);
@ -218,12 +222,12 @@ class Backend_api extends CI_Controller {
// Get unavailable periods (only for provider).
if ($this->input->post('filter_type') == FILTER_TYPE_PROVIDER)
{
$where_clause = [
$where_id => $this->input->post('record_id'),
'DATE(start_datetime) >=' => $this->input->post('start_date'),
'DATE(start_datetime) <=' => date('Y-m-d', strtotime($this->input->post('end_date') . ' +1 day')),
'is_unavailable' => TRUE
];
$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND is_unavailable = 1
';
$response['unavailables'] = $this->appointments_model->get_batch($where_clause);
}