From cf7bad9f19a303b96ba31011d79515fba13bb2cf Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 14 Dec 2020 20:41:21 +0200 Subject: [PATCH] Always display events in the provider's timezone in the backend calendar pages --- application/controllers/Backend_api.php | 36 +++++++---------------- application/libraries/Timezones.php | 34 --------------------- application/models/Appointments_model.php | 11 +------ 3 files changed, 11 insertions(+), 70 deletions(-) diff --git a/application/controllers/Backend_api.php b/application/controllers/Backend_api.php index 6e9c9cfe..bef6e303 100755 --- a/application/controllers/Backend_api.php +++ b/application/controllers/Backend_api.php @@ -82,11 +82,11 @@ class Backend_api extends EA_Controller { ]) ]; - foreach ($response['appointments'] as $index => $appointment) + foreach ($response['appointments'] as &$appointment) { - $response['appointments'][$index]['provider'] = $this->providers_model->get_row($appointment['id_users_provider']); - $response['appointments'][$index]['service'] = $this->services_model->get_row($appointment['id_services']); - $response['appointments'][$index]['customer'] = $this->customers_model->get_row($appointment['id_users_customer']); + $appointment['provider'] = $this->providers_model->get_row($appointment['id_users_provider']); + $appointment['service'] = $this->services_model->get_row($appointment['id_services']); + $appointment['customer'] = $this->customers_model->get_row($appointment['id_users_customer']); } $user_id = $this->session->userdata('user_id'); @@ -218,6 +218,11 @@ class Backend_api extends EA_Controller { $response['unavailables'] = $this->appointments_model->get_batch($where_clause); } + foreach ($response['unavailables'] as &$unavailable) + { + $unavailable['provider'] = $this->providers_model->get_row($unavailable['id_users_provider']); + } + $this->output ->set_content_type('application/json') ->set_output(json_encode($response)); @@ -282,16 +287,6 @@ class Backend_api extends EA_Controller { $appointment['id_users_customer'] = $customer['id']; } - $provider_timezone = $this->user_model->get_user_timezone($appointment['id_users_provider']); - - $session_timezone = $this->timezones->get_session_timezone(); - - $appointment['start_datetime'] = $this->timezones->convert($appointment['start_datetime'], - $session_timezone, $provider_timezone); - - $appointment['end_datetime'] = $this->timezones->convert($appointment['end_datetime'], - $session_timezone, $provider_timezone); - $appointment['id'] = $this->appointments_model->add($appointment); } @@ -565,8 +560,7 @@ class Backend_api extends EA_Controller { foreach ($customers as &$customer) { - $appointments = $this->appointments_model - ->get_batch(['id_users_customer' => $customer['id']]); + $appointments = $this->appointments_model->get_batch(['id_users_customer' => $customer['id']]); foreach ($appointments as &$appointment) { @@ -615,16 +609,6 @@ class Backend_api extends EA_Controller { $provider = $this->providers_model->get_row($unavailable['id_users_provider']); // Add appointment - $provider_timezone = $this->user_model->get_user_timezone($unavailable['id_users_provider']); - - $session_timezone = $this->timezones->get_session_timezone(); - - $unavailable['start_datetime'] = $this->timezones->convert($unavailable['start_datetime'], - $session_timezone, $provider_timezone); - - $unavailable['end_datetime'] = $this->timezones->convert($unavailable['end_datetime'], - $session_timezone, $provider_timezone); - $unavailable['id'] = $this->appointments_model->add_unavailable($unavailable); $unavailable = $this->appointments_model->get_row($unavailable['id']); // fetch all inserted data diff --git a/application/libraries/Timezones.php b/application/libraries/Timezones.php index 1c2af09c..357bca0b 100644 --- a/application/libraries/Timezones.php +++ b/application/libraries/Timezones.php @@ -13,10 +13,6 @@ /** * Timezones - * - * @property CI_Loader $load - * - * @package Models */ class Timezones { /** @@ -484,36 +480,6 @@ class Timezones { return $this->timezones; } - /** - * Convert the dates of an event to the timezone of the user. - * - * @param array $event Must contain the "start_datetime", "end_datetime" and "id_users_provider" properties. - * - * @return array - * - * @throws Exception - */ - public function convert_event_timezone($event) - { - if ( ! isset($event['start_datetime'], $event['end_datetime'], $event['id_users_provider'])) - { - throw new Exception('The provided event does not have the required properties: ' . print_r($event)); - } - - $user_timezone = $this->CI->user_model->get_user_timezone($event['id_users_provider']); - - $session_timezone = $this->get_session_timezone(); - - $event['start_datetime'] = $this->convert($event['start_datetime'], - $user_timezone, $session_timezone); - - $event['end_datetime'] = $this->convert($event['end_datetime'], - $user_timezone, $session_timezone); - - return $event; - } - - /** * Returns the session timezone or the default timezone as a fallback. * diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index 25973d56..9866d350 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -24,7 +24,6 @@ class Appointments_model extends EA_Model { { parent::__construct(); $this->load->helper('data_validation'); - $this->load->library('timezones'); } /** @@ -317,11 +316,7 @@ class Appointments_model extends EA_Model { . $appointment_id); } - $appointment = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array(); - - $appointment = $this->timezones->convert_event_timezone($appointment); - - return $appointment; + return $this->db->get_where('appointments', ['id' => $appointment_id])->row_array(); } /** @@ -363,8 +358,6 @@ class Appointments_model extends EA_Model { throw new Exception('The given field name does not exist in the database: ' . $field_name); } - $row_data = $this->timezones->convert_event_timezone($row_data); - return $row_data[$field_name]; } @@ -401,8 +394,6 @@ class Appointments_model extends EA_Model { foreach ($appointments as &$appointment) { - $appointment = $this->timezones->convert_event_timezone($appointment); - if ($aggregates) { $appointment = $this->get_aggregates($appointment);