Various fixes and additions to the model classes
This commit is contained in:
parent
0b058cece7
commit
b4f903e724
9 changed files with 143 additions and 66 deletions
|
@ -41,9 +41,9 @@ class Admins_model extends EA_Model {
|
|||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'zip' => 'zip_code',
|
||||
'notes' => 'notes',
|
||||
'timezone' => 'timezone',
|
||||
'language' => 'language',
|
||||
'notes' => 'notes',
|
||||
'roleId' => 'id_roles',
|
||||
];
|
||||
|
||||
|
@ -499,6 +499,7 @@ class Admins_model extends EA_Model {
|
|||
->select()
|
||||
->from('users')
|
||||
->where('id_roles', $role_id)
|
||||
->group_start()
|
||||
->like('first_name', $keyword)
|
||||
->or_like('last_name', $keyword)
|
||||
->or_like('email', $keyword)
|
||||
|
@ -509,6 +510,7 @@ class Admins_model extends EA_Model {
|
|||
->or_like('state', $keyword)
|
||||
->or_like('zip_code', $keyword)
|
||||
->or_like('notes', $keyword)
|
||||
->group_end()
|
||||
->limit($limit)
|
||||
->offset($offset)
|
||||
->order_by($order_by)
|
||||
|
|
|
@ -28,6 +28,22 @@ class Appointments_model extends EA_Model {
|
|||
'id_services' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'book' => 'book_datetime',
|
||||
'start' => 'start_datetime',
|
||||
'end' => 'end_datetime',
|
||||
'location' => 'location',
|
||||
'notes' => 'notes',
|
||||
'hash' => 'hash',
|
||||
'providerId' => 'id_users_provider',
|
||||
'googleCalendarId' => 'id_google_calendar',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Save (insert or update) an appointment.
|
||||
*
|
||||
|
@ -179,8 +195,6 @@ class Appointments_model extends EA_Model {
|
|||
*/
|
||||
protected function update(array $appointment): int
|
||||
{
|
||||
$this->db->where('id', $appointment['id']);
|
||||
|
||||
if ( ! $this->db->update('appointments', $appointment, ['id' => $appointment['id']]))
|
||||
{
|
||||
throw new RuntimeException('Could not update appointment record.');
|
||||
|
@ -292,7 +306,7 @@ class Appointments_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
$appointments = $this->db->get('appointments', $limit, $offset)->result_array();
|
||||
$appointments = $this->db->get_where('appointments', ['is_unavailable' => FALSE], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($appointments as &$appointment)
|
||||
{
|
||||
|
@ -302,56 +316,6 @@ class Appointments_model extends EA_Model {
|
|||
return $appointments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save (insert or update) an unavailable.
|
||||
*
|
||||
* @param array $unavailable Associative array with the unavailable data.
|
||||
*
|
||||
* @return int Returns the unavailable ID.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function save_unavailable(array $unavailable): int
|
||||
{
|
||||
// Make sure the start date time is before the end date time.
|
||||
$start = strtotime($unavailable['start_datetime']);
|
||||
|
||||
$end = strtotime($unavailable['end_datetime']);
|
||||
|
||||
if ($start > $end)
|
||||
{
|
||||
throw new InvalidArgumentException('Unavailable period start date time must be before the end date time.');
|
||||
}
|
||||
|
||||
// Make sure the provider ID really exists in the database.
|
||||
$role = $this->db->get_where('roles', ['slug' => DB_SLUG_PROVIDER])->row_array();
|
||||
|
||||
$count = $this->db->get_where('users', [
|
||||
'id' => $unavailable['id_users_provider'],
|
||||
'id_roles' => $role['id'],
|
||||
])->num_rows();
|
||||
|
||||
if ( ! $count)
|
||||
{
|
||||
throw new InvalidArgumentException('Provider id was not found in database.');
|
||||
}
|
||||
|
||||
if (empty($unavailable['id']))
|
||||
{
|
||||
$unavailable['book_datetime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$unavailable['is_unavailable'] = TRUE;
|
||||
|
||||
$this->db->insert('appointments', $unavailable);
|
||||
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->db->update('appointments', $unavailable, ['id' => $unavailable['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the Google Calendar event IDs from appointment records.
|
||||
*
|
||||
|
@ -472,6 +436,8 @@ class Appointments_model extends EA_Model {
|
|||
->join('services', 'services.id = appointments.id_services', 'left')
|
||||
->join('users AS providers', 'providers.id = appointments.id_users_provider', 'inner')
|
||||
->join('users AS customers', 'customers.id = appointment.id_users_customer', 'left')
|
||||
->where('is_unavailable', FALSE)
|
||||
->group_start()
|
||||
->like('appointments.start_datetime', $keyword)
|
||||
->or_like('appointments.end_datetime', $keyword)
|
||||
->or_like('appointments.location', $keyword)
|
||||
|
@ -487,6 +453,7 @@ class Appointments_model extends EA_Model {
|
|||
->or_like('customers.last_name', $keyword)
|
||||
->or_like('customers.email', $keyword)
|
||||
->or_like('customers.phone_number', $keyword)
|
||||
->group_end()
|
||||
->limit($limit)
|
||||
->offset($offset)
|
||||
->order_by($order_by)
|
||||
|
|
|
@ -27,6 +27,24 @@ class Customers_model extends EA_Model {
|
|||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'firstName' => 'first_name',
|
||||
'lastName' => 'last_name',
|
||||
'email' => 'email',
|
||||
'phone' => 'phone_number',
|
||||
'address' => 'address',
|
||||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'zip' => 'zip_code',
|
||||
'timezone' => 'timezone',
|
||||
'language' => 'language',
|
||||
'notes' => 'notes',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a customer.
|
||||
*
|
||||
|
@ -380,6 +398,7 @@ class Customers_model extends EA_Model {
|
|||
->select()
|
||||
->from('users')
|
||||
->where('id_roles', $role_id)
|
||||
->group_start()
|
||||
->like('first_name', $keyword)
|
||||
->or_like('last_name', $keyword)
|
||||
->or_like('email', $keyword)
|
||||
|
@ -390,6 +409,7 @@ class Customers_model extends EA_Model {
|
|||
->or_like('state', $keyword)
|
||||
->or_like('zip_code', $keyword)
|
||||
->or_like('notes', $keyword)
|
||||
->group_end()
|
||||
->limit($limit)
|
||||
->offset($offset)
|
||||
->order_by($order_by)
|
||||
|
|
|
@ -27,6 +27,25 @@ class Providers_model extends EA_Model {
|
|||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'firstName' => 'first_name',
|
||||
'lastName' => 'last_name',
|
||||
'email' => 'email',
|
||||
'mobile' => 'mobile_number',
|
||||
'phone' => 'phone_number',
|
||||
'address' => 'address',
|
||||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'zip' => 'zip_code',
|
||||
'timezone' => 'timezone',
|
||||
'language' => 'language',
|
||||
'notes' => 'notes',
|
||||
'roleId' => 'id_roles',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a provider.
|
||||
|
@ -89,11 +108,7 @@ class Providers_model extends EA_Model {
|
|||
}
|
||||
|
||||
// Validate provider services.
|
||||
if (empty($provider['services']) || ! is_array($provider['services']))
|
||||
{
|
||||
throw new InvalidArgumentException('The provided provider services are invalid: ' . print_r($provider, TRUE));
|
||||
}
|
||||
else
|
||||
if ( ! empty($provider['services']))
|
||||
{
|
||||
// Make sure the provided service entries are numeric values.
|
||||
foreach ($provider['services'] as $service_id)
|
||||
|
@ -464,9 +479,9 @@ class Providers_model extends EA_Model {
|
|||
*
|
||||
* @param int $provider_id Provider ID.
|
||||
* @param string $name Setting name.
|
||||
* @param string|null $value Setting value.
|
||||
* @param mixed $value Setting value.
|
||||
*/
|
||||
public function set_setting(int $provider_id, string $name, string $value = NULL)
|
||||
public function set_setting(int $provider_id, string $name, $value = NULL)
|
||||
{
|
||||
if ( ! $this->db->update('user_settings', [$name => $value], ['id_users' => $provider_id]))
|
||||
{
|
||||
|
@ -665,6 +680,7 @@ class Providers_model extends EA_Model {
|
|||
->select()
|
||||
->from('users')
|
||||
->where('id_roles', $role_id)
|
||||
->group_start()
|
||||
->like('first_name', $keyword)
|
||||
->or_like('last_name', $keyword)
|
||||
->or_like('email', $keyword)
|
||||
|
@ -675,6 +691,7 @@ class Providers_model extends EA_Model {
|
|||
->or_like('state', $keyword)
|
||||
->or_like('zip_code', $keyword)
|
||||
->or_like('notes', $keyword)
|
||||
->group_end()
|
||||
->limit($limit)
|
||||
->offset($offset)
|
||||
->order_by($order_by)
|
||||
|
|
|
@ -27,6 +27,26 @@ class Secretaries_model extends EA_Model {
|
|||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'firstName' => 'first_name',
|
||||
'lastName' => 'last_name',
|
||||
'email' => 'email',
|
||||
'mobile' => 'mobile_number',
|
||||
'phone' => 'phone_number',
|
||||
'address' => 'address',
|
||||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'zip' => 'zip_code',
|
||||
'timezone' => 'timezone',
|
||||
'language' => 'language',
|
||||
'notes' => 'notes',
|
||||
'roleId' => 'id_roles',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a secretary.
|
||||
*
|
||||
|
@ -88,11 +108,7 @@ class Secretaries_model extends EA_Model {
|
|||
}
|
||||
|
||||
// Validate secretary providers.
|
||||
if (empty($secretary['providers']) || ! is_array($secretary['providers']))
|
||||
{
|
||||
throw new InvalidArgumentException('The provided secretary providers are invalid: ' . print_r($secretary, TRUE));
|
||||
}
|
||||
else
|
||||
if ( ! empty($secretary['providers']))
|
||||
{
|
||||
// Make sure the provided provider entries are numeric values.
|
||||
foreach ($secretary['providers'] as $secretary_id)
|
||||
|
@ -529,6 +545,7 @@ class Secretaries_model extends EA_Model {
|
|||
->select()
|
||||
->from('users')
|
||||
->where('id_roles', $role_id)
|
||||
->group_start()
|
||||
->like('first_name', $keyword)
|
||||
->or_like('last_name', $keyword)
|
||||
->or_like('email', $keyword)
|
||||
|
@ -539,6 +556,7 @@ class Secretaries_model extends EA_Model {
|
|||
->or_like('state', $keyword)
|
||||
->or_like('zip_code', $keyword)
|
||||
->or_like('notes', $keyword)
|
||||
->group_end()
|
||||
->limit($limit)
|
||||
->offset($offset)
|
||||
->order_by($order_by)
|
||||
|
|
|
@ -26,6 +26,15 @@ class Service_categories_model extends EA_Model {
|
|||
'id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
'description' => 'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a service category.
|
||||
*
|
||||
|
|
|
@ -29,6 +29,22 @@ class Services_model extends EA_Model {
|
|||
'id_service_categories' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
'duration' => 'duration',
|
||||
'price' => 'price',
|
||||
'currency' => 'currency',
|
||||
'description' => 'description',
|
||||
'location' => 'location',
|
||||
'availabilitiesType' => 'availabilities_type',
|
||||
'attendantsNumber' => 'attendants_number',
|
||||
'categoryId' => 'id_service_categories',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a service.
|
||||
*
|
||||
|
|
|
@ -26,6 +26,14 @@ class Settings_model extends EA_Model {
|
|||
'id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'name' => 'name',
|
||||
'value' => 'value',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a setting.
|
||||
*
|
||||
|
|
|
@ -27,6 +27,26 @@ class Users_model extends EA_Model {
|
|||
'id_roles' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $api_resource = [
|
||||
'id' => 'id',
|
||||
'firstName' => 'first_name',
|
||||
'lastName' => 'last_name',
|
||||
'email' => 'email',
|
||||
'mobile' => 'mobile_number',
|
||||
'phone' => 'phone_number',
|
||||
'address' => 'address',
|
||||
'city' => 'city',
|
||||
'state' => 'state',
|
||||
'zip' => 'zip_code',
|
||||
'timezone' => 'timezone',
|
||||
'language' => 'language',
|
||||
'notes' => 'notes',
|
||||
'roleId' => 'id_roles',
|
||||
];
|
||||
|
||||
/**
|
||||
* Save (insert or update) a user.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue