mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-24 08:53:05 +03:00
Add support for soft appointment, service, customer and provider removals (#1115).
This commit is contained in:
parent
4c0793129d
commit
2c203ae1aa
13 changed files with 487 additions and 139 deletions
74
application/migrations/037_add_timestamp_columns.php
Normal file
74
application/migrations/037_add_timestamp_columns.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
class Migration_Add_timestamp_columns extends EA_Migration {
|
||||
protected $tables = [
|
||||
'appointments',
|
||||
'categories',
|
||||
'consents',
|
||||
'roles',
|
||||
'services',
|
||||
'settings',
|
||||
'users'
|
||||
];
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $columns = [
|
||||
'delete_datetime',
|
||||
'update_datetime',
|
||||
'create_datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Upgrade method.
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
foreach ($this->tables as $table)
|
||||
{
|
||||
foreach ($this->columns as $column)
|
||||
{
|
||||
if ( ! $this->db->field_exists($column, $table))
|
||||
{
|
||||
$fields = [
|
||||
$column => [
|
||||
'type' => 'DATETIME',
|
||||
'null' => TRUE,
|
||||
'after' => 'id',
|
||||
]
|
||||
];
|
||||
|
||||
$this->dbforge->add_column($table, $fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downgrade method.
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
foreach ($this->tables as $table)
|
||||
{
|
||||
foreach ($this->columns as $column)
|
||||
{
|
||||
if ($this->db->field_exists($column, $table))
|
||||
{
|
||||
$this->dbforge->drop_column($table, $column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -251,23 +251,28 @@ class Admins_model extends EA_Model {
|
|||
* Remove an existing admin from the database.
|
||||
*
|
||||
* @param int $admin_id Admin ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $admin_id)
|
||||
public function delete(int $admin_id, bool $force_delete = FALSE)
|
||||
{
|
||||
$role_id = $this->get_admin_role_id();
|
||||
|
||||
$count = $this->db->get_where('users', ['id_roles' => $role_id])->num_rows();
|
||||
$count = $this->db->get_where('users', ['id_roles' => $role_id, 'delete_datetime !=' => NULL])->num_rows();
|
||||
|
||||
if ($count === 1)
|
||||
{
|
||||
throw new RuntimeException('Record could not be deleted as the app requires at least one admin user.');
|
||||
}
|
||||
|
||||
if ( ! $this->db->delete('users', ['id' => $admin_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete admin.');
|
||||
$this->db->delete('users', ['id' => $admin_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $admin_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,20 +280,26 @@ class Admins_model extends EA_Model {
|
|||
* Get a specific admin from the database.
|
||||
*
|
||||
* @param int $admin_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the admin data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $admin_id): array
|
||||
public function find(int $admin_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('users', ['id' => $admin_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided admin ID was not found in the database: ' . $admin_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$admin = $this->db->get_where('users', ['id' => $admin_id])->row_array();
|
||||
|
||||
if ( ! $admin)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided admin ID was not found in the database: ' . $admin_id);
|
||||
}
|
||||
|
||||
$this->cast($admin);
|
||||
|
||||
$admin['settings'] = $this->db->get_where('user_settings', ['id_users' => $admin_id])->row_array();
|
||||
|
@ -352,10 +363,11 @@ class Admins_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of admins.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_admin_role_id();
|
||||
|
||||
|
@ -369,6 +381,11 @@ class Admins_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$admins = $this->db->get_where('users', ['id_roles' => $role_id], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($admins as &$admin)
|
||||
|
@ -487,13 +504,19 @@ class Admins_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of admins.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_admin_role_id();
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$admins = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -208,14 +208,19 @@ class Appointments_model extends EA_Model {
|
|||
* Remove an existing appointment from the database.
|
||||
*
|
||||
* @param int $appointment_id Appointment ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $appointment_id)
|
||||
public function delete(int $appointment_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('appointments', ['id' => $appointment_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete appointment.');
|
||||
$this->db->delete('appointments', ['id' => $appointment_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('appointments', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $appointment_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,20 +228,26 @@ class Appointments_model extends EA_Model {
|
|||
* Get a specific appointment from the database.
|
||||
*
|
||||
* @param int $appointment_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the appointment data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $appointment_id): array
|
||||
public function find(int $appointment_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('appointments', ['id' => $appointment_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided appointment ID was not found in the database: ' . $appointment_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$appointment = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array();
|
||||
|
||||
if ( ! $appointment)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided appointment ID was not found in the database: ' . $appointment_id);
|
||||
}
|
||||
|
||||
$this->cast($appointment);
|
||||
|
||||
return $appointment;
|
||||
|
@ -292,10 +303,11 @@ class Appointments_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of appointments.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -307,6 +319,11 @@ class Appointments_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$appointments = $this->db->get_where('appointments', ['is_unavailability' => FALSE], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($appointments as &$appointment)
|
||||
|
@ -425,11 +442,17 @@ class Appointments_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of appointments.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('appointments.delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$appointments = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -129,14 +129,19 @@ class Categories_model extends EA_Model {
|
|||
* Remove an existing category from the database.
|
||||
*
|
||||
* @param int $category_id Category ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $category_id)
|
||||
public function delete(int $category_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('categories', ['id' => $category_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete service categories.');
|
||||
$this->db->delete('categories', ['id' => $category_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('categories', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $category_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,20 +149,26 @@ class Categories_model extends EA_Model {
|
|||
* Get a specific category from the database.
|
||||
*
|
||||
* @param int $category_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the category data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $category_id): array
|
||||
public function find(int $category_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('categories', ['id' => $category_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $category_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$category = $this->db->get_where('categories', ['id' => $category_id])->row_array();
|
||||
|
||||
if ( ! $category)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $category_id);
|
||||
}
|
||||
|
||||
$this->cast($category);
|
||||
|
||||
return $category;
|
||||
|
@ -213,10 +224,11 @@ class Categories_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of service categories.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -228,6 +240,11 @@ class Categories_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$categories = $this->db->get('categories', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($categories as $category)
|
||||
|
@ -255,11 +272,17 @@ class Categories_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of service categories.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$categories = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -25,7 +25,7 @@ class Consents_model extends EA_Model {
|
|||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Save (insert or update) a consent.
|
||||
*
|
||||
|
@ -118,14 +118,19 @@ class Consents_model extends EA_Model {
|
|||
* Remove an existing consent from the database.
|
||||
*
|
||||
* @param int $consent_id Consent ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $consent_id)
|
||||
public function delete(int $consent_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('consents', ['id' => $consent_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete consent.');
|
||||
$this->db->delete('consents', ['id' => $consent_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->db->update('consents', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $consent_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,22 +138,26 @@ class Consents_model extends EA_Model {
|
|||
* Get a specific consent from the database.
|
||||
*
|
||||
* @param int $consent_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the consent data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $consent_id): array
|
||||
public function find(int $consent_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('consents', ['id' => $consent_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$consent = $this->db->get_where('consents', ['id' => $consent_id])->row_array();
|
||||
|
||||
if ( ! $consent)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided consent ID was not found in the database: ' . $consent_id);
|
||||
}
|
||||
|
||||
$consent = $this->db->get_where('consents', ['id' => $consent_id])->row_array();
|
||||
|
||||
$this->cast($consent);
|
||||
|
||||
$this->cast($consent);
|
||||
|
||||
return $consent;
|
||||
}
|
||||
|
||||
|
@ -184,7 +193,7 @@ class Consents_model extends EA_Model {
|
|||
|
||||
// Check if the required field is part of the consent data.
|
||||
$consent = $query->row_array();
|
||||
|
||||
|
||||
$this->cast($consent);
|
||||
|
||||
if ( ! array_key_exists($field, $consent))
|
||||
|
@ -202,10 +211,11 @@ class Consents_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of consents.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -217,14 +227,19 @@ class Consents_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
$consents = $this->db->get('consents', $limit, $offset)->result_array();
|
||||
|
||||
foreach($consents as &$consent)
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->cast($consent);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
return $consents;
|
||||
|
||||
$consents = $this->db->get('consents', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($consents as &$consent)
|
||||
{
|
||||
$this->cast($consent);
|
||||
}
|
||||
|
||||
return $consents;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,11 +259,17 @@ class Consents_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of consents.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$consents = $this
|
||||
->db
|
||||
->select()
|
||||
|
@ -263,7 +284,7 @@ class Consents_model extends EA_Model {
|
|||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach($consents as &$consent)
|
||||
foreach ($consents as &$consent)
|
||||
{
|
||||
$this->cast($consent);
|
||||
}
|
||||
|
|
|
@ -190,14 +190,19 @@ class Customers_model extends EA_Model {
|
|||
* Remove an existing customer from the database.
|
||||
*
|
||||
* @param int $customer_id Customer ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $customer_id)
|
||||
public function delete(int $customer_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('users', ['id' => $customer_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete customer.');
|
||||
$this->db->delete('users', ['id' => $customer_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $customer_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,20 +210,24 @@ class Customers_model extends EA_Model {
|
|||
* Get a specific customer from the database.
|
||||
*
|
||||
* @param int $customer_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the customer data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $customer_id): array
|
||||
public function find(int $customer_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('users', ['id' => $customer_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided customer ID was not found in the database: ' . $customer_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$customer = $this->db->get_where('users', ['id' => $customer_id])->row_array();
|
||||
|
||||
if ( ! $customer)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided customer ID was not found in the database: ' . $customer_id);
|
||||
}
|
||||
|
||||
$this->cast($customer);
|
||||
|
||||
return $customer;
|
||||
|
@ -274,10 +283,11 @@ class Customers_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of customers.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_customer_role_id();
|
||||
|
||||
|
@ -291,6 +301,11 @@ class Customers_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$customers = $this->db->get_where('users', ['id_roles' => $role_id], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($customers as &$customer)
|
||||
|
@ -400,13 +415,19 @@ class Customers_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of customers.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_customer_role_id();
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$customers = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -273,14 +273,19 @@ class Providers_model extends EA_Model {
|
|||
* Remove an existing provider from the database.
|
||||
*
|
||||
* @param int $provider_id Provider ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $provider_id)
|
||||
public function delete(int $provider_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('users', ['id' => $provider_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete provider.');
|
||||
$this->db->delete('users', ['id' => $provider_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $provider_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,20 +293,26 @@ class Providers_model extends EA_Model {
|
|||
* Get a specific provider from the database.
|
||||
*
|
||||
* @param int $provider_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the provider data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $provider_id): array
|
||||
public function find(int $provider_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('users', ['id' => $provider_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$provider = $this->db->get_where('users', ['id' => $provider_id])->row_array();
|
||||
|
||||
if ( ! $provider)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided provider ID was not found in the database: ' . $provider_id);
|
||||
}
|
||||
|
||||
$provider = $this->db->get_where('users', ['id' => $provider_id])->row_array();
|
||||
|
||||
$this->cast($provider);
|
||||
|
||||
$provider['settings'] = $this->db->get_where('user_settings', ['id_users' => $provider_id])->row_array();
|
||||
|
@ -370,10 +381,11 @@ class Providers_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of providers.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_provider_role_id();
|
||||
|
||||
|
@ -387,6 +399,11 @@ class Providers_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$providers = $this->db->get_where('users', ['id_roles' => $role_id], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($providers as &$provider)
|
||||
|
@ -628,6 +645,7 @@ class Providers_model extends EA_Model {
|
|||
->from('users')
|
||||
->join('roles', 'roles.id = users.id_roles', 'inner')
|
||||
->where('roles.slug', DB_SLUG_PROVIDER)
|
||||
->where('users.delete_datetime IS NULL')
|
||||
->order_by('first_name ASC, last_name ASC, email ASC')
|
||||
->get()
|
||||
->result_array();
|
||||
|
@ -675,13 +693,19 @@ class Providers_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of providers.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_provider_role_id();
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$providers = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -127,14 +127,19 @@ class Roles_model extends EA_Model {
|
|||
* Remove an existing role from the database.
|
||||
*
|
||||
* @param int $role_id Role ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $role_id)
|
||||
public function delete(int $role_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('roles', ['id' => $role_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete role.');
|
||||
$this->db->delete('roles', ['id' => $role_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('roles', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $role_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,23 +147,29 @@ class Roles_model extends EA_Model {
|
|||
* Get a specific role from the database.
|
||||
*
|
||||
* @param int $role_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the role data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $role_id): array
|
||||
public function find(int $role_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('roles', ['id' => $role_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$role = $this->db->get_where('roles', ['id' => $role_id])->row_array();
|
||||
|
||||
if ( ! $role)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided role ID was not found in the database: ' . $role_id);
|
||||
}
|
||||
|
||||
$role = $this->db->get_where('roles', ['id' => $role_id])->row_array();
|
||||
|
||||
$this->cast($role);
|
||||
|
||||
return $role;
|
||||
$this->cast($role);
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,7 +204,7 @@ class Roles_model extends EA_Model {
|
|||
|
||||
// Check if the required field is part of the role data.
|
||||
$role = $query->row_array();
|
||||
|
||||
|
||||
$this->cast($role);
|
||||
|
||||
if ( ! array_key_exists($field, $role))
|
||||
|
@ -211,10 +222,11 @@ class Roles_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of roles.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -226,13 +238,18 @@ class Roles_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
$roles = $this->db->get('roles', $limit, $offset)->result_array();
|
||||
|
||||
foreach($roles as &$role)
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->cast($role);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
|
||||
$roles = $this->db->get('roles', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($roles as &$role)
|
||||
{
|
||||
$this->cast($role);
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
|
@ -255,7 +272,7 @@ class Roles_model extends EA_Model {
|
|||
public function get_permissions_by_slug(string $slug): array
|
||||
{
|
||||
$role = $this->db->get_where('roles', ['slug' => $slug])->row_array();
|
||||
|
||||
|
||||
$this->cast($role);
|
||||
|
||||
unset(
|
||||
|
@ -321,11 +338,17 @@ class Roles_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of roles.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$roles = $this
|
||||
->db
|
||||
->select()
|
||||
|
@ -338,7 +361,7 @@ class Roles_model extends EA_Model {
|
|||
->get()
|
||||
->result_array();
|
||||
|
||||
foreach($roles as &$role)
|
||||
foreach ($roles as &$role)
|
||||
{
|
||||
$this->cast($role);
|
||||
}
|
||||
|
|
|
@ -272,14 +272,19 @@ class Secretaries_model extends EA_Model {
|
|||
* Remove an existing secretary from the database.
|
||||
*
|
||||
* @param int $secretary_id Provider ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $secretary_id)
|
||||
public function delete(int $secretary_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('users', ['id' => $secretary_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete secretary.');
|
||||
$this->db->delete('users', ['id' => $secretary_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $secretary_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,20 +292,26 @@ class Secretaries_model extends EA_Model {
|
|||
* Get a specific secretary from the database.
|
||||
*
|
||||
* @param int $secretary_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the secretary data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $secretary_id): array
|
||||
public function find(int $secretary_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('users', ['id' => $secretary_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided secretary ID was not found in the database: ' . $secretary_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$secretary = $this->db->get_where('users', ['id' => $secretary_id])->row_array();
|
||||
|
||||
if ( ! $secretary)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided secretary ID was not found in the database: ' . $secretary_id);
|
||||
}
|
||||
|
||||
$secretary['settings'] = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->row_array();
|
||||
|
||||
unset(
|
||||
|
@ -369,7 +380,8 @@ class Secretaries_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of secretaries.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL)
|
||||
|
@ -386,6 +398,11 @@ class Secretaries_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$secretaries = $this->db->get_where('users', ['id_roles' => $role_id], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($secretaries as &$secretary)
|
||||
|
@ -533,13 +550,19 @@ class Secretaries_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of secretaries.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
$role_id = $this->get_secretary_role_id();
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$secretaries = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -185,14 +185,19 @@ class Services_model extends EA_Model {
|
|||
* Remove an existing service from the database.
|
||||
*
|
||||
* @param int $service_id Service ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $service_id)
|
||||
public function delete(int $service_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('services', ['id' => $service_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete service.');
|
||||
$this->db->delete('services', ['id' => $service_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('services', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $service_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,20 +205,26 @@ class Services_model extends EA_Model {
|
|||
* Get a specific service from the database.
|
||||
*
|
||||
* @param int $service_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the service data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $service_id): array
|
||||
public function find(int $service_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('services', ['id' => $service_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
|
||||
|
||||
if ( ! $service)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided service ID was not found in the database: ' . $service_id);
|
||||
}
|
||||
|
||||
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
|
||||
|
||||
$this->cast($service);
|
||||
|
||||
return $service;
|
||||
|
@ -269,10 +280,11 @@ class Services_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of services.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -284,6 +296,11 @@ class Services_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$services = $this->db->get('services', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($services as &$service)
|
||||
|
@ -315,6 +332,7 @@ class Services_model extends EA_Model {
|
|||
->from('services')
|
||||
->join('services_providers', 'services_providers.id_services = services.id', 'inner')
|
||||
->join('categories', 'categories.id = services.id_categories', 'left')
|
||||
->where('services.delete_datetime IS NULL')
|
||||
->order_by('name ASC')
|
||||
->get()
|
||||
->result_array();
|
||||
|
@ -344,11 +362,17 @@ class Services_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of services.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$services = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -126,16 +126,21 @@ class Settings_model extends EA_Model {
|
|||
|
||||
/**
|
||||
* Remove an existing setting from the database.
|
||||
*
|
||||
|
||||
* @param int $setting_id Setting ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $setting_id)
|
||||
public function delete(int $setting_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('settings', ['id' => $setting_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete setting.');
|
||||
$this->db->delete('settings', ['id' => $setting_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('settings', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $setting_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,20 +148,26 @@ class Settings_model extends EA_Model {
|
|||
* Get a specific setting from the database.
|
||||
*
|
||||
* @param int $setting_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the setting data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $setting_id): array
|
||||
public function find(int $setting_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('settings', ['id' => $setting_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$setting = $this->db->get_where('settings', ['id' => $setting_id])->row_array();
|
||||
|
||||
if ( ! $setting)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided setting ID was not found in the database: ' . $setting_id);
|
||||
}
|
||||
|
||||
$setting = $this->db->get_where('settings', ['id' => $setting_id])->row_array();
|
||||
|
||||
$this->cast($setting);
|
||||
|
||||
return $setting;
|
||||
|
@ -212,10 +223,11 @@ class Settings_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of settings.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -227,6 +239,11 @@ class Settings_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$settings = $this->db->get('settings', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($settings as &$setting)
|
||||
|
@ -254,11 +271,17 @@ class Settings_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of settings.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$settings = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
|
@ -163,14 +163,19 @@ class Unavailabilities_model extends EA_Model {
|
|||
* Remove an existing unavailability from the database.
|
||||
*
|
||||
* @param int $unavailability_id Unavailability ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $unavailability_id)
|
||||
public function delete(int $unavailability_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('users', ['id' => $unavailability_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete unavailability.');
|
||||
$this->db->delete('appointments', ['id' => $unavailability_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('appointments', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $unavailability_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,20 +183,26 @@ class Unavailabilities_model extends EA_Model {
|
|||
* Get a specific unavailability from the database.
|
||||
*
|
||||
* @param int $unavailability_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the unavailability data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $unavailability_id): array
|
||||
public function find(int $unavailability_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('appointments', ['id' => $unavailability_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided unavailability ID was not found in the database: ' . $unavailability_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$unavailability = $this->db->get_where('appointments', ['id' => $unavailability_id])->row_array();
|
||||
|
||||
if ( ! $unavailability)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided unavailability ID was not found in the database: ' . $unavailability_id);
|
||||
}
|
||||
|
||||
$this->cast($unavailability);
|
||||
|
||||
return $unavailability;
|
||||
|
@ -247,10 +258,11 @@ class Unavailabilities_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of unavailabilities.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -262,6 +274,11 @@ class Unavailabilities_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$unavailabilities = $this->db->get_where('appointments', ['is_unavailability' => TRUE], $limit, $offset)->result_array();
|
||||
|
||||
foreach ($unavailabilities as &$unavailability)
|
||||
|
@ -289,11 +306,17 @@ class Unavailabilities_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of unavailabilities.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('appointments.delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$unavailabilities = $this
|
||||
->db
|
||||
->select()
|
||||
|
@ -352,7 +375,7 @@ class Unavailabilities_model extends EA_Model {
|
|||
])
|
||||
->row_array();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw new InvalidArgumentException('The requested unavailability relation is not supported: ' . $resource);
|
||||
}
|
||||
|
|
|
@ -170,14 +170,19 @@ class Users_model extends EA_Model {
|
|||
* Remove an existing user from the database.
|
||||
*
|
||||
* @param int $user_id User ID.
|
||||
* @param bool $force_delete Override soft delete.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function delete(int $user_id)
|
||||
public function delete(int $user_id, bool $force_delete = FALSE)
|
||||
{
|
||||
if ( ! $this->db->delete('users', ['id' => $user_id]))
|
||||
if ($force_delete)
|
||||
{
|
||||
throw new RuntimeException('Could not delete user.');
|
||||
$this->db->delete('users', ['id' => $user_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $user_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,20 +190,26 @@ class Users_model extends EA_Model {
|
|||
* Get a specific user from the database.
|
||||
*
|
||||
* @param int $user_id The ID of the record to be returned.
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array with the user data.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function find(int $user_id): array
|
||||
public function find(int $user_id, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $this->db->get_where('users', ['id' => $user_id])->num_rows())
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided user ID was not found in the database: ' . $user_id);
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$user = $this->db->get_where('users', ['id' => $user_id])->row_array();
|
||||
|
||||
if ( ! $user)
|
||||
{
|
||||
throw new InvalidArgumentException('The provided user ID was not found in the database: ' . $user_id);
|
||||
}
|
||||
|
||||
$this->cast($user);
|
||||
|
||||
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user_id])->row_array();
|
||||
|
@ -258,10 +269,11 @@ class Users_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of users.
|
||||
*/
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
||||
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ($where !== NULL)
|
||||
{
|
||||
|
@ -273,6 +285,11 @@ class Users_model extends EA_Model {
|
|||
$this->db->order_by($order_by);
|
||||
}
|
||||
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$users = $this->db->get('users', $limit, $offset)->result_array();
|
||||
|
||||
foreach ($users as &$user)
|
||||
|
@ -372,11 +389,17 @@ class Users_model extends EA_Model {
|
|||
* @param int|null $limit Record limit.
|
||||
* @param int|null $offset Record offset.
|
||||
* @param string|null $order_by Order by.
|
||||
*
|
||||
* @param bool $with_trashed
|
||||
*
|
||||
* @return array Returns an array of settings.
|
||||
*/
|
||||
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, bool $with_trashed = FALSE): array
|
||||
{
|
||||
if ( ! $with_trashed)
|
||||
{
|
||||
$this->db->where('delete_datetime IS NULL');
|
||||
}
|
||||
|
||||
$users = $this
|
||||
->db
|
||||
->select()
|
||||
|
|
Loading…
Reference in a new issue