forked from mirrors/easyappointments
Type casting for the Admins_model.php
This commit is contained in:
parent
64205cb23b
commit
d1b78397ef
1 changed files with 34 additions and 5 deletions
|
@ -19,6 +19,14 @@
|
|||
* @package Models
|
||||
*/
|
||||
class Admins_model extends EA_Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) an admin.
|
||||
*
|
||||
|
@ -261,6 +269,8 @@ class Admins_model extends EA_Model {
|
|||
|
||||
$admin = $this->db->get_where('users', ['id' => $admin_id])->row_array();
|
||||
|
||||
$this->cast($admin);
|
||||
|
||||
$admin['settings'] = $this->db->get_where('user_settings', ['id_users' => $admin_id])->row_array();
|
||||
|
||||
unset(
|
||||
|
@ -305,6 +315,8 @@ class Admins_model extends EA_Model {
|
|||
// Check if the required field is part of the admin data.
|
||||
$admin = $query->row_array();
|
||||
|
||||
$this->cast($admin);
|
||||
|
||||
if ( ! array_key_exists($field, $admin))
|
||||
{
|
||||
throw new InvalidArgumentException('The requested field was not found in the admin data: ' . $field);
|
||||
|
@ -341,6 +353,8 @@ class Admins_model extends EA_Model {
|
|||
|
||||
foreach ($admins as &$admin)
|
||||
{
|
||||
$this->cast($admin);
|
||||
|
||||
$admin['settings'] = $this->db->get_where('user_settings', ['id_users' => $admin['id']])->row_array();
|
||||
|
||||
unset(
|
||||
|
@ -460,7 +474,7 @@ class Admins_model extends EA_Model {
|
|||
{
|
||||
$role_id = $this->get_admin_role_id();
|
||||
|
||||
return $this
|
||||
$admins = $this
|
||||
->db
|
||||
->select()
|
||||
->from('users')
|
||||
|
@ -480,6 +494,21 @@ class Admins_model extends EA_Model {
|
|||
->order_by($order_by)
|
||||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach ($admins as &$admin)
|
||||
{
|
||||
$this->cast($admin);
|
||||
|
||||
$admin['settings'] = $this->db->get_where('user_settings', ['id_users' => $admin['id']])->row_array();
|
||||
|
||||
unset(
|
||||
$admin['settings']['id_users'],
|
||||
$admin['settings']['password'],
|
||||
$admin['settings']['salt']
|
||||
);
|
||||
}
|
||||
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue