The timezones model got converted into a library (as there is no direct database table to manage).

This commit is contained in:
Alex Tselegidis 2020-05-12 20:50:55 +02:00
parent 8795deef6b
commit df44f72964
24 changed files with 87 additions and 66 deletions

View file

@ -35,7 +35,7 @@ use EA\Engine\Types\Url;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model
@ -59,7 +59,7 @@ class Appointments extends CI_Controller {
$this->load->model('services_model'); $this->load->model('services_model');
$this->load->model('customers_model'); $this->load->model('customers_model');
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
if ($this->session->userdata('language')) if ($this->session->userdata('language'))
{ {
@ -106,7 +106,7 @@ class Appointments extends CI_Controller {
$display_privacy_policy = $this->settings_model->get_setting('display_privacy_policy'); $display_privacy_policy = $this->settings_model->get_setting('display_privacy_policy');
$privacy_policy_content = $this->settings_model->get_setting('privacy_policy_content'); $privacy_policy_content = $this->settings_model->get_setting('privacy_policy_content');
$display_any_provider = $this->settings_model->get_setting('display_any_provider'); $display_any_provider = $this->settings_model->get_setting('display_any_provider');
$timezones = $this->timezones_model->to_array(); $timezones = $this->timezones->to_array();
// Remove the data that are not needed inside the $available_providers array. // Remove the data that are not needed inside the $available_providers array.
foreach ($available_providers as $index => $provider) foreach ($available_providers as $index => $provider)

View file

@ -30,7 +30,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model
@ -88,7 +88,7 @@ class Backend extends CI_Controller {
$this->load->model('roles_model'); $this->load->model('roles_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('secretaries_model'); $this->load->model('secretaries_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$calendar_view_query_param = $this->input->get('view'); $calendar_view_query_param = $this->input->get('view');
@ -108,7 +108,7 @@ class Backend extends CI_Controller {
$view['available_services'] = $this->services_model->get_available_services(); $view['available_services'] = $this->services_model->get_available_services();
$view['customers'] = $this->customers_model->get_batch(); $view['customers'] = $this->customers_model->get_batch();
$view['calendar_view'] = !empty($calendar_view_query_param) ? $calendar_view_query_param : $user['settings']['calendar_view']; $view['calendar_view'] = !empty($calendar_view_query_param) ? $calendar_view_query_param : $user['settings']['calendar_view'];
$view['timezones'] = $this->timezones_model->to_array(); $view['timezones'] = $this->timezones->to_array();
$this->set_user_data($view); $this->set_user_data($view);
if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY) if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY)
@ -225,7 +225,7 @@ class Backend extends CI_Controller {
$this->load->model('services_model'); $this->load->model('services_model');
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$view['base_url'] = $this->config->item('base_url'); $view['base_url'] = $this->config->item('base_url');
$view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id')); $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
@ -238,7 +238,7 @@ class Backend extends CI_Controller {
$view['customers'] = $this->customers_model->get_batch(); $view['customers'] = $this->customers_model->get_batch();
$view['available_providers'] = $this->providers_model->get_available_providers(); $view['available_providers'] = $this->providers_model->get_available_providers();
$view['available_services'] = $this->services_model->get_available_services(); $view['available_services'] = $this->services_model->get_available_services();
$view['timezones'] = $this->timezones_model->to_array(); $view['timezones'] = $this->timezones->to_array();
if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY) if ($this->session->userdata('role_slug') === DB_SLUG_SECRETARY)
{ {
@ -278,7 +278,7 @@ class Backend extends CI_Controller {
$this->load->model('services_model'); $this->load->model('services_model');
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$view['base_url'] = $this->config->item('base_url'); $view['base_url'] = $this->config->item('base_url');
$view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id')); $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
@ -289,7 +289,7 @@ class Backend extends CI_Controller {
$view['first_weekday'] = $this->settings_model->get_setting('first_weekday'); $view['first_weekday'] = $this->settings_model->get_setting('first_weekday');
$view['services'] = $this->services_model->get_batch(); $view['services'] = $this->services_model->get_batch();
$view['categories'] = $this->services_model->get_all_categories(); $view['categories'] = $this->services_model->get_all_categories();
$view['timezones'] = $this->timezones_model->to_array(); $view['timezones'] = $this->timezones->to_array();
$this->set_user_data($view); $this->set_user_data($view);
$this->load->view('backend/header', $view); $this->load->view('backend/header', $view);
@ -318,7 +318,7 @@ class Backend extends CI_Controller {
$this->load->model('services_model'); $this->load->model('services_model');
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$view['base_url'] = $this->config->item('base_url'); $view['base_url'] = $this->config->item('base_url');
$view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id')); $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
@ -332,7 +332,7 @@ class Backend extends CI_Controller {
$view['secretaries'] = $this->secretaries_model->get_batch(); $view['secretaries'] = $this->secretaries_model->get_batch();
$view['services'] = $this->services_model->get_batch(); $view['services'] = $this->services_model->get_batch();
$view['working_plan'] = $this->settings_model->get_setting('company_working_plan'); $view['working_plan'] = $this->settings_model->get_setting('company_working_plan');
$view['timezones'] = $this->timezones_model->to_array(); $view['timezones'] = $this->timezones->to_array();
$view['extra_working_plan'] = '{}'; $view['extra_working_plan'] = '{}';
$this->set_user_data($view); $this->set_user_data($view);
@ -359,7 +359,7 @@ class Backend extends CI_Controller {
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$this->load->library('session'); $this->load->library('session');
$user_id = $this->session->userdata('user_id'); $user_id = $this->session->userdata('user_id');
@ -374,7 +374,7 @@ class Backend extends CI_Controller {
$view['role_slug'] = $this->session->userdata('role_slug'); $view['role_slug'] = $this->session->userdata('role_slug');
$view['system_settings'] = $this->settings_model->get_settings(); $view['system_settings'] = $this->settings_model->get_settings();
$view['user_settings'] = $this->user_model->get_user($user_id); $view['user_settings'] = $this->user_model->get_user($user_id);
$view['timezones'] = $this->timezones_model->to_array(); $view['timezones'] = $this->timezones->to_array();
$this->set_user_data($view); $this->set_user_data($view);
$this->load->view('backend/header', $view); $this->load->view('backend/header', $view);

View file

@ -37,7 +37,7 @@ use EA\Engine\Types\Url;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model
@ -280,7 +280,8 @@ class Backend_api extends CI_Controller {
$this->load->model('services_model'); $this->load->model('services_model');
$this->load->model('customers_model'); $this->load->model('customers_model');
$this->load->model('settings_model'); $this->load->model('settings_model');
$this->load->model('timezones_model'); $this->load->library('timezones');
$this->load->model('user_model');
// Save customer changes to the database. // Save customer changes to the database.
if ($this->input->post('customer_data')) if ($this->input->post('customer_data'))
@ -319,14 +320,14 @@ class Backend_api extends CI_Controller {
$appointment['id_users_customer'] = $customer['id']; $appointment['id_users_customer'] = $customer['id'];
} }
$provider_timezone = $this->timezones_model->get_user_timezone($appointment['id_users_provider']); $provider_timezone = $this->user_model->get_user_timezone($appointment['id_users_provider']);
$session_timezone = $this->timezones_model->get_session_timezone(); $session_timezone = $this->timezones->get_session_timezone();
$appointment['start_datetime'] = $this->timezones_model->convert($appointment['start_datetime'], $appointment['start_datetime'] = $this->timezones->convert($appointment['start_datetime'],
$session_timezone, $provider_timezone); $session_timezone, $provider_timezone);
$appointment['end_datetime'] = $this->timezones_model->convert($appointment['end_datetime'], $appointment['end_datetime'] = $this->timezones->convert($appointment['end_datetime'],
$session_timezone, $provider_timezone); $session_timezone, $provider_timezone);
$appointment['id'] = $this->appointments_model->add($appointment); $appointment['id'] = $this->appointments_model->add($appointment);

View file

@ -30,7 +30,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -33,7 +33,7 @@
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Consents_Model consents_model * @property Consents_Model consents_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -30,7 +30,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -32,7 +32,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -33,7 +33,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -30,7 +30,7 @@
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -34,7 +34,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -35,7 +35,7 @@ use EA\Engine\Types\UnsignedInteger;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -35,7 +35,7 @@ use EA\Engine\Api\V1\Response;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
* @property Services_Model services_model * @property Services_Model services_model
* @property Customers_Model customers_model * @property Customers_Model customers_model
* @property Settings_Model settings_model * @property Settings_Model settings_model
* @property Timezones_Model timezones_model * @property Timezones timezones
* @property Roles_Model roles_model * @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model * @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model * @property Admins_Model admins_model

View file

@ -21,9 +21,9 @@ function render_timezone_dropdown($attributes = '')
{ {
$framework = get_instance(); $framework = get_instance();
$framework->load->model('timezones_model'); $framework->load->library('timezones');
$timezones = $framework->timezones_model->to_grouped_array(); $timezones = $framework->timezones->to_grouped_array();
ob_start(); ob_start();

View file

@ -12,14 +12,18 @@
* ---------------------------------------------------------------------------- */ * ---------------------------------------------------------------------------- */
/** /**
* Timezones Model * Timezones
* *
* @property CI_DB_query_builder db
* @property CI_Loader load * @property CI_Loader load
* *
* @package Models * @package Models
*/ */
class Timezones_Model extends CI_Model { class Timezones {
/**
* @var CI_Controller
*/
protected $framework;
/** /**
* @var string * @var string
*/ */
@ -460,6 +464,15 @@ class Timezones_Model extends CI_Model {
], ],
]; ];
public function __construct()
{
$this->framework = & get_instance();
$this->framework->load->model('user_model');
$this->framework->load->library('session');
}
/** /**
* Get all timezones to a grouped array (by continent). * Get all timezones to a grouped array (by continent).
* *
@ -474,7 +487,9 @@ class Timezones_Model extends CI_Model {
* Convert the dates of an event to the timezone of the user. * 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. * @param array $event Must contain the "start_datetime", "end_datetime" and "id_users_provider" properties.
*
* @return array * @return array
*
* @throws Exception * @throws Exception
*/ */
public function convert_event_timezone($event) public function convert_event_timezone($event)
@ -484,7 +499,7 @@ class Timezones_Model extends CI_Model {
throw new Exception('The provided event does not have the required properties: ' . print_r($event)); throw new Exception('The provided event does not have the required properties: ' . print_r($event));
} }
$user_timezone = $this->get_user_timezone($event['id_users_provider']); $user_timezone = $this->framework->user_model->get_user_timezone($event['id_users_provider']);
$session_timezone = $this->get_session_timezone(); $session_timezone = $this->get_session_timezone();
@ -497,18 +512,6 @@ class Timezones_Model extends CI_Model {
return $event; return $event;
} }
/**
* Get the timezone of a user.
*
* @param int $id Database ID of the user.
* @return string|null
*/
public function get_user_timezone($id)
{
$row = $this->db->get_where('users', ['id' => $id])->row_array();
return $row ? $row['timezone'] : NULL;
}
/** /**
* Returns the session timezone or the default timezone as a fallback. * Returns the session timezone or the default timezone as a fallback.
@ -517,11 +520,11 @@ class Timezones_Model extends CI_Model {
*/ */
public function get_session_timezone() public function get_session_timezone()
{ {
$this->load->library('session');
$default_timezone = $this->get_default_timezone(); $default_timezone = $this->get_default_timezone();
return isset($this->session->timezone) ? $this->session->timezone : $default_timezone; return $this->framework->session->has_userdata('timezone')
? $this->framework->session->userdata('timezone')
: $default_timezone;
} }
/** /**
@ -540,7 +543,9 @@ class Timezones_Model extends CI_Model {
* @param string $value Provide a date time value as a string (format Y-m-d H:i:s). * @param string $value Provide a date time value as a string (format Y-m-d H:i:s).
* @param string $from_timezone From timezone value. * @param string $from_timezone From timezone value.
* @param string $to_timezone To timezone value. * @param string $to_timezone To timezone value.
*
* @return string * @return string
*
* @throws Exception * @throws Exception
*/ */
public function convert($value, $from_timezone, $to_timezone) public function convert($value, $from_timezone, $to_timezone)
@ -565,6 +570,7 @@ class Timezones_Model extends CI_Model {
* Get the timezone name for the provided value. * Get the timezone name for the provided value.
* *
* @param string $value * @param string $value
*
* @return string|null * @return string|null
*/ */
public function get_timezone_name($value) public function get_timezone_name($value)

View file

@ -302,9 +302,9 @@ class Appointments_Model extends CI_Model {
$appointment = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array(); $appointment = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array();
$this->load->model('timezones_model'); $this->load->library('timezones');
$appointment = $this->timezones_model->convert_event_timezone($appointment); $appointment = $this->timezones->convert_event_timezone($appointment);
return $appointment; return $appointment;
} }
@ -348,9 +348,9 @@ class Appointments_Model extends CI_Model {
throw new Exception('The given field name does not exist in the database: ' . $field_name); throw new Exception('The given field name does not exist in the database: ' . $field_name);
} }
$this->load->model('timezones_model'); $this->load->library('timezones');
$row_data = $this->timezones_model->convert_event_timezone($row_data); $row_data = $this->timezones->convert_event_timezone($row_data);
return $row_data[$field_name]; return $row_data[$field_name];
} }
@ -385,11 +385,11 @@ class Appointments_Model extends CI_Model {
$appointments = $this->db->get('appointments', $limit, $offset)->result_array(); $appointments = $this->db->get('appointments', $limit, $offset)->result_array();
$this->load->model('timezones_model'); $this->load->library('timezones');
foreach ($appointments as &$appointment) foreach ($appointments as &$appointment)
{ {
$appointment = $this->timezones_model->convert_event_timezone($appointment); $appointment = $this->timezones->convert_event_timezone($appointment);
if ($aggregates) if ($aggregates)
{ {

View file

@ -109,9 +109,9 @@ class User_Model extends CI_Model {
return NULL; return NULL;
} }
$this->load->model('timezones_model'); $this->load->library('timezones');
$default_timezone = $this->timezones_model->get_default_timezone(); $default_timezone = $this->timezones->get_default_timezone();
return [ return [
'user_id' => $user['id'], 'user_id' => $user['id'],
@ -192,4 +192,18 @@ class User_Model extends CI_Model {
return $new_password; return $new_password;
} }
/**
* Get the timezone of a user.
*
* @param int $id Database ID of the user.
*
* @return string|null
*/
public function get_user_timezone($id)
{
$row = $this->db->get_where('users', ['id' => $id])->row_array();
return $row ? $row['timezone'] : NULL;
}
} }