mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-25 08:03:01 +03:00
Type casting for the Services_model.php
This commit is contained in:
parent
791f1e38e4
commit
83777d35ba
1 changed files with 41 additions and 4 deletions
|
@ -19,6 +19,16 @@
|
|||
* @package Models
|
||||
*/
|
||||
class Services_model extends EA_Model {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'price' => 'float',
|
||||
'attendants_number' => 'integer',
|
||||
'id_service_categories' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a service.
|
||||
*
|
||||
|
@ -183,7 +193,11 @@ class Services_model extends EA_Model {
|
|||
throw new InvalidArgumentException('The provided service ID was not found in the database: ' . $service_id);
|
||||
}
|
||||
|
||||
return $this->db->get_where('services', ['id' => $service_id])->row_array();
|
||||
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
|
||||
|
||||
$this->cast($service);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,6 +232,8 @@ class Services_model extends EA_Model {
|
|||
|
||||
// Check if the required field is part of the service data.
|
||||
$service = $query->row_array();
|
||||
|
||||
$this->cast($service);
|
||||
|
||||
if ( ! array_key_exists($field, $service))
|
||||
{
|
||||
|
@ -249,7 +265,14 @@ class Services_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
return $this->db->get('services', $limit, $offset)->result_array();
|
||||
$services = $this->db->get('services', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($services as $service)
|
||||
{
|
||||
$this->cast($service);
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,7 +282,7 @@ class Services_model extends EA_Model {
|
|||
*/
|
||||
public function get_available_services(): array
|
||||
{
|
||||
return $this
|
||||
$services = $this
|
||||
->db
|
||||
->distinct()
|
||||
->select('services.*, service_categories.name AS category_name, service_categories.id AS category_id')
|
||||
|
@ -269,6 +292,13 @@ class Services_model extends EA_Model {
|
|||
->order_by('name ASC')
|
||||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach ($services as $service)
|
||||
{
|
||||
$this->cast($service);
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,7 +323,7 @@ class Services_model extends EA_Model {
|
|||
*/
|
||||
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
{
|
||||
return $this
|
||||
$services = $this
|
||||
->db
|
||||
->select()
|
||||
->from('services')
|
||||
|
@ -304,6 +334,13 @@ class Services_model extends EA_Model {
|
|||
->order_by($order_by)
|
||||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach ($services as $service)
|
||||
{
|
||||
$this->cast($service);
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue