Groupped load commands in model constructor methods
This commit is contained in:
parent
8842e2d918
commit
39c8ec9068
7 changed files with 79 additions and 41 deletions
|
@ -22,6 +22,14 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Admins_Model extends CI_Model {
|
class Admins_Model extends CI_Model {
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('general');
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add (insert or update) an admin user record into database.
|
* Add (insert or update) an admin user record into database.
|
||||||
*
|
*
|
||||||
|
@ -63,8 +71,6 @@ class Admins_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($admin)
|
public function validate($admin)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
|
||||||
|
|
||||||
// If a record id is provided then check whether the record exists in the database.
|
// If a record id is provided then check whether the record exists in the database.
|
||||||
if (isset($admin['id']))
|
if (isset($admin['id']))
|
||||||
{
|
{
|
||||||
|
@ -227,8 +233,6 @@ class Admins_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function insert($admin)
|
protected function insert($admin)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
$admin['id_roles'] = $this->get_admin_role_id();
|
$admin['id_roles'] = $this->get_admin_role_id();
|
||||||
$settings = $admin['settings'];
|
$settings = $admin['settings'];
|
||||||
unset($admin['settings']);
|
unset($admin['settings']);
|
||||||
|
@ -278,8 +282,6 @@ class Admins_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function update($admin)
|
protected function update($admin)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
$settings = $admin['settings'];
|
$settings = $admin['settings'];
|
||||||
unset($admin['settings']);
|
unset($admin['settings']);
|
||||||
$settings['id_users'] = $admin['id'];
|
$settings['id_users'] = $admin['id'];
|
||||||
|
|
|
@ -20,6 +20,18 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Appointments_Model extends CI_Model {
|
class Appointments_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* Appointments_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
|
||||||
|
$this->load->library('timezones');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an appointment record to the database.
|
* Add an appointment record to the database.
|
||||||
*
|
*
|
||||||
|
@ -61,8 +73,6 @@ class Appointments_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($appointment)
|
public function validate($appointment)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
|
||||||
|
|
||||||
// If a appointment id is given, check whether the record exists in the database.
|
// If a appointment id is given, check whether the record exists in the database.
|
||||||
if (isset($appointment['id']))
|
if (isset($appointment['id']))
|
||||||
{
|
{
|
||||||
|
@ -310,8 +320,6 @@ 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->library('timezones');
|
|
||||||
|
|
||||||
$appointment = $this->timezones->convert_event_timezone($appointment);
|
$appointment = $this->timezones->convert_event_timezone($appointment);
|
||||||
|
|
||||||
return $appointment;
|
return $appointment;
|
||||||
|
@ -356,8 +364,6 @@ 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->library('timezones');
|
|
||||||
|
|
||||||
$row_data = $this->timezones->convert_event_timezone($row_data);
|
$row_data = $this->timezones->convert_event_timezone($row_data);
|
||||||
|
|
||||||
return $row_data[$field_name];
|
return $row_data[$field_name];
|
||||||
|
@ -393,8 +399,6 @@ 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->library('timezones');
|
|
||||||
|
|
||||||
foreach ($appointments as &$appointment)
|
foreach ($appointments as &$appointment)
|
||||||
{
|
{
|
||||||
$appointment = $this->timezones->convert_event_timezone($appointment);
|
$appointment = $this->timezones->convert_event_timezone($appointment);
|
||||||
|
|
|
@ -20,6 +20,16 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Customers_Model extends CI_Model {
|
class Customers_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* Customers_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a customer record to the database.
|
* Add a customer record to the database.
|
||||||
*
|
*
|
||||||
|
@ -68,10 +78,7 @@ class Customers_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($customer)
|
public function validate($customer)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
// If a customer id is provided, check whether the record exist in the database.
|
||||||
|
|
||||||
// If a customer id is provided, check whether the record
|
|
||||||
// exist in the database.
|
|
||||||
if (isset($customer['id']))
|
if (isset($customer['id']))
|
||||||
{
|
{
|
||||||
$num_rows = $this->db->get_where('users',
|
$num_rows = $this->db->get_where('users',
|
||||||
|
|
|
@ -22,6 +22,17 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Providers_Model extends CI_Model {
|
class Providers_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* Providers_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
$this->load->helper('general');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add (insert - update) a service provider record.
|
* Add (insert - update) a service provider record.
|
||||||
*
|
*
|
||||||
|
@ -66,7 +77,6 @@ class Providers_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($provider)
|
public function validate($provider)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
|
||||||
|
|
||||||
// If a provider id is present, check whether the record exist in the database.
|
// If a provider id is present, check whether the record exist in the database.
|
||||||
if (isset($provider['id']))
|
if (isset($provider['id']))
|
||||||
|
@ -254,7 +264,6 @@ class Providers_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function insert($provider)
|
protected function insert($provider)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
// Get provider role id.
|
// Get provider role id.
|
||||||
$provider['id_roles'] = $this->get_providers_role_id();
|
$provider['id_roles'] = $this->get_providers_role_id();
|
||||||
|
@ -394,8 +403,6 @@ class Providers_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function update($provider)
|
protected function update($provider)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
// Store service and settings (must not be present on the $provider array).
|
// Store service and settings (must not be present on the $provider array).
|
||||||
$services = $provider['services'];
|
$services = $provider['services'];
|
||||||
unset($provider['services']);
|
unset($provider['services']);
|
||||||
|
|
|
@ -22,6 +22,17 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Secretaries_Model extends CI_Model {
|
class Secretaries_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* Secretaries_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('general');
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add (insert or update) a secretary user record into database.
|
* Add (insert or update) a secretary user record into database.
|
||||||
*
|
*
|
||||||
|
@ -63,8 +74,6 @@ class Secretaries_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($secretary)
|
public function validate($secretary)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
|
||||||
|
|
||||||
// If a record id is provided then check whether the record exists in the database.
|
// If a record id is provided then check whether the record exists in the database.
|
||||||
if (isset($secretary['id']))
|
if (isset($secretary['id']))
|
||||||
{
|
{
|
||||||
|
@ -233,8 +242,6 @@ class Secretaries_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function insert($secretary)
|
protected function insert($secretary)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
$providers = $secretary['providers'];
|
$providers = $secretary['providers'];
|
||||||
unset($secretary['providers']);
|
unset($secretary['providers']);
|
||||||
$settings = $secretary['settings'];
|
$settings = $secretary['settings'];
|
||||||
|
@ -358,8 +365,6 @@ class Secretaries_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
protected function update($secretary)
|
protected function update($secretary)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
|
|
||||||
$providers = $secretary['providers'];
|
$providers = $secretary['providers'];
|
||||||
unset($secretary['providers']);
|
unset($secretary['providers']);
|
||||||
$settings = $secretary['settings'];
|
$settings = $secretary['settings'];
|
||||||
|
|
|
@ -20,6 +20,16 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Services_Model extends CI_Model {
|
class Services_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* Services_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->helper('data_validation');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add (insert or update) a service record on the database
|
* Add (insert or update) a service record on the database
|
||||||
*
|
*
|
||||||
|
@ -55,14 +65,11 @@ class Services_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function validate($service)
|
public function validate($service)
|
||||||
{
|
{
|
||||||
$this->load->helper('data_validation');
|
// If record id is provided we need to check whether the record exists in the database.
|
||||||
|
|
||||||
// If record id is provided we need to check whether the record exists
|
|
||||||
// in the database.
|
|
||||||
if (isset($service['id']))
|
if (isset($service['id']))
|
||||||
{
|
{
|
||||||
$num_rows = $this->db->get_where('services', ['id' => $service['id']])
|
$num_rows = $this->db->get_where('services', ['id' => $service['id']])->num_rows();
|
||||||
->num_rows();
|
|
||||||
if ($num_rows == 0)
|
if ($num_rows == 0)
|
||||||
{
|
{
|
||||||
throw new Exception('Provided service id does not exist in the database.');
|
throw new Exception('Provided service id does not exist in the database.');
|
||||||
|
|
|
@ -22,6 +22,19 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class User_Model extends CI_Model {
|
class User_Model extends CI_Model {
|
||||||
|
/**
|
||||||
|
* User_Model constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->library('timezones');
|
||||||
|
|
||||||
|
$this->load->helper('general');
|
||||||
|
$this->load->helper('string');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user from the database for the "settings" page.
|
* Returns the user from the database for the "settings" page.
|
||||||
*
|
*
|
||||||
|
@ -53,7 +66,6 @@ class User_Model extends CI_Model {
|
||||||
// Prepare user password (hash).
|
// Prepare user password (hash).
|
||||||
if (isset($user_settings['password']))
|
if (isset($user_settings['password']))
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
$salt = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row()->salt;
|
$salt = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row()->salt;
|
||||||
$user_settings['password'] = hash_password($salt, $user_settings['password']);
|
$user_settings['password'] = hash_password($salt, $user_settings['password']);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +93,6 @@ class User_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function check_login($username, $password)
|
public function check_login($username, $password)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
$salt = $this->get_salt($username);
|
$salt = $this->get_salt($username);
|
||||||
$password = hash_password($salt, $password);
|
$password = hash_password($salt, $password);
|
||||||
|
|
||||||
|
@ -109,8 +120,6 @@ class User_Model extends CI_Model {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->library('timezones');
|
|
||||||
|
|
||||||
$default_timezone = $this->timezones->get_default_timezone();
|
$default_timezone = $this->timezones->get_default_timezone();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -167,9 +176,6 @@ class User_Model extends CI_Model {
|
||||||
*/
|
*/
|
||||||
public function regenerate_password($username, $email)
|
public function regenerate_password($username, $email)
|
||||||
{
|
{
|
||||||
$this->load->helper('general');
|
|
||||||
$this->load->helper('string');
|
|
||||||
|
|
||||||
$result = $this->db
|
$result = $this->db
|
||||||
->select('users.id')
|
->select('users.id')
|
||||||
->from('users')
|
->from('users')
|
||||||
|
|
Loading…
Reference in a new issue