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

@ -136,7 +136,7 @@ class Accounts {
$user = $query->row_array();
// Generate a new password for the user.
// Generate a new password for the user.
$new_password = random_string('alnum', 12);
$salt = $this->get_salt_by_username($username);
@ -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

@ -91,7 +91,7 @@ class Admins_model extends EA_Model {
}
}
// Make sure all required fields are provided.
// Make sure all required fields are provided.
if (
empty($admin['first_name'])
|| empty($admin['last_name'])
@ -108,7 +108,7 @@ class Admins_model extends EA_Model {
throw new InvalidArgumentException('Invalid email address provided: ' . $admin['email']);
}
// Make sure the username is unique.
// Make sure the username is unique.
if ( ! empty($admin['settings']['username']))
{
$admin_id = $admin['id'] ?? NULL;
@ -119,7 +119,7 @@ class Admins_model extends EA_Model {
}
}
// Validate the password.
// Validate the password.
if ( ! empty($admin['settings']['password']))
{
if (strlen($admin['settings']['password']) < MIN_PASSWORD_LENGTH)
@ -128,7 +128,7 @@ class Admins_model extends EA_Model {
}
}
// New users must always have a password value set.
// New users must always have a password value set.
if (empty($admin['id']) && empty($admin['settings']['password']))
{
throw new InvalidArgumentException('The admin password cannot be empty when inserting a new record.');
@ -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)
@ -457,7 +436,7 @@ class Admins_model extends EA_Model {
throw new InvalidArgumentException('The settings argument cannot be empty.');
}
// Make sure the settings record exists in the database.
// Make sure the settings record exists in the database.
$count = $this->db->get_where('user_settings', ['id_users' => $admin_id])->num_rows();
if ( ! $count)
@ -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()
@ -588,7 +561,7 @@ class Admins_model extends EA_Model {
*/
public function load(array &$admin, array $resources)
{
// Admins do not currently have any related resources (settings are already part of the admins).
// Admins do not currently have any related resources (settings are already part of the admins).
}
/**

View File

@ -91,10 +91,10 @@ class Appointments_model extends EA_Model {
}
}
// Make sure all required fields are provided.
// Make sure all required fields are provided.
$require_notes = filter_var(setting('require_notes'), FILTER_VALIDATE_BOOLEAN);
if (
empty($appointment['start_datetime'])
|| empty($appointment['end_datetime'])
@ -126,7 +126,7 @@ class Appointments_model extends EA_Model {
throw new InvalidArgumentException('The appointment duration cannot be less than ' . EVENT_MINIMUM_DURATION . ' minutes.');
}
// Make sure the provider ID really exists in the database.
// Make sure the provider ID really exists in the database.
$count = $this
->db
->select()
@ -144,7 +144,7 @@ class Appointments_model extends EA_Model {
if ( ! filter_var($appointment['is_unavailability'], FILTER_VALIDATE_BOOLEAN))
{
// Make sure the customer ID really exists in the database.
// Make sure the customer ID really exists in the database.
$count = $this
->db
->select()
@ -160,7 +160,7 @@ class Appointments_model extends EA_Model {
throw new InvalidArgumentException('The appointment customer ID was not found in the database: ' . $appointment['id_users_customer']);
}
// Make sure the service ID really exists in the database.
// Make sure the service ID really exists in the database.
$count = $this->db->get_where('services', ['id' => $appointment['id_services']])->num_rows();
if ( ! $count)
@ -206,7 +206,7 @@ class Appointments_model extends EA_Model {
protected function update(array $appointment): int
{
$appointment['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('appointments', $appointment, ['id' => $appointment['id']]))
{
throw new RuntimeException('Could not update appointment record.');
@ -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

@ -100,7 +100,7 @@ class Categories_model extends EA_Model {
{
$category['create_datetime'] = date('Y-m-d H:i:s');
$category['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->insert('categories', $category))
{
throw new RuntimeException('Could not insert category.');
@ -121,7 +121,7 @@ class Categories_model extends EA_Model {
protected function update(array $category): int
{
$category['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('categories', $category, ['id' => $category['id']]))
{
throw new RuntimeException('Could not update service categories.');
@ -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()
@ -320,7 +294,7 @@ class Categories_model extends EA_Model {
*/
public function load(array &$category, array $resources)
{
// Service categories do not currently have any related resources.
// Service categories do not currently have any related resources.
}
/**

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()
@ -301,6 +277,6 @@ class Consents_model extends EA_Model {
*/
public function load(array &$consent, array $resources)
{
// Consents do not currently have any related resources.
// Consents do not currently have any related resources.
}
}

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()
@ -476,7 +446,7 @@ class Customers_model extends EA_Model {
*/
public function load(array &$customer, array $resources)
{
// Customers do not currently have any related resources.
// Customers do not currently have any related resources.
}
/**

View File

@ -93,7 +93,7 @@ class Providers_model extends EA_Model {
}
}
// Make sure all required fields are provided.
// Make sure all required fields are provided.
if (
empty($provider['first_name'])
|| empty($provider['last_name'])
@ -123,7 +123,7 @@ class Providers_model extends EA_Model {
}
}
// Make sure the username is unique.
// Make sure the username is unique.
if ( ! empty($provider['settings']['username']))
{
$provider_id = $provider['id'] ?? NULL;
@ -134,7 +134,7 @@ class Providers_model extends EA_Model {
}
}
// Validate the password.
// Validate the password.
if ( ! empty($provider['settings']['password']))
{
if (strlen($provider['settings']['password']) < MIN_PASSWORD_LENGTH)
@ -143,7 +143,7 @@ class Providers_model extends EA_Model {
}
}
// New users must always have a password value set.
// New users must always have a password value set.
if (empty($provider['id']) && empty($provider['settings']['password']))
{
throw new InvalidArgumentException('The provider password cannot be empty when inserting a new record.');
@ -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();
@ -486,7 +466,7 @@ class Providers_model extends EA_Model {
throw new InvalidArgumentException('The settings argument cannot be empty.');
}
// Make sure the settings record exists in the database.
// Make sure the settings record exists in the database.
$count = $this->db->get_where('user_settings', ['id_users' => $provider_id])->num_rows();
if ( ! $count)
@ -496,7 +476,7 @@ class Providers_model extends EA_Model {
foreach ($settings as $name => $value)
{
// Sort working plans exceptions in descending order that they are easier to modify later on.
// Sort working plans exceptions in descending order that they are easier to modify later on.
if ($name === 'working_plan_exceptions')
{
$value = json_decode($value, TRUE);
@ -558,7 +538,7 @@ class Providers_model extends EA_Model {
*/
protected function save_service_ids(int $provider_id, array $service_ids)
{
// Re-insert the provider-service connections.
// Re-insert the provider-service connections.
$this->db->delete('services_providers', ['id_users' => $provider_id]);
foreach ($service_ids as $service_id)
@ -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

@ -98,7 +98,7 @@ class Roles_model extends EA_Model {
{
$role['create_datetime'] = date('Y-m-d H:i:s');
$role['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->insert('roles', $role))
{
throw new RuntimeException('Could not insert role.');
@ -119,7 +119,7 @@ class Roles_model extends EA_Model {
protected function update(array $role): int
{
$role['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('roles', $role, ['id' => $role['id']]))
{
throw new RuntimeException('Could not update role.');
@ -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()
@ -386,6 +360,6 @@ class Roles_model extends EA_Model {
*/
public function load(array &$role, array $resources)
{
// Roles do not currently have any related resources.
// Roles do not currently have any related resources.
}
}

View File

@ -91,7 +91,7 @@ class Secretaries_model extends EA_Model {
}
}
// Make sure all required fields are provided.
// Make sure all required fields are provided.
if (
empty($secretary['first_name'])
|| empty($secretary['last_name'])
@ -121,7 +121,7 @@ class Secretaries_model extends EA_Model {
}
}
// Make sure the username is unique.
// Make sure the username is unique.
if ( ! empty($secretary['settings']['username']))
{
$secretary_id = $secretary['id'] ?? NULL;
@ -132,7 +132,7 @@ class Secretaries_model extends EA_Model {
}
}
// Validate the password.
// Validate the password.
if ( ! empty($secretary['settings']['password']))
{
if (strlen($secretary['settings']['password']) < MIN_PASSWORD_LENGTH)
@ -141,7 +141,7 @@ class Secretaries_model extends EA_Model {
}
}
// New users must always have a password value set.
// New users must always have a password value set.
if (empty($secretary['id']) && empty($secretary['settings']['password']))
{
throw new InvalidArgumentException('The provider password cannot be empty when inserting a new record.');
@ -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)
@ -478,7 +457,7 @@ class Secretaries_model extends EA_Model {
throw new InvalidArgumentException('The settings argument cannot be empty.');
}
// Make sure the settings record exists in the database.
// Make sure the settings record exists in the database.
$count = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->num_rows();
if ( ! $count)
@ -535,7 +514,7 @@ class Secretaries_model extends EA_Model {
*/
protected function save_provider_ids(int $secretary_id, array $provider_ids)
{
// Re-insert the secretary-provider connections.
// Re-insert the secretary-provider connections.
$this->db->delete('secretaries_providers', ['id_users_secretary' => $secretary_id]);
foreach ($provider_ids as $provider_id)
@ -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()
@ -800,10 +773,10 @@ class Secretaries_model extends EA_Model {
/**
* Quickly check if a provider is assigned to a provider.
*
*
* @param int $secretary_id
* @param int $provider_id
*
*
* @return bool
*/
public function is_provider_supported(int $secretary_id, int $provider_id): bool

View File

@ -99,7 +99,7 @@ class Services_model extends EA_Model {
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($service, TRUE));
}
// If a category was provided then make sure it really exists in the database.
// If a category was provided then make sure it really exists in the database.
if ( ! empty($service['id_categories']))
{
$count = $this->db->get_where('categories', ['id' => $service['id_categories']])->num_rows();
@ -110,7 +110,7 @@ class Services_model extends EA_Model {
}
}
// Make sure the duration value is valid.
// Make sure the duration value is valid.
if ( ! empty($service['duration']))
{
if ((int)$service['duration'] < EVENT_MINIMUM_DURATION)
@ -136,7 +136,7 @@ class Services_model extends EA_Model {
throw new InvalidArgumentException('The provided availabilities type is invalid: ' . $service['availabilities_type']);
}
// Validate the attendants number value.
// Validate the attendants number value.
if (empty($service['attendants_number']) || (int)$service['attendants_number'] < 1)
{
throw new InvalidArgumentException('The provided attendants number is invalid: ' . $service['attendants_number']);
@ -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

@ -27,11 +27,11 @@ class Settings_model extends EA_Model {
];
/**
* @var array
* @var array
*/
protected array $api_resource = [
'name' => 'name',
'value' => 'value',
'name' => 'name',
'value' => 'value',
];
/**
@ -99,7 +99,7 @@ class Settings_model extends EA_Model {
{
$setting['create_datetime'] = date('Y-m-d H:i:s');
$setting['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->insert('settings', $setting))
{
throw new RuntimeException('Could not insert setting.');
@ -120,7 +120,7 @@ class Settings_model extends EA_Model {
protected function update(array $setting): int
{
$setting['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('settings', $setting, ['id' => $setting['id']]))
{
throw new RuntimeException('Could not update setting.');
@ -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()
@ -319,7 +293,7 @@ class Settings_model extends EA_Model {
*/
public function load(array &$setting, array $resources)
{
// Users do not currently have any related resources.
// Users do not currently have any related resources.
}
/**

View File

@ -88,7 +88,7 @@ class Unavailabilities_model extends EA_Model {
}
}
// Make sure all required fields are provided.
// Make sure all required fields are provided.
if (
empty($unavailability['start_datetime'])
|| empty($unavailability['end_datetime'])
@ -117,7 +117,7 @@ class Unavailabilities_model extends EA_Model {
throw new InvalidArgumentException('The unavailability duration cannot be less than ' . EVENT_MINIMUM_DURATION . ' minutes.');
}
// Make sure the provider ID really exists in the database.
// Make sure the provider ID really exists in the database.
$count = $this
->db
->select()
@ -171,7 +171,7 @@ class Unavailabilities_model extends EA_Model {
protected function update(array $unavailability): int
{
$unavailability['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('appointments', $unavailability, ['id' => $unavailability['id']]))
{
throw new RuntimeException('Could not update unavailability record.');
@ -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

@ -116,7 +116,7 @@ class Users_model extends EA_Model {
{
$user['create_datetime'] = date('Y-m-d H:i:s');
$user['update_datetime'] = date('Y-m-d H:i:s');
$settings = $user['settings'];
unset($user['settings']);
@ -146,7 +146,7 @@ class Users_model extends EA_Model {
protected function update(array $user): int
{
$user['update_datetime'] = date('Y-m-d H:i:s');
$settings = $user['settings'];
unset($user['settings']);
@ -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)
@ -333,7 +313,7 @@ class Users_model extends EA_Model {
throw new InvalidArgumentException('The settings argument cannot be empty.');
}
// Make sure the settings record exists in the database.
// Make sure the settings record exists in the database.
$count = $this->db->get_where('user_settings', ['id_users' => $user_id])->num_rows();
if ( ! $count)
@ -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()
@ -458,7 +432,7 @@ class Users_model extends EA_Model {
*/
public function load(array &$user, array $resources)
{
// Users do not currently have any related resources.
// Users do not currently have any related resources.
}
/**

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()
@ -318,6 +292,6 @@ class Webhooks_model extends EA_Model {
*/
public function load(array &$webhook, array $resources)
{
// Webhooks do not currently have any related resources.
// Webhooks do not currently have any related resources.
}
}