mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 09:23:08 +03:00
The timezones model got converted into a library (as there is no direct database table to manage).
This commit is contained in:
parent
8795deef6b
commit
df44f72964
24 changed files with 87 additions and 66 deletions
|
@ -35,7 +35,7 @@ use EA\Engine\Types\Url;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
@ -59,7 +59,7 @@ class Appointments extends CI_Controller {
|
|||
$this->load->model('services_model');
|
||||
$this->load->model('customers_model');
|
||||
$this->load->model('settings_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
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');
|
||||
$privacy_policy_content = $this->settings_model->get_setting('privacy_policy_content');
|
||||
$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.
|
||||
foreach ($available_providers as $index => $provider)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
@ -88,7 +88,7 @@ class Backend extends CI_Controller {
|
|||
$this->load->model('roles_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('secretaries_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
$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['customers'] = $this->customers_model->get_batch();
|
||||
$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);
|
||||
|
||||
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('settings_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$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['available_providers'] = $this->providers_model->get_available_providers();
|
||||
$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)
|
||||
{
|
||||
|
@ -278,7 +278,7 @@ class Backend extends CI_Controller {
|
|||
$this->load->model('services_model');
|
||||
$this->load->model('settings_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$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['services'] = $this->services_model->get_batch();
|
||||
$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->load->view('backend/header', $view);
|
||||
|
@ -318,7 +318,7 @@ class Backend extends CI_Controller {
|
|||
$this->load->model('services_model');
|
||||
$this->load->model('settings_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$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['services'] = $this->services_model->get_batch();
|
||||
$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'] = '{}';
|
||||
$this->set_user_data($view);
|
||||
|
||||
|
@ -359,7 +359,7 @@ class Backend extends CI_Controller {
|
|||
|
||||
$this->load->model('settings_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
$this->load->library('session');
|
||||
$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['system_settings'] = $this->settings_model->get_settings();
|
||||
$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->load->view('backend/header', $view);
|
||||
|
|
|
@ -37,7 +37,7 @@ use EA\Engine\Types\Url;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
@ -280,7 +280,8 @@ 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');
|
||||
$this->load->library('timezones');
|
||||
$this->load->model('user_model');
|
||||
|
||||
// Save customer changes to the database.
|
||||
if ($this->input->post('customer_data'))
|
||||
|
@ -319,14 +320,14 @@ class Backend_api extends CI_Controller {
|
|||
$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);
|
||||
|
||||
$appointment['end_datetime'] = $this->timezones_model->convert($appointment['end_datetime'],
|
||||
$appointment['end_datetime'] = $this->timezones->convert($appointment['end_datetime'],
|
||||
$session_timezone, $provider_timezone);
|
||||
|
||||
$appointment['id'] = $this->appointments_model->add($appointment);
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
* @property Customers_Model customers_model
|
||||
* @property Consents_Model consents_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -34,7 +34,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -35,7 +35,7 @@ use EA\Engine\Types\UnsignedInteger;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -35,7 +35,7 @@ use EA\Engine\Api\V1\Response;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -36,7 +36,7 @@ use EA\Engine\Types\NonEmptyText;
|
|||
* @property Services_Model services_model
|
||||
* @property Customers_Model customers_model
|
||||
* @property Settings_Model settings_model
|
||||
* @property Timezones_Model timezones_model
|
||||
* @property Timezones timezones
|
||||
* @property Roles_Model roles_model
|
||||
* @property Secretaries_Model secretaries_model
|
||||
* @property Admins_Model admins_model
|
||||
|
|
|
@ -21,9 +21,9 @@ function render_timezone_dropdown($attributes = '')
|
|||
{
|
||||
$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();
|
||||
|
||||
|
|
|
@ -12,14 +12,18 @@
|
|||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Timezones Model
|
||||
* Timezones
|
||||
*
|
||||
* @property CI_DB_query_builder db
|
||||
* @property CI_Loader load
|
||||
*
|
||||
* @package Models
|
||||
*/
|
||||
class Timezones_Model extends CI_Model {
|
||||
class Timezones {
|
||||
/**
|
||||
* @var CI_Controller
|
||||
*/
|
||||
protected $framework;
|
||||
|
||||
/**
|
||||
* @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).
|
||||
*
|
||||
|
@ -474,7 +487,9 @@ class Timezones_Model extends CI_Model {
|
|||
* 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)
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
|
@ -497,18 +512,6 @@ class Timezones_Model extends CI_Model {
|
|||
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.
|
||||
|
@ -517,11 +520,11 @@ class Timezones_Model extends CI_Model {
|
|||
*/
|
||||
public function get_session_timezone()
|
||||
{
|
||||
$this->load->library('session');
|
||||
|
||||
$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 $from_timezone From timezone value.
|
||||
* @param string $to_timezone To timezone value.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_timezone_name($value)
|
|
@ -302,9 +302,9 @@ class Appointments_Model extends CI_Model {
|
|||
|
||||
$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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
$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];
|
||||
}
|
||||
|
@ -385,11 +385,11 @@ class Appointments_Model extends CI_Model {
|
|||
|
||||
$appointments = $this->db->get('appointments', $limit, $offset)->result_array();
|
||||
|
||||
$this->load->model('timezones_model');
|
||||
$this->load->library('timezones');
|
||||
|
||||
foreach ($appointments as &$appointment)
|
||||
{
|
||||
$appointment = $this->timezones_model->convert_event_timezone($appointment);
|
||||
$appointment = $this->timezones->convert_event_timezone($appointment);
|
||||
|
||||
if ($aggregates)
|
||||
{
|
||||
|
|
|
@ -109,9 +109,9 @@ class User_Model extends CI_Model {
|
|||
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 [
|
||||
'user_id' => $user['id'],
|
||||
|
@ -192,4 +192,18 @@ class User_Model extends CI_Model {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue