From 26442a1e171dc6101dad38c6b44a1f70ef04df35 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sun, 29 Mar 2020 14:17:56 +0200 Subject: [PATCH] Events get rendered based on the current user timezone. --- application/models/Appointments_model.php | 20 +++++++++++++++++--- application/models/Timezones_model.php | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index 93d61c41..9024ba85 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -282,7 +282,13 @@ class Appointments_Model extends CI_Model { . $appointment_id); } - return $this->db->get_where('ea_appointments', ['id' => $appointment_id])->row_array(); + $appointment = $this->db->get_where('ea_appointments', ['id' => $appointment_id])->row_array(); + + $this->load->model('timezones_model'); + + $appointment = $this->timezones_model->convert_event_timezone($appointment); + + return $appointment; } /** @@ -324,6 +330,10 @@ class Appointments_Model extends CI_Model { throw new Exception('The given field name does not exist in the database: ' . $field_name); } + $this->load->model('timezones_model'); + + $row_data = $this->timezones_model->convert_event_timezone($row_data); + return $row_data[$field_name]; } @@ -348,9 +358,13 @@ class Appointments_Model extends CI_Model { $appointments = $this->db->get('ea_appointments')->result_array(); - if ($aggregates) + $this->load->model('timezones_model'); + + foreach ($appointments as &$appointment) { - foreach ($appointments as &$appointment) + $appointment = $this->timezones_model->convert_event_timezone($appointment); + + if ($aggregates) { $appointment = $this->get_aggregates($appointment); } diff --git a/application/models/Timezones_model.php b/application/models/Timezones_model.php index b19b8906..4a9f2091 100644 --- a/application/models/Timezones_model.php +++ b/application/models/Timezones_model.php @@ -515,7 +515,7 @@ class Timezones_Model extends CI_Model { * @return array * @throws Exception */ - public function convert_event_datetime($event) + public function convert_event_timezone($event) { if ( ! isset($event['start_datetime'], $event['end_datetime'], $event['id_users_provider'])) {