Added 'calendar_view' setting in models (#182).

This commit is contained in:
Alex Tselegidis 2016-07-17 12:49:27 +02:00
parent f083aa7e49
commit 9c82805b83
3 changed files with 50 additions and 27 deletions

View file

@ -12,7 +12,7 @@
* ---------------------------------------------------------------------------- */ * ---------------------------------------------------------------------------- */
/** /**
* Admins_Model Class * Admins Model Class
* *
* Handles the database actions for admin users management. * Handles the database actions for admin users management.
* *
@ -208,12 +208,12 @@ class Admins_Model extends CI_Model {
if (!isset($admin['last_name']) if (!isset($admin['last_name'])
|| !isset($admin['email']) || !isset($admin['email'])
|| !isset($admin['phone_number'])) { || !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. // Validate admin email address.
if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) { 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. // Check if username exists.
@ -233,6 +233,13 @@ class Admins_Model extends CI_Model {
} }
} }
// 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. // When inserting a record the email address must be unique.
$admin_id = (isset($admin['id'])) ? $admin['id'] : ''; $admin_id = (isset($admin['id'])) ? $admin['id'] : '';
@ -265,7 +272,7 @@ class Admins_Model extends CI_Model {
*/ */
public function delete($admin_id) { public function delete($admin_id) {
if (!is_numeric($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 // 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) { public function get_value($field_name, $admin_id) {
if (!is_string($field_name)) { 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)) { 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)); $result = $this->db->get_where('ea_users', array('id' => $admin_id));
if ($result->num_rows() == 0) { if ($result->num_rows() == 0) {
throw new Exception('The record with the given id does not exist in the ' 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. // Check if the required field name exist in database.

View file

@ -39,7 +39,8 @@
* 'google_token' * 'google_token'
* 'google_calendar' * 'google_calendar'
* 'sync_past_days' * 'sync_past_days'
* 'sync_future_days' * 'sync_future_days',
* 'calendar_view'
* *
* @package Models * @package Models
*/ */
@ -87,7 +88,7 @@ class Providers_Model extends CI_Model {
*/ */
public function exists($provider) { public function exists($provider) {
if (!isset($provider['email'])) { 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. // 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) { public function find_record_id($provider) {
if (!isset($provider['email'])) { 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 $result = $this->db
@ -221,12 +222,12 @@ class Providers_Model extends CI_Model {
if (!isset($provider['last_name']) if (!isset($provider['last_name'])
|| !isset($provider['email']) || !isset($provider['email'])
|| !isset($provider['phone_number'])) { || !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. // Validate provider email address.
if (!filter_var($provider['email'], FILTER_VALIDATE_EMAIL)) { 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. // 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. // When inserting a record the email address must be unique.
$provider_id = (isset($provider['id'])) ? $provider['id'] : ''; $provider_id = (isset($provider['id'])) ? $provider['id'] : '';
@ -294,7 +302,7 @@ class Providers_Model extends CI_Model {
*/ */
public function delete($provider_id) { public function delete($provider_id) {
if (!is_numeric($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(); $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 string $field_name The field name of the value to be returned.
* @param numeric $provider_id Record id 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. * @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 $field_name argument is not a valid string.
* @throws Exception When the $admin_id is not a valid numeric. * @throws Exception When the $provider_id is not a valid numeric.
* @throws Exception When the admin record does not exist in the database. * @throws Exception When the provider record does not exist in the database.
* @throws Exception When the selected field value is not present on database. * @throws Exception When the selected field value is not present on database.
*/ */
public function get_value($field_name, $provider_id) { public function get_value($field_name, $provider_id) {
if (!is_numeric($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)) { 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)); $result = $this->db->get_where('ea_users', array('id' => $provider_id));
if ($result->num_rows() == 0) { if ($result->num_rows() == 0) {
throw new Exception('The record with the $provider_id argument does not exist in ' 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(); $provider = $result->row_array();
if (!isset($provider[$field_name])) { if (!isset($provider[$field_name])) {
throw new Exception('The given $field_name argument does not exist in the ' throw new Exception('The given $field_name argument does not exist in the '
. 'database : ' . $field_name); . 'database: ' . $field_name);
} }
return $provider[$field_name]; return $provider[$field_name];
@ -509,7 +518,7 @@ class Providers_Model extends CI_Model {
*/ */
protected function save_settings($settings, $provider_id) { protected function save_settings($settings, $provider_id) {
if (!is_numeric($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)) { if (count($settings) == 0 || !is_array($settings)) {

View file

@ -206,12 +206,12 @@ class Secretaries_Model extends CI_Model {
if (!isset($secretary['last_name']) if (!isset($secretary['last_name'])
|| !isset($secretary['email']) || !isset($secretary['email'])
|| !isset($secretary['phone_number'])) { || !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. // Validate secretary email address.
if (!filter_var($secretary['email'], FILTER_VALIDATE_EMAIL)) { 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. // 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. // When inserting a record the email address must be unique.
$secretary_id = (isset($secretary['id'])) ? $secretary['id'] : ''; $secretary_id = (isset($secretary['id'])) ? $secretary['id'] : '';
@ -261,7 +268,7 @@ class Secretaries_Model extends CI_Model {
*/ */
public function delete($secretary_id) { public function delete($secretary_id) {
if (!is_numeric($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(); $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) { public function get_value($field_name, $secretary_id) {
if (!is_string($field_name)) { 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)) { 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)); $result = $this->db->get_where('ea_users', array('id' => $secretary_id));
if ($result->num_rows() == 0) { if ($result->num_rows() == 0) {
throw new Exception('The record with the given id does not exist in the ' 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. // 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) { protected function save_settings($settings, $secretary_id) {
if (!is_numeric($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)) { if (count($settings) == 0 || !is_array($settings)) {