2013-07-27 00:30:44 +03:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed.');
|
|
|
|
|
2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2017-01-31 09:35:34 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2017, Alex Tselegidis
|
2015-07-20 22:41:24 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
2016-07-17 13:49:27 +03:00
|
|
|
* Admins Model Class
|
2013-07-28 01:48:19 +03:00
|
|
|
*
|
|
|
|
* Handles the database actions for admin users management.
|
|
|
|
*
|
|
|
|
* Data Structure:
|
|
|
|
* 'fist_name'
|
|
|
|
* 'last_name' (required)
|
|
|
|
* 'email' (required)
|
|
|
|
* 'mobile_number'
|
|
|
|
* 'phone_number' (required)
|
|
|
|
* 'address'
|
|
|
|
* 'city'
|
|
|
|
* 'state'
|
|
|
|
* 'zip_code'
|
|
|
|
* 'notes'
|
|
|
|
* 'id_roles'
|
2013-09-03 21:58:56 +03:00
|
|
|
* 'settings' >>> array that contains user settings (username, password etc)
|
2015-07-08 01:36:16 +03:00
|
|
|
*
|
|
|
|
* @package Models
|
2013-07-28 01:48:19 +03:00
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
class Admins_Model extends CI_Model {
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
2013-08-26 14:53:11 +03:00
|
|
|
* Add (insert or update) an admin user record into database.
|
2013-07-28 01:48:19 +03:00
|
|
|
*
|
|
|
|
* @param array $admin Contains the admin user data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return int Returns the record id.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the admin data are invalid (see validate() method).
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function add($admin) {
|
2013-09-26 19:06:57 +03:00
|
|
|
$this->validate($admin);
|
2013-07-28 01:48:19 +03:00
|
|
|
|
|
|
|
if ($this->exists($admin) && !isset($admin['id'])) {
|
|
|
|
$admin['id'] = $this->find_record_id($admin);
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!isset($admin['id'])) {
|
|
|
|
$admin['id'] = $this->insert($admin);
|
|
|
|
} else {
|
|
|
|
$admin['id'] = $this->update($admin);
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:49:39 +03:00
|
|
|
return (int)$admin['id'];
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Check whether a particular admin record exists in the database.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param array $admin Contains the admin data. The 'email' value is required to be present at the moment.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return bool Returns whether the record exists or not.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the 'email' value is not present on the $admin argument.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function exists($admin) {
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!isset($admin['email'])) {
|
|
|
|
throw new Exception('Admin email is not provided: ' . print_r($admin, TRUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method shouldn't depend on another method of this class.
|
|
|
|
$num_rows = $this->db
|
|
|
|
->select('*')
|
|
|
|
->from('ea_users')
|
|
|
|
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
|
2013-08-26 14:53:11 +03:00
|
|
|
->where('ea_users.email', $admin['email'])
|
2013-07-28 01:48:19 +03:00
|
|
|
->where('ea_roles.slug', DB_SLUG_ADMIN)
|
|
|
|
->get()->num_rows();
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
return ($num_rows > 0) ? TRUE : FALSE;
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Insert a new admin record into the database.
|
|
|
|
*
|
|
|
|
* @param array $admin Contains the admin data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return int Returns the new record id.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the insert operation fails.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function insert($admin) {
|
2013-09-23 18:42:36 +03:00
|
|
|
$this->load->helper('general');
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
$admin['id_roles'] = $this->get_admin_role_id();
|
2013-09-03 21:58:56 +03:00
|
|
|
$settings = $admin['settings'];
|
|
|
|
unset($admin['settings']);
|
|
|
|
|
|
|
|
$this->db->trans_begin();
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!$this->db->insert('ea_users', $admin)) {
|
|
|
|
throw new Exception('Could not insert admin into the database.');
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:49:39 +03:00
|
|
|
$admin['id'] = (int)$this->db->insert_id();
|
2013-09-03 21:58:56 +03:00
|
|
|
$settings['id_users'] = $admin['id'];
|
2013-09-23 18:42:36 +03:00
|
|
|
$settings['salt'] = generate_salt();
|
|
|
|
$settings['password'] = hash_password($settings['salt'], $settings['password']);
|
2013-09-03 21:58:56 +03:00
|
|
|
|
|
|
|
// Insert admin settings.
|
|
|
|
if (!$this->db->insert('ea_user_settings', $settings)) {
|
|
|
|
$this->db->trans_rollback();
|
|
|
|
throw new Exception('Could not insert admin settings into the database.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->trans_complete();
|
|
|
|
|
|
|
|
return $admin['id'];
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Update an existing admin record in the database.
|
|
|
|
*
|
|
|
|
* @param array $admin Contains the admin record data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* @return int Returns the record id.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the update operation fails.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function update($admin) {
|
2013-09-23 18:42:36 +03:00
|
|
|
$this->load->helper('general');
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$settings = $admin['settings'];
|
|
|
|
unset($admin['settings']);
|
|
|
|
$settings['id_users'] = $admin['id'];
|
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
if (isset($settings['password'])) {
|
|
|
|
$salt = $this->db->get_where('ea_user_settings', array('id_users' => $admin['id']))->row()->salt;
|
|
|
|
$settings['password'] = hash_password($salt, $settings['password']);
|
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
$this->db->where('id', $admin['id']);
|
2013-09-03 21:58:56 +03:00
|
|
|
if (!$this->db->update('ea_users', $admin)) {
|
2013-07-28 01:48:19 +03:00
|
|
|
throw new Exception('Could not update admin record.');
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$this->db->where('id_users', $settings['id_users']);
|
|
|
|
if (!$this->db->update('ea_user_settings', $settings)) {
|
|
|
|
throw new Exception('Could not update admin settings.');
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:49:39 +03:00
|
|
|
return (int)$admin['id'];
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
2013-08-26 14:53:11 +03:00
|
|
|
* Find the database record id of an admin user.
|
2013-07-28 01:48:19 +03:00
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param array $admin Contains the admin data. The 'email' value is required in order to find the record id.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return int Returns the record id
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the 'email' value is not present on the $admin array.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function find_record_id($admin) {
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!isset($admin['email'])) {
|
|
|
|
throw new Exception('Admin email was not provided: ' . print_r($admin, TRUE));
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
$result = $this->db
|
|
|
|
->select('ea_users.id')
|
|
|
|
->from('ea_users')
|
|
|
|
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
|
|
|
|
->where('ea_users.email', $admin['email'])
|
|
|
|
->where('ea_roles.slug', DB_SLUG_ADMIN)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
if ($result->num_rows() == 0) {
|
|
|
|
throw new Exception('Could not find admin record id.');
|
|
|
|
}
|
|
|
|
|
2017-08-08 10:49:39 +03:00
|
|
|
return (int)$result->row()->id;
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Validate admin user data before add() operation is executed.
|
|
|
|
*
|
|
|
|
* @param array $admin Contains the admin user data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return bool Returns the validation result.
|
2013-09-26 19:06:57 +03:00
|
|
|
*
|
|
|
|
* @throws Exception When data are invalid.
|
2013-07-28 01:48:19 +03:00
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function validate($admin) {
|
2013-07-28 01:48:19 +03:00
|
|
|
$this->load->helper('data_validation');
|
2013-09-26 19:06:57 +03:00
|
|
|
|
|
|
|
// If a record id is provided then check whether the record exists in the database.
|
|
|
|
if (isset($admin['id'])) {
|
|
|
|
$num_rows = $this->db->get_where('ea_users', array('id' => $admin['id']))
|
|
|
|
->num_rows();
|
|
|
|
if ($num_rows == 0) {
|
|
|
|
throw new Exception('Given admin id does not exist in database: ' . $admin['id']);
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate required fields integrity.
|
|
|
|
if (!isset($admin['last_name'])
|
|
|
|
|| !isset($admin['email'])
|
|
|
|
|| !isset($admin['phone_number'])) {
|
2016-07-17 13:49:27 +03:00
|
|
|
throw new Exception('Not all required fields are provided: ' . print_r($admin, TRUE));
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate admin email address.
|
|
|
|
if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) {
|
2016-07-17 13:49:27 +03:00
|
|
|
throw new Exception('Invalid email address provided: ' . $admin['email']);
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
2013-11-23 21:10:31 +02:00
|
|
|
|
|
|
|
// Check if username exists.
|
|
|
|
if (isset($admin['settings']['username'])) {
|
|
|
|
$user_id = (isset($admin['id'])) ? $admin['id'] : '';
|
|
|
|
if (!$this->validate_username($admin['settings']['username'], $user_id)) {
|
|
|
|
throw new Exception ('Username already exists. Please select a different '
|
|
|
|
. 'username for this record.');
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 19:06:57 +03:00
|
|
|
|
|
|
|
// Validate admin password
|
|
|
|
if (isset($admin['settings']['password'])) {
|
|
|
|
if (strlen($admin['settings']['password']) < MIN_PASSWORD_LENGTH) {
|
|
|
|
throw new Exception('The user password must be at least '
|
|
|
|
. MIN_PASSWORD_LENGTH . ' characters long.');
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
2016-07-17 13:49:27 +03:00
|
|
|
|
|
|
|
// Validate calendar view mode.
|
|
|
|
if (isset($admin['settings']['calendar_view']) && ($admin['settings']['calendar_view'] !== CALENDAR_VIEW_DEFAULT
|
2016-07-19 00:46:15 +03:00
|
|
|
&& $admin['settings']['calendar_view'] !== CALENDAR_VIEW_TABLE)) {
|
2016-07-17 13:49:27 +03:00
|
|
|
throw new Exception('The calendar view setting must be either "' . CALENDAR_VIEW_DEFAULT
|
|
|
|
. '" or "' . CALENDAR_VIEW_TABLE . '", given: ' . $admin['settings']['calendar_view']);
|
|
|
|
}
|
2013-11-23 21:10:31 +02:00
|
|
|
|
|
|
|
// When inserting a record the email address must be unique.
|
2013-11-24 19:01:46 +02:00
|
|
|
$admin_id = (isset($admin['id'])) ? $admin['id'] : '';
|
|
|
|
|
2013-11-23 21:10:31 +02:00
|
|
|
$num_rows = $this->db
|
|
|
|
->select('*')
|
|
|
|
->from('ea_users')
|
|
|
|
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
|
|
|
|
->where('ea_roles.slug', DB_SLUG_ADMIN)
|
|
|
|
->where('ea_users.email', $admin['email'])
|
2013-11-24 19:01:46 +02:00
|
|
|
->where('ea_users.id <>', $admin_id)
|
2013-11-23 21:10:31 +02:00
|
|
|
->get()
|
|
|
|
->num_rows();
|
|
|
|
|
2013-11-24 19:01:46 +02:00
|
|
|
if ($num_rows > 0) {
|
2013-11-23 21:10:31 +02:00
|
|
|
throw new Exception('Given email address belongs to another admin record. '
|
|
|
|
. 'Please use a different email.');
|
|
|
|
}
|
2013-09-26 19:06:57 +03:00
|
|
|
|
|
|
|
return TRUE; // Operation completed successfully.
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Delete an existing admin record from the database.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param int $admin_id The admin record id to be deleted.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return bool Returns the delete operation result.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
|
|
|
* @throws Exception When the $admin_id is not a valid int value.
|
|
|
|
* @throws Exception When the record to be deleted is the only one admin user left on the system.
|
2013-07-28 01:48:19 +03:00
|
|
|
*/
|
|
|
|
public function delete($admin_id) {
|
|
|
|
if (!is_numeric($admin_id)) {
|
2016-07-17 13:49:27 +03:00
|
|
|
throw new Exception('Invalid argument type $admin_id: ' . $admin_id);
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// There must be always at least one admin user. If this is the only admin
|
|
|
|
// the system, it cannot be deleted.
|
|
|
|
$admin_count = $this->db->get_where('ea_users',
|
2013-08-26 14:53:11 +03:00
|
|
|
array('id_roles' => $this->get_admin_role_id()))->num_rows();
|
2013-07-28 01:48:19 +03:00
|
|
|
if ($admin_count == 1) {
|
|
|
|
throw new Exception('Record could not be deleted. The system requires at least '
|
|
|
|
. 'one admin user.');
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
$num_rows = $this->db->get_where('ea_users', array('id' => $admin_id))->num_rows();
|
|
|
|
if ($num_rows == 0) {
|
|
|
|
return FALSE; // Record does not exist in database.
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->db->delete('ea_users', array('id' => $admin_id));
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Get a specific admin record from the database.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param int $admin_id The id of the record to be returned.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return array Returns an array with the admin user data.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
|
|
|
* @throws Exception When the $admin_id is not a valid int value.
|
2013-07-28 01:48:19 +03:00
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function get_row($admin_id) {
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!is_numeric($admin_id)) {
|
|
|
|
throw new Exception('$admin_id argument is not a valid numeric value: ' . $admin_id);
|
|
|
|
}
|
2013-09-13 16:21:03 +03:00
|
|
|
|
|
|
|
// Check if record exists
|
|
|
|
if ($this->db->get_where('ea_users', array('id' => $admin_id))->num_rows() == 0) {
|
|
|
|
throw new Exception('The given admin id does not match a record in the database.');
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
$admin = $this->db->get_where('ea_users', array('id' => $admin_id))->row_array();
|
2013-09-13 16:21:03 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$admin['settings'] = $this->db->get_where('ea_user_settings',
|
|
|
|
array('id_users' => $admin_id))->row_array();
|
|
|
|
unset($admin['settings']['id_users']);
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
return $admin;
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Get a specific field value from the database.
|
|
|
|
*
|
|
|
|
* @param string $field_name The field name of the value to be returned.
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param int $admin_id Record id of the value to be returned.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return string Returns the selected record value from the database.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the $field_name argument is not a valid string.
|
2017-09-08 15:03:45 +03:00
|
|
|
* @throws Exception When the $admin_id is not a valid int.
|
2013-07-28 01:48:19 +03:00
|
|
|
* @throws Exception When the admin record does not exist in the database.
|
|
|
|
* @throws Exception When the selected field value is not present on database.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function get_value($field_name, $admin_id) {
|
2013-07-28 01:48:19 +03:00
|
|
|
if (!is_string($field_name)) {
|
2016-07-17 13:49:27 +03:00
|
|
|
throw new Exception('$field_name argument is not a string: ' . $field_name);
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_numeric($admin_id)) {
|
|
|
|
throw new Exception('$admin_id argument is not a valid numeric value: ' . $admin_id);
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
// Check whether the admin record exists.
|
|
|
|
$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 '
|
2016-07-17 13:49:27 +03:00
|
|
|
. 'database: ' . $admin_id);
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the required field name exist in database.
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $provider[$field_name];
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Get all, or specific admin records from database.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param string|array $where_clause (OPTIONAL) The WHERE clause of the query to be executed. Use this to get
|
|
|
|
* specific admin records.
|
|
|
|
*
|
2013-07-28 01:48:19 +03:00
|
|
|
* @return array Returns an array with admin records.
|
|
|
|
*/
|
2013-07-27 00:30:44 +03:00
|
|
|
public function get_batch($where_clause = '') {
|
2013-08-26 14:53:11 +03:00
|
|
|
$role_id = $this->get_admin_role_id();
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
if ($where_clause != '') {
|
|
|
|
$this->db->where($where_clause);
|
|
|
|
}
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$batch = $this->db->get_where('ea_users', array('id_roles' => $role_id))->result_array();
|
|
|
|
|
|
|
|
// Get every admin settings.
|
|
|
|
foreach ($batch as &$admin) {
|
|
|
|
$admin['settings'] = $this->db->get_where('ea_user_settings',
|
|
|
|
array('id_users' => $admin['id']))->row_array();
|
|
|
|
unset($admin['settings']['id_users']);
|
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
return $batch;
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|
|
|
|
|
2013-07-28 01:48:19 +03:00
|
|
|
/**
|
|
|
|
* Get the admin users role id.
|
|
|
|
*
|
|
|
|
* @return int Returns the role record id.
|
|
|
|
*/
|
|
|
|
public function get_admin_role_id() {
|
2017-08-08 10:49:39 +03:00
|
|
|
return (int)$this->db->get_where('ea_roles', array('slug' => DB_SLUG_ADMIN))->row()->id;
|
2013-07-28 01:48:19 +03:00
|
|
|
}
|
2013-09-23 18:42:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate Records Username
|
|
|
|
*
|
|
|
|
* @param string $username The provider records username.
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param int $user_id The user record id.
|
|
|
|
*
|
2013-09-23 18:42:36 +03:00
|
|
|
* @return bool Returns the validation result.
|
|
|
|
*/
|
2013-11-23 21:10:31 +02:00
|
|
|
public function validate_username($username, $user_id) {
|
|
|
|
$num_rows = $this->db->get_where('ea_user_settings',
|
|
|
|
array('username' => $username, 'id_users <> ' => $user_id))->num_rows();
|
|
|
|
return ($num_rows > 0) ? FALSE : TRUE;
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
2013-07-27 00:30:44 +03:00
|
|
|
}
|