forked from mirrors/easyappointments
Type casting for the Users_model.php
This commit is contained in:
parent
d62dd9b053
commit
b7305be038
1 changed files with 22 additions and 1 deletions
|
@ -19,6 +19,14 @@
|
|||
* @package Models
|
||||
*/
|
||||
class Users_model extends EA_Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a user.
|
||||
*
|
||||
|
@ -170,6 +178,8 @@ class Users_model extends EA_Model {
|
|||
}
|
||||
|
||||
$user = $this->db->get_where('users', ['id' => $user_id])->row_array();
|
||||
|
||||
$this->cast($user);
|
||||
|
||||
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user_id])->row_array();
|
||||
|
||||
|
@ -210,6 +220,8 @@ class Users_model extends EA_Model {
|
|||
|
||||
// Check if the required field is part of the user data.
|
||||
$user = $query->row_array();
|
||||
|
||||
$this->cast($user);
|
||||
|
||||
if ( ! array_key_exists($field, $user))
|
||||
{
|
||||
|
@ -245,6 +257,8 @@ class Users_model extends EA_Model {
|
|||
|
||||
foreach ($users as &$user)
|
||||
{
|
||||
$this->cast($user);
|
||||
|
||||
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row_array();
|
||||
|
||||
unset(
|
||||
|
@ -343,7 +357,7 @@ class Users_model extends EA_Model {
|
|||
*/
|
||||
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
{
|
||||
return $this
|
||||
$users = $this
|
||||
->db
|
||||
->select()
|
||||
->from('users')
|
||||
|
@ -362,6 +376,13 @@ class Users_model extends EA_Model {
|
|||
->order_by($order_by)
|
||||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach ($users as &$user)
|
||||
{
|
||||
$this->cast($user);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue