From ea53955f712fa8ef61c23c7b48f39f00faa6e9ee Mon Sep 17 00:00:00 2001 From: alext Date: Fri, 2 Feb 2018 14:49:06 +0100 Subject: [PATCH] Corrected conditions when fetching events that start or end outside the displayed period of time for back-end calendar page. --- src/application/controllers/Backend_api.php | 28 ++++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/application/controllers/Backend_api.php b/src/application/controllers/Backend_api.php index fb5abeff..2f5ae866 100644 --- a/src/application/controllers/Backend_api.php +++ b/src/application/controllers/Backend_api.php @@ -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); }