mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
Type casting for the Consents_model.php
This commit is contained in:
parent
d1b78397ef
commit
6cc17d7bf5
1 changed files with 36 additions and 9 deletions
|
@ -19,6 +19,13 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Consents_model extends EA_Model {
|
class Consents_model extends EA_Model {
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save (insert or update) a consent.
|
* Save (insert or update) a consent.
|
||||||
*
|
*
|
||||||
|
@ -138,7 +145,11 @@ class Consents_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('The provided consent ID was not found in the database: ' . $consent_id);
|
throw new InvalidArgumentException('The provided consent ID was not found in the database: ' . $consent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->db->get_where('consents', ['id' => $consent_id])->row_array();
|
$consent = $this->db->get_where('consents', ['id' => $consent_id])->row_array();
|
||||||
|
|
||||||
|
$this->cast($consent);
|
||||||
|
|
||||||
|
return $consent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +174,7 @@ class Consents_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('The consent ID argument cannot be empty.');
|
throw new InvalidArgumentException('The consent ID argument cannot be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the user exists.
|
// Check whether the consent exists.
|
||||||
$query = $this->db->get_where('consents', ['id' => $consent_id]);
|
$query = $this->db->get_where('consents', ['id' => $consent_id]);
|
||||||
|
|
||||||
if ( ! $query->num_rows())
|
if ( ! $query->num_rows())
|
||||||
|
@ -171,15 +182,17 @@ class Consents_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('The provided consent ID was not found in the database: ' . $consent_id);
|
throw new InvalidArgumentException('The provided consent ID was not found in the database: ' . $consent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the required field is part of the user data.
|
// Check if the required field is part of the consent data.
|
||||||
$user = $query->row_array();
|
$consent = $query->row_array();
|
||||||
|
|
||||||
|
$this->cast($consent);
|
||||||
|
|
||||||
if ( ! array_key_exists($field, $user))
|
if ( ! array_key_exists($field, $consent))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The requested field was not found in the user data: ' . $field);
|
throw new InvalidArgumentException('The requested field was not found in the consent data: ' . $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $user[$field];
|
return $consent[$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,7 +217,14 @@ class Consents_model extends EA_Model {
|
||||||
$this->db->order_by($order_by);
|
$this->db->order_by($order_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->db->get('consents', $limit, $offset)->result_array();
|
$consents = $this->db->get('consents', $limit, $offset)->result_array();
|
||||||
|
|
||||||
|
foreach($consents as &$consent)
|
||||||
|
{
|
||||||
|
$this->cast($consent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $consents;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,7 +249,7 @@ class Consents_model extends EA_Model {
|
||||||
*/
|
*/
|
||||||
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||||
{
|
{
|
||||||
return $this
|
$consents = $this
|
||||||
->db
|
->db
|
||||||
->select()
|
->select()
|
||||||
->from('consents')
|
->from('consents')
|
||||||
|
@ -242,6 +262,13 @@ class Consents_model extends EA_Model {
|
||||||
->order_by($order_by)
|
->order_by($order_by)
|
||||||
->get()
|
->get()
|
||||||
->result_array();
|
->result_array();
|
||||||
|
|
||||||
|
foreach($consents as &$consent)
|
||||||
|
{
|
||||||
|
$this->cast($consent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $consents;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue