Groupped load commands in model constructor methods

This commit is contained in:
Alex Tselegidis 2020-11-12 14:51:10 +02:00
parent 8842e2d918
commit 39c8ec9068
7 changed files with 79 additions and 41 deletions

View file

@ -22,6 +22,14 @@
* @package Models
*/
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.
*
@ -63,8 +71,6 @@ class Admins_Model extends CI_Model {
*/
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 (isset($admin['id']))
{
@ -227,8 +233,6 @@ class Admins_Model extends CI_Model {
*/
protected function insert($admin)
{
$this->load->helper('general');
$admin['id_roles'] = $this->get_admin_role_id();
$settings = $admin['settings'];
unset($admin['settings']);
@ -278,8 +282,6 @@ class Admins_Model extends CI_Model {
*/
protected function update($admin)
{
$this->load->helper('general');
$settings = $admin['settings'];
unset($admin['settings']);
$settings['id_users'] = $admin['id'];

View file

@ -20,6 +20,18 @@
* @package Models
*/
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.
*
@ -61,8 +73,6 @@ class Appointments_Model extends CI_Model {
*/
public function validate($appointment)
{
$this->load->helper('data_validation');
// If a appointment id is given, check whether the record exists in the database.
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();
$this->load->library('timezones');
$appointment = $this->timezones->convert_event_timezone($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);
}
$this->load->library('timezones');
$row_data = $this->timezones->convert_event_timezone($row_data);
return $row_data[$field_name];
@ -393,8 +399,6 @@ class Appointments_Model extends CI_Model {
$appointments = $this->db->get('appointments', $limit, $offset)->result_array();
$this->load->library('timezones');
foreach ($appointments as &$appointment)
{
$appointment = $this->timezones->convert_event_timezone($appointment);

View file

@ -20,6 +20,16 @@
* @package Models
*/
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.
*
@ -68,10 +78,7 @@ class Customers_Model extends CI_Model {
*/
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']))
{
$num_rows = $this->db->get_where('users',

View file

@ -22,6 +22,17 @@
* @package Models
*/
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.
*
@ -66,7 +77,6 @@ class Providers_Model extends CI_Model {
*/
public function validate($provider)
{
$this->load->helper('data_validation');
// If a provider id is present, check whether the record exist in the database.
if (isset($provider['id']))
@ -254,7 +264,6 @@ class Providers_Model extends CI_Model {
*/
protected function insert($provider)
{
$this->load->helper('general');
// Get provider role id.
$provider['id_roles'] = $this->get_providers_role_id();
@ -394,8 +403,6 @@ class Providers_Model extends CI_Model {
*/
protected function update($provider)
{
$this->load->helper('general');
// Store service and settings (must not be present on the $provider array).
$services = $provider['services'];
unset($provider['services']);

View file

@ -22,6 +22,17 @@
* @package Models
*/
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.
*
@ -63,8 +74,6 @@ class Secretaries_Model extends CI_Model {
*/
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 (isset($secretary['id']))
{
@ -233,8 +242,6 @@ class Secretaries_Model extends CI_Model {
*/
protected function insert($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];
@ -358,8 +365,6 @@ class Secretaries_Model extends CI_Model {
*/
protected function update($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];

View file

@ -20,6 +20,16 @@
* @package Models
*/
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
*
@ -55,14 +65,11 @@ class Services_Model extends CI_Model {
*/
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']))
{
$num_rows = $this->db->get_where('services', ['id' => $service['id']])
->num_rows();
$num_rows = $this->db->get_where('services', ['id' => $service['id']])->num_rows();
if ($num_rows == 0)
{
throw new Exception('Provided service id does not exist in the database.');

View file

@ -22,6 +22,19 @@
* @package Models
*/
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.
*
@ -53,7 +66,6 @@ class User_Model extends CI_Model {
// Prepare user password (hash).
if (isset($user_settings['password']))
{
$this->load->helper('general');
$salt = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row()->salt;
$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)
{
$this->load->helper('general');
$salt = $this->get_salt($username);
$password = hash_password($salt, $password);
@ -109,8 +120,6 @@ class User_Model extends CI_Model {
return NULL;
}
$this->load->library('timezones');
$default_timezone = $this->timezones->get_default_timezone();
return [
@ -167,9 +176,6 @@ class User_Model extends CI_Model {
*/
public function regenerate_password($username, $email)
{
$this->load->helper('general');
$this->load->helper('string');
$result = $this->db
->select('users.id')
->from('users')