From 9c82805b83dbc1db77ea7031a2927bbf2f6b0415 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sun, 17 Jul 2016 12:49:27 +0200 Subject: [PATCH] Added 'calendar_view' setting in models (#182). --- src/application/models/Admins_model.php | 21 +++++++---- src/application/models/Providers_model.php | 37 ++++++++++++-------- src/application/models/Secretaries_model.php | 19 ++++++---- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/application/models/Admins_model.php b/src/application/models/Admins_model.php index 7630e46e..f002a32e 100644 --- a/src/application/models/Admins_model.php +++ b/src/application/models/Admins_model.php @@ -12,7 +12,7 @@ * ---------------------------------------------------------------------------- */ /** - * Admins_Model Class + * Admins Model Class * * Handles the database actions for admin users management. * @@ -208,12 +208,12 @@ class Admins_Model extends CI_Model { if (!isset($admin['last_name']) || !isset($admin['email']) || !isset($admin['phone_number'])) { - throw new Exception('Not all required fields are provided : ' . print_r($admin, TRUE)); + throw new Exception('Not all required fields are provided: ' . print_r($admin, TRUE)); } // Validate admin email address. if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) { - throw new Exception('Invalid email address provided : ' . $admin['email']); + throw new Exception('Invalid email address provided: ' . $admin['email']); } // Check if username exists. @@ -232,6 +232,13 @@ class Admins_Model extends CI_Model { . MIN_PASSWORD_LENGTH . ' characters long.'); } } + + // Validate calendar view mode. + if (isset($admin['settings']['calendar_view']) && ($admin['settings']['calendar_view'] !== CALENDAR_VIEW_DEFAULT + || $admin['settings']['calendar_view'] !== CALENDAR_VIEW_TABLE)) { + throw new Exception('The calendar view setting must be either "' . CALENDAR_VIEW_DEFAULT + . '" or "' . CALENDAR_VIEW_TABLE . '", given: ' . $admin['settings']['calendar_view']); + } // When inserting a record the email address must be unique. $admin_id = (isset($admin['id'])) ? $admin['id'] : ''; @@ -265,7 +272,7 @@ class Admins_Model extends CI_Model { */ public function delete($admin_id) { if (!is_numeric($admin_id)) { - throw new Exception('Invalid argument type $admin_id : ' . $admin_id); + throw new Exception('Invalid argument type $admin_id: ' . $admin_id); } // There must be always at least one admin user. If this is the only admin @@ -325,7 +332,7 @@ class Admins_Model extends CI_Model { */ public function get_value($field_name, $admin_id) { if (!is_string($field_name)) { - throw new Exception('$field_name argument is not a string : ' . $field_name); + throw new Exception('$field_name argument is not a string: ' . $field_name); } if (!is_numeric($admin_id)) { @@ -336,7 +343,7 @@ class Admins_Model extends CI_Model { $result = $this->db->get_where('ea_users', array('id' => $admin_id)); if ($result->num_rows() == 0) { throw new Exception('The record with the given id does not exist in the ' - . 'database : ' . $admin_id); + . 'database: ' . $admin_id); } // Check if the required field name exist in database. @@ -399,4 +406,4 @@ class Admins_Model extends CI_Model { } /* End of file admins_model.php */ -/* Location: ./application/models/admins_model.php */ \ No newline at end of file +/* Location: ./application/models/admins_model.php */ diff --git a/src/application/models/Providers_model.php b/src/application/models/Providers_model.php index 0341b3bc..455089e1 100644 --- a/src/application/models/Providers_model.php +++ b/src/application/models/Providers_model.php @@ -39,7 +39,8 @@ * 'google_token' * 'google_calendar' * 'sync_past_days' - * 'sync_future_days' + * 'sync_future_days', + * 'calendar_view' * * @package Models */ @@ -87,7 +88,7 @@ class Providers_Model extends CI_Model { */ public function exists($provider) { if (!isset($provider['email'])) { - throw new Exception('Provider email is not provided :' . print_r($provider, TRUE)); + throw new Exception('Provider email is not provided:' . print_r($provider, TRUE)); } // This method shouldn't depend on another method of this class. @@ -181,7 +182,7 @@ class Providers_Model extends CI_Model { */ public function find_record_id($provider) { if (!isset($provider['email'])) { - throw new Exception('Provider email was not provided :' . print_r($provider, TRUE)); + throw new Exception('Provider email was not provided:' . print_r($provider, TRUE)); } $result = $this->db @@ -221,12 +222,12 @@ class Providers_Model extends CI_Model { if (!isset($provider['last_name']) || !isset($provider['email']) || !isset($provider['phone_number'])) { - throw new Exception('Not all required fields are provided : ' . print_r($provider, TRUE)); + throw new Exception('Not all required fields are provided: ' . print_r($provider, TRUE)); } // Validate provider email address. if (!filter_var($provider['email'], FILTER_VALIDATE_EMAIL)) { - throw new Exception('Invalid email address provided : ' . $provider['email']); + throw new Exception('Invalid email address provided: ' . $provider['email']); } // Validate provider services. @@ -264,6 +265,13 @@ class Providers_Model extends CI_Model { } } + // Validate calendar view mode. + if (isset($provider['settings']['calendar_view']) && ($provider['settings']['calendar_view'] !== CALENDAR_VIEW_DEFAULT + || $provider['settings']['calendar_view'] !== CALENDAR_VIEW_TABLE)) { + throw new Exception('The calendar view setting must be either "' . CALENDAR_VIEW_DEFAULT + . '" or "' . CALENDAR_VIEW_TABLE . '", given: ' . $provider['settings']['calendar_view']); + } + // When inserting a record the email address must be unique. $provider_id = (isset($provider['id'])) ? $provider['id'] : ''; @@ -294,7 +302,7 @@ class Providers_Model extends CI_Model { */ public function delete($provider_id) { if (!is_numeric($provider_id)) { - throw new Exception('Invalid argument type $provider_id : ' . $provider_id); + throw new Exception('Invalid argument type $provider_id: ' . $provider_id); } $num_rows = $this->db->get_where('ea_users', array('id' => $provider_id))->num_rows(); @@ -350,31 +358,32 @@ class Providers_Model extends CI_Model { * @param string $field_name The field name of the value to be returned. * @param numeric $provider_id Record id of the value to be returned. * @return string Returns the selected record value from the database. + * * @throws Exception When the $field_name argument is not a valid string. - * @throws Exception When the $admin_id is not a valid numeric. - * @throws Exception When the admin record does not exist in the database. + * @throws Exception When the $provider_id is not a valid numeric. + * @throws Exception When the provider record does not exist in the database. * @throws Exception When the selected field value is not present on database. */ public function get_value($field_name, $provider_id) { if (!is_numeric($provider_id)) { - throw new Exception('Invalid argument provided as $provider_id : ' . $provider_id); + throw new Exception('Invalid argument provided as $provider_id: ' . $provider_id); } if (!is_string($field_name)) { - throw new Exception('$field_name argument is not a string : ' . $field_name); + throw new Exception('$field_name argument is not a string: ' . $field_name); } - // Check whether the admin record exists in database. + // Check whether the provider record exists in database. $result = $this->db->get_where('ea_users', array('id' => $provider_id)); if ($result->num_rows() == 0) { throw new Exception('The record with the $provider_id argument does not exist in ' - . 'the database : ' . $provider_id); + . 'the database: ' . $provider_id); } $provider = $result->row_array(); if (!isset($provider[$field_name])) { throw new Exception('The given $field_name argument does not exist in the ' - . 'database : ' . $field_name); + . 'database: ' . $field_name); } return $provider[$field_name]; @@ -509,7 +518,7 @@ class Providers_Model extends CI_Model { */ protected function save_settings($settings, $provider_id) { if (!is_numeric($provider_id)) { - throw new Exception('Invalid $provider_id argument given :' . $provider_id); + throw new Exception('Invalid $provider_id argument given:' . $provider_id); } if (count($settings) == 0 || !is_array($settings)) { diff --git a/src/application/models/Secretaries_model.php b/src/application/models/Secretaries_model.php index 1c15fbeb..f08a123f 100644 --- a/src/application/models/Secretaries_model.php +++ b/src/application/models/Secretaries_model.php @@ -206,12 +206,12 @@ class Secretaries_Model extends CI_Model { if (!isset($secretary['last_name']) || !isset($secretary['email']) || !isset($secretary['phone_number'])) { - throw new Exception('Not all required fields are provided : ' . print_r($secretary, TRUE)); + throw new Exception('Not all required fields are provided: ' . print_r($secretary, TRUE)); } // Validate secretary email address. if (!filter_var($secretary['email'], FILTER_VALIDATE_EMAIL)) { - throw new Exception('Invalid email address provided : ' . $secretary['email']); + throw new Exception('Invalid email address provided: ' . $secretary['email']); } // Check if username exists. @@ -231,6 +231,13 @@ class Secretaries_Model extends CI_Model { } } + // Validate calendar view mode. + if (isset($secretary['settings']['calendar_view']) && ($secretary['settings']['calendar_view'] !== CALENDAR_VIEW_DEFAULT + || $secretary['settings']['calendar_view'] !== CALENDAR_VIEW_TABLE)) { + throw new Exception('The calendar view setting must be either "' . CALENDAR_VIEW_DEFAULT + . '" or "' . CALENDAR_VIEW_TABLE . '", given: ' . $secretary['settings']['calendar_view']); + } + // When inserting a record the email address must be unique. $secretary_id = (isset($secretary['id'])) ? $secretary['id'] : ''; @@ -261,7 +268,7 @@ class Secretaries_Model extends CI_Model { */ public function delete($secretary_id) { if (!is_numeric($secretary_id)) { - throw new Exception('Invalid argument type $secretary_id : ' . $secretary_id); + throw new Exception('Invalid argument type $secretary_id: ' . $secretary_id); } $num_rows = $this->db->get_where('ea_users', array('id' => $secretary_id))->num_rows(); @@ -319,7 +326,7 @@ class Secretaries_Model extends CI_Model { */ public function get_value($field_name, $secretary_id) { if (!is_string($field_name)) { - throw new Exception('$field_name argument is not a string : ' . $field_name); + throw new Exception('$field_name argument is not a string: ' . $field_name); } if (!is_numeric($secretary_id)) { @@ -330,7 +337,7 @@ class Secretaries_Model extends CI_Model { $result = $this->db->get_where('ea_users', array('id' => $secretary_id)); if ($result->num_rows() == 0) { throw new Exception('The record with the given id does not exist in the ' - . 'database : ' . $secretary_id); + . 'database: ' . $secretary_id); } // Check if the required field name exist in database. @@ -418,7 +425,7 @@ class Secretaries_Model extends CI_Model { */ protected function save_settings($settings, $secretary_id) { if (!is_numeric($secretary_id)) { - throw new Exception('Invalid $provider_id argument given :' . $secretary_id); + throw new Exception('Invalid $provider_id argument given:' . $secretary_id); } if (count($settings) == 0 || !is_array($settings)) {