Drop support for soft deletes in order to reduce the code complexity and data usage

This commit is contained in:
Alex Tselegidis 2023-10-19 16:25:45 +02:00
parent 1710d46b6d
commit cf19a90311
16 changed files with 198 additions and 474 deletions

View file

@ -157,6 +157,6 @@ class Accounts {
*/
public function does_account_exist(int $user_id): bool
{
return $this->CI->users_model->query()->where(['id' => $user_id, 'delete_datetime' => NULL])->get()->num_rows() > 0;
return $this->CI->users_model->query()->where(['id' => $user_id])->get()->num_rows() > 0;
}
}

View file

@ -12,6 +12,9 @@
* ---------------------------------------------------------------------------- */
class Migration_Add_timestamp_columns extends EA_Migration {
/**
* @var string[]
*/
protected $tables = [
'appointments',
'categories',
@ -21,6 +24,7 @@ class Migration_Add_timestamp_columns extends EA_Migration {
'settings',
'users'
];
/**
* @var string[]
*/

View file

@ -0,0 +1,64 @@
<?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_Drop_delete_datetime_column_from_all_tables extends EA_Migration {
/**
* @var string[]
*/
protected $tables = [
'appointments',
'categories',
'consents',
'roles',
'services',
'settings',
'users',
'webhooks'
];
/**
* Upgrade method.
*/
public function up()
{
foreach ($this->tables as $table)
{
if ($this->db->field_exists('delete_datetime', $table))
{
$this->dbforge->drop_column($table, 'delete_datetime');
}
}
}
/**
* Downgrade method.
*/
public function down()
{
foreach ($this->tables as $table)
{
if ( ! $this->db->field_exists('delete_datetime', $table))
{
$fields = [
'delete_datetime' => [
'type' => 'DATETIME',
'null' => TRUE,
'after' => 'update_datetime',
]
];
$this->dbforge->add_column($table, $fields);
}
}
}
}

View file

@ -154,7 +154,6 @@ class Admins_model extends EA_Model {
->where('roles.slug', DB_SLUG_ADMIN)
->where('users.email', $admin['email'])
->where('users.id !=', $admin_id)
->where('users.delete_datetime')
->get()
->num_rows();
@ -183,7 +182,7 @@ class Admins_model extends EA_Model {
->db
->from('users')
->join('user_settings', 'user_settings.id_users = users.id', 'inner')
->where(['username' => $username, 'delete_datetime' => NULL])
->where(['username' => $username])
->get()
->num_rows() === 0;
}
@ -272,48 +271,34 @@ 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, bool $force_delete = FALSE)
public function delete(int $admin_id): void
{
$role_id = $this->get_admin_role_id();
$count = $this->db->get_where('users', ['id_roles' => $role_id, 'delete_datetime' => NULL])->num_rows();
$count = $this->db->get_where('users', ['id_roles' => $role_id])->num_rows();
if ($count <= 1)
{
throw new RuntimeException('Record could not be deleted as the app requires at least one admin user.');
}
if ($force_delete)
{
$this->db->delete('users', ['id' => $admin_id]);
}
else
{
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $admin_id]);
}
$this->db->delete('users', ['id' => $admin_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $admin_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$admin = $this->db->get_where('users', ['id' => $admin_id])->row_array();
if ( ! $admin)
@ -384,11 +369,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_admin_role_id();
@ -402,11 +386,6 @@ 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)
@ -525,19 +504,13 @@ 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, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_admin_role_id();
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$admins = $this
->db
->select()

View file

@ -219,39 +219,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $appointment_id): void
{
if ($force_delete)
{
$this->db->delete('appointments', ['id' => $appointment_id]);
}
else
{
$this->db->update('appointments', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $appointment_id]);
}
$this->db->delete('appointments', ['id' => $appointment_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $appointment_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$appointment = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array();
if ( ! $appointment)
@ -314,11 +300,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -330,11 +315,6 @@ 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)
@ -453,17 +433,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('appointments.delete_datetime IS NULL');
}
$appointments = $this
->db
->select('appointments.*')

View file

@ -134,39 +134,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $category_id): void
{
if ($force_delete)
{
$this->db->delete('categories', ['id' => $category_id]);
}
else
{
$this->db->update('categories', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $category_id]);
}
$this->db->delete('categories', ['id' => $category_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $category_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$category = $this->db->get_where('categories', ['id' => $category_id])->row_array();
if ( ! $category)
@ -229,11 +215,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -245,11 +230,6 @@ 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)
@ -277,17 +257,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$categories = $this
->db
->select()

View file

@ -115,37 +115,23 @@ 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, bool $force_delete = FALSE)
public function delete(int $consent_id): void
{
if ($force_delete)
{
$this->db->delete('consents', ['id' => $consent_id]);
}
else
{
$this->db->update('consents', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $consent_id]);
}
$this->db->delete('consents', ['id' => $consent_id]);
}
/**
* 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.
*/
public function find(int $consent_id, bool $with_trashed = FALSE): array
public function find(int $consent_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$consent = $this->db->get_where('consents', ['id' => $consent_id])->row_array();
if ( ! $consent)
@ -208,11 +194,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -224,10 +209,7 @@ class Consents_model extends EA_Model {
$this->db->order_by($order_by);
}
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$consents = $this->db->get('consents', $limit, $offset)->result_array();
@ -256,17 +238,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$consents = $this
->db
->select()

View file

@ -131,7 +131,6 @@ class Customers_model extends EA_Model {
->select()
->from('users')
->join('roles', 'roles.id = users.id_roles', 'inner')
->where('users.delete_datetime')
->where('roles.slug', DB_SLUG_CUSTOMER)
->where('users.email', $customer['email'])
->where('users.id !=', $customer_id)
@ -193,38 +192,23 @@ 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, bool $force_delete = FALSE)
public function delete(int $customer_id): void
{
if ($force_delete)
{
$this->db->delete('users', ['id' => $customer_id]);
}
else
{
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $customer_id]);
$this->db->update('appointments', ['delete_datetime' => date('Y-m-d H:i:s')], ['id_users_customer' => $customer_id, 'delete_datetime' => NULL]);
}
$this->db->delete('users', ['id' => $customer_id]);
}
/**
* 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.
*/
public function find(int $customer_id, bool $with_trashed = FALSE): array
public function find(int $customer_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$customer = $this->db->get_where('users', ['id' => $customer_id])->row_array();
if ( ! $customer)
@ -287,11 +271,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_customer_role_id();
@ -305,11 +288,6 @@ 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)
@ -359,7 +337,6 @@ class Customers_model extends EA_Model {
->from('users')
->join('roles', 'roles.id = users.id_roles', 'inner')
->where('users.email', $customer['email'])
->where('users.delete_datetime')
->where('roles.slug', DB_SLUG_CUSTOMER)
->get()
->num_rows();
@ -389,7 +366,6 @@ class Customers_model extends EA_Model {
->from('users')
->join('roles', 'roles.id = users.id_roles', 'inner')
->where('users.email', $customer['email'])
->where('users.delete_datetime')
->where('roles.slug', DB_SLUG_CUSTOMER)
->get()
->row_array();
@ -421,19 +397,13 @@ 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, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_customer_role_id();
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$customers = $this
->db
->select()

View file

@ -169,7 +169,6 @@ class Providers_model extends EA_Model {
->where('roles.slug', DB_SLUG_PROVIDER)
->where('users.email', $provider['email'])
->where('users.id !=', $provider_id)
->where('users.delete_datetime')
->get()
->num_rows();
@ -198,7 +197,7 @@ class Providers_model extends EA_Model {
->db
->from('users')
->join('user_settings', 'user_settings.id_users = users.id', 'inner')
->where(['username' => $username, 'delete_datetime' => NULL])
->where(['username' => $username])
->get()
->num_rows() === 0;
}
@ -291,39 +290,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $provider_id): void
{
if ($force_delete)
{
$this->db->delete('users', ['id' => $provider_id]);
}
else
{
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $provider_id]);
}
$this->db->delete('users', ['id' => $provider_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $provider_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$provider = $this->db->get_where('users', ['id' => $provider_id])->row_array();
if ( ! $provider)
@ -403,11 +388,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_provider_role_id();
@ -421,10 +405,6 @@ 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();
@ -610,7 +590,7 @@ class Providers_model extends EA_Model {
// Store the working plan exception.
$working_plan_exceptions = json_decode($provider['settings']['working_plan_exceptions'], TRUE);
if ( is_array($working_plan_exception) && ! isset($working_plan_exception['breaks']))
if (is_array($working_plan_exception) && ! isset($working_plan_exception['breaks']))
{
$working_plan_exception['breaks'] = [];
}
@ -668,7 +648,6 @@ 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();
@ -716,19 +695,13 @@ 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, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_provider_role_id();
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$providers = $this
->db
->select()

View file

@ -132,39 +132,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $role_id): void
{
if ($force_delete)
{
$this->db->delete('roles', ['id' => $role_id]);
}
else
{
$this->db->update('roles', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $role_id]);
}
$this->db->delete('roles', ['id' => $role_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $role_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$role = $this->db->get_where('roles', ['id' => $role_id])->row_array();
if ( ! $role)
@ -227,11 +213,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -243,11 +228,6 @@ class Roles_model extends EA_Model {
$this->db->order_by($order_by);
}
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$roles = $this->db->get('roles', $limit, $offset)->result_array();
foreach ($roles as &$role)
@ -343,17 +323,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$roles = $this
->db
->select()

View file

@ -167,7 +167,6 @@ class Secretaries_model extends EA_Model {
->where('roles.slug', DB_SLUG_SECRETARY)
->where('users.email', $secretary['email'])
->where('users.id !=', $secretary_id)
->where('users.delete_datetime')
->get()
->num_rows();
@ -196,7 +195,7 @@ class Secretaries_model extends EA_Model {
->db
->from('users')
->join('user_settings', 'user_settings.id_users = users.id', 'inner')
->where(['username' => $username, 'delete_datetime' => NULL])
->where(['username' => $username])
->get()
->num_rows() === 0;
}
@ -290,39 +289,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $secretary_id): void
{
if ($force_delete)
{
$this->db->delete('users', ['id' => $secretary_id]);
}
else
{
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $secretary_id]);
}
$this->db->delete('users', ['id' => $secretary_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $secretary_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$secretary = $this->db->get_where('users', ['id' => $secretary_id])->row_array();
if ( ! $secretary)
@ -398,11 +383,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_secretary_role_id();
@ -416,11 +400,6 @@ 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)
@ -568,19 +547,13 @@ 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, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$role_id = $this->get_secretary_role_id();
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$secretaries = $this
->db
->select()

View file

@ -190,39 +190,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $service_id): void
{
if ($force_delete)
{
$this->db->delete('services', ['id' => $service_id]);
}
else
{
$this->db->update('services', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $service_id]);
}
$this->db->delete('services', ['id' => $service_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $service_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
if ( ! $service)
@ -285,11 +271,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -301,11 +286,6 @@ 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)
@ -337,7 +317,6 @@ 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();
@ -367,17 +346,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$services = $this
->db
->select()

View file

@ -131,41 +131,27 @@ 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, bool $force_delete = FALSE)
public function delete(int $setting_id): void
{
if ($force_delete)
{
$this->db->delete('settings', ['id' => $setting_id]);
}
else
{
$this->db->update('settings', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $setting_id]);
}
$this->db->delete('settings', ['id' => $setting_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $setting_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$setting = $this->db->get_where('settings', ['id' => $setting_id])->row_array();
if ( ! $setting)
@ -228,11 +214,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -244,11 +229,6 @@ 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)
@ -276,17 +256,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$settings = $this
->db
->select()

View file

@ -184,39 +184,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $unavailability_id): void
{
if ($force_delete)
{
$this->db->delete('appointments', ['id' => $unavailability_id]);
}
else
{
$this->db->update('appointments', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $unavailability_id]);
}
$this->db->delete('appointments', ['id' => $unavailability_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $unavailability_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$unavailability = $this->db->get_where('appointments', ['id' => $unavailability_id])->row_array();
if ( ! $unavailability)
@ -279,11 +265,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -295,11 +280,6 @@ 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)
@ -327,17 +307,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 search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('appointments.delete_datetime IS NULL');
}
$unavailabilities = $this
->db
->select()

View file

@ -176,39 +176,25 @@ 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, bool $force_delete = FALSE)
public function delete(int $user_id): void
{
if ($force_delete)
{
$this->db->delete('users', ['id' => $user_id]);
}
else
{
$this->db->update('users', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $user_id]);
}
$this->db->delete('users', ['id' => $user_id]);
}
/**
* 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, bool $with_trashed = FALSE): array
public function find(int $user_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$user = $this->db->get_where('users', ['id' => $user_id])->row_array();
if ( ! $user)
@ -279,11 +265,10 @@ 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(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -295,11 +280,6 @@ 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)
@ -399,17 +379,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 settings.
*/
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$users = $this
->db
->select()

View file

@ -133,37 +133,23 @@ class Webhooks_model extends EA_Model {
* Remove an existing webhook from the database.
*
* @param int $webhook_id Webhook ID.
* @param bool $force_delete Override soft delete.
*
* @throws RuntimeException
*/
public function delete(int $webhook_id, bool $force_delete = FALSE)
public function delete(int $webhook_id): void
{
if ($force_delete)
{
$this->db->delete('webhooks', ['id' => $webhook_id]);
}
else
{
$this->db->update('webhooks', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $webhook_id]);
}
$this->db->delete('webhooks', ['id' => $webhook_id]);
}
/**
* Get a specific webhook from the database.
*
* @param int $webhook_id The ID of the record to be returned.
* @param bool $with_trashed
*
* @return array Returns an array with the webhook data.
*/
public function find(int $webhook_id, bool $with_trashed = FALSE): array
public function find(int $webhook_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$webhook = $this->db->get_where('webhooks', ['id' => $webhook_id])->row_array();
if ( ! $webhook)
@ -226,11 +212,10 @@ class Webhooks_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 webhooks.
*/
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -242,11 +227,6 @@ class Webhooks_model extends EA_Model {
$this->db->order_by($order_by);
}
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$webhooks = $this->db->get('webhooks', $limit, $offset)->result_array();
foreach ($webhooks as &$webhook)
@ -274,17 +254,11 @@ class Webhooks_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 webhooks.
*/
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$webhooks = $this
->db
->select()