forked from mirrors/easyappointments
Type casting for the Service_categories_model.php
This commit is contained in:
parent
879b58ad6a
commit
791f1e38e4
1 changed files with 30 additions and 3 deletions
|
@ -19,6 +19,13 @@
|
||||||
* @package Models
|
* @package Models
|
||||||
*/
|
*/
|
||||||
class Service_categories_model extends EA_Model {
|
class Service_categories_model extends EA_Model {
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save (insert or update) a service category.
|
* Save (insert or update) a service category.
|
||||||
*
|
*
|
||||||
|
@ -140,7 +147,11 @@ class Service_categories_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('The provided service category ID was not found in the database: ' . $service_category_id);
|
throw new InvalidArgumentException('The provided service category ID was not found in the database: ' . $service_category_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->db->get_where('service_categories', ['id' => $service_category_id])->row_array();
|
$service_category = $this->db->get_where('service_categories', ['id' => $service_category_id])->row_array();
|
||||||
|
|
||||||
|
$this->cast($service_category);
|
||||||
|
|
||||||
|
return $service_category;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,6 +187,8 @@ class Service_categories_model extends EA_Model {
|
||||||
// Check if the required field is part of the service category data.
|
// Check if the required field is part of the service category data.
|
||||||
$service_category = $query->row_array();
|
$service_category = $query->row_array();
|
||||||
|
|
||||||
|
$this->cast($service_category);
|
||||||
|
|
||||||
if ( ! array_key_exists($field, $service_category))
|
if ( ! array_key_exists($field, $service_category))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The requested field was not found in the service category data: ' . $field);
|
throw new InvalidArgumentException('The requested field was not found in the service category data: ' . $field);
|
||||||
|
@ -206,7 +219,14 @@ class Service_categories_model extends EA_Model {
|
||||||
$this->db->order_by($order_by);
|
$this->db->order_by($order_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->db->get('service_categories', $limit, $offset)->result_array();
|
$service_categories = $this->db->get('service_categories', $limit, $offset)->result_array();
|
||||||
|
|
||||||
|
foreach($service_categories as $service_category)
|
||||||
|
{
|
||||||
|
$this->cast($service_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,7 +251,7 @@ class Service_categories_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
|
$service_categories = $this
|
||||||
->db
|
->db
|
||||||
->select()
|
->select()
|
||||||
->from('service_categories')
|
->from('service_categories')
|
||||||
|
@ -242,6 +262,13 @@ class Service_categories_model extends EA_Model {
|
||||||
->order_by($order_by)
|
->order_by($order_by)
|
||||||
->get()
|
->get()
|
||||||
->result_array();
|
->result_array();
|
||||||
|
|
||||||
|
foreach($service_categories as &$service_category)
|
||||||
|
{
|
||||||
|
$this->cast($service_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue