From 849f83ed03430ba8637a840889e03147f050e517 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sun, 29 Mar 2020 15:08:07 +0200 Subject: [PATCH] Backend calendar handling with timezones. --- application/controllers/Backend_api.php | 19 ++++-- application/models/Timezones_model.php | 3 + application/views/backend/calendar.php | 61 ++++++++++++++++++- .../views/partial/timezone_dropdown.php | 1 - .../js/backend_calendar_appointments_modal.js | 24 ++++++-- assets/js/backend_calendar_default_view.js | 10 +++ 6 files changed, 107 insertions(+), 11 deletions(-) diff --git a/application/controllers/Backend_api.php b/application/controllers/Backend_api.php index f012f616..c755bbed 100755 --- a/application/controllers/Backend_api.php +++ b/application/controllers/Backend_api.php @@ -11,9 +11,9 @@ * @since v1.0.0 * ---------------------------------------------------------------------------- */ -use \EA\Engine\Types\Text; -use \EA\Engine\Types\Email; -use \EA\Engine\Types\Url; +use EA\Engine\Types\Email; +use EA\Engine\Types\Text; +use EA\Engine\Types\Url; /** * Backend API Controller @@ -102,7 +102,7 @@ class Backend_api extends CI_Controller { $userId = $this->session->userdata('user_id'); $roleSlug = $this->session->userdata('role_slug'); - // If the current user is a provider he must only see his own appointments. + // If the current user is a provider he must only see his own appointments. if ($roleSlug === DB_SLUG_PROVIDER) { foreach ($response['appointments'] as $index => $appointment) @@ -261,6 +261,7 @@ class Backend_api extends CI_Controller { $this->load->model('services_model'); $this->load->model('customers_model'); $this->load->model('settings_model'); + $this->load->model('timezones_model'); // :: SAVE CUSTOMER CHANGES TO DATABASE if ($this->input->post('customer_data')) @@ -299,6 +300,16 @@ class Backend_api extends CI_Controller { $appointment['id_users_customer'] = $customer['id']; } + $provider_timezone = $this->timezones_model->get_user_timezone($appointment['id_users_provider']); + + $session_timezone = $this->timezones_model->get_session_timezone(); + + $appointment['start_datetime'] = $this->timezones_model->convert($appointment['start_datetime'], + $session_timezone, $provider_timezone); + + $appointment['end_datetime'] = $this->timezones_model->convert($appointment['end_datetime'], + $session_timezone, $provider_timezone); + $appointment['id'] = $this->appointments_model->add($appointment); } diff --git a/application/models/Timezones_model.php b/application/models/Timezones_model.php index d19833a9..bb40494b 100644 --- a/application/models/Timezones_model.php +++ b/application/models/Timezones_model.php @@ -26,6 +26,9 @@ class Timezones_Model extends CI_Model { * @var array */ protected $timezones = [ + 'UTC' => [ + 'UTC' => 'UTC' + ], 'America' => [ 'America/Adak' => 'Adak -10:00', 'America/Atka' => 'Atka -10:00', diff --git a/application/views/backend/calendar.php b/application/views/backend/calendar.php index 04a81b87..7a8bbb0b 100755 --- a/application/views/backend/calendar.php +++ b/application/views/backend/calendar.php @@ -187,6 +187,11 @@ + +
+ + +
@@ -201,8 +206,22 @@
- - + + +
@@ -316,6 +335,25 @@ +
+ + + +
+
@@ -361,6 +399,25 @@
+ +
+ + + +
diff --git a/application/views/partial/timezone_dropdown.php b/application/views/partial/timezone_dropdown.php index fc53d7f3..77a34ec2 100644 --- a/application/views/partial/timezone_dropdown.php +++ b/application/views/partial/timezone_dropdown.php @@ -1,5 +1,4 @@