From 8c91c8650874e785d302ca92729f589c124f96d0 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Wed, 30 Nov 2022 11:21:39 +0100 Subject: [PATCH] Do not take deleted records into concern --- application/models/Admins_model.php | 9 +++++---- application/models/Providers_model.php | 15 ++++++++------- application/models/Secretaries_model.php | 15 ++++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/application/models/Admins_model.php b/application/models/Admins_model.php index 10baf1e5..4ddb4d24 100644 --- a/application/models/Admins_model.php +++ b/application/models/Admins_model.php @@ -153,6 +153,7 @@ 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', NULL) ->get() ->num_rows(); @@ -177,7 +178,7 @@ class Admins_model extends EA_Model { $this->db->where('id_users !=', $admin_id); } - return $this->db->get_where('user_settings', ['username' => $username])->num_rows() === 0; + return $this->db->get_where('user_settings', ['username' => $username, 'delete_datetime' => NULL])->num_rows() === 0; } /** @@ -194,7 +195,7 @@ class Admins_model extends EA_Model { $admin['id_roles'] = $this->get_admin_role_id(); $settings = $admin['settings']; - + unset( $admin['settings'] ); @@ -228,9 +229,9 @@ class Admins_model extends EA_Model { protected function update(array $admin): int { $settings = $admin['settings']; - + $settings['id_users'] = $admin['id']; - + unset( $admin['settings'] ); diff --git a/application/models/Providers_model.php b/application/models/Providers_model.php index 92305b92..6bcf1862 100755 --- a/application/models/Providers_model.php +++ b/application/models/Providers_model.php @@ -168,6 +168,7 @@ 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', NULL) ->get() ->num_rows(); @@ -192,7 +193,7 @@ class Providers_model extends EA_Model { $this->db->where('id_users !=', $provider_id); } - return $this->db->get_where('user_settings', ['username' => $username])->num_rows() === 0; + return $this->db->get_where('user_settings', ['username' => $username, 'delete_datetime' => NULL])->num_rows() === 0; } /** @@ -213,7 +214,7 @@ class Providers_model extends EA_Model { $service_ids = $provider['services']; $settings = $provider['settings']; - + unset( $provider['services'], $provider['settings'] @@ -246,7 +247,7 @@ class Providers_model extends EA_Model { protected function update(array $provider): int { $provider['update_datetime'] = date('Y-m-d H:i:s'); - + $service_ids = $provider['services']; $settings = $provider['settings']; @@ -315,7 +316,7 @@ class Providers_model extends EA_Model { { $this->db->where('delete_datetime IS NULL'); } - + $provider = $this->db->get_where('users', ['id' => $provider_id])->row_array(); if ( ! $provider) @@ -396,7 +397,7 @@ class Providers_model extends EA_Model { * @param int|null $offset Record offset. * @param string|null $order_by Order by. * @param bool $with_trashed - * + * * @return array Returns an array of providers. */ public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array @@ -708,7 +709,7 @@ class Providers_model extends EA_Model { * @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 @@ -719,7 +720,7 @@ class Providers_model extends EA_Model { { $this->db->where('delete_datetime IS NULL'); } - + $providers = $this ->db ->select() diff --git a/application/models/Secretaries_model.php b/application/models/Secretaries_model.php index fb54fcfb..d5eb8a8e 100644 --- a/application/models/Secretaries_model.php +++ b/application/models/Secretaries_model.php @@ -166,6 +166,7 @@ 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', NULL) ->get() ->num_rows(); @@ -190,7 +191,7 @@ class Secretaries_model extends EA_Model { $this->db->where('id_users !=', $secretary_id); } - return $this->db->get_where('user_settings', ['username' => $username])->num_rows() === 0; + return $this->db->get_where('user_settings', ['username' => $username, 'delete_datetime' => NULL])->num_rows() === 0; } /** @@ -206,7 +207,7 @@ class Secretaries_model extends EA_Model { { $secretary['create_datetime'] = date('Y-m-d H:i:s'); $secretary['update_datetime'] = date('Y-m-d H:i:s'); - + $secretary['id_roles'] = $this->get_secretary_role_id(); $provider_ids = $secretary['providers'] ?? []; @@ -245,7 +246,7 @@ class Secretaries_model extends EA_Model { protected function update(array $secretary): int { $secretary['update_datetime'] = date('Y-m-d H:i:s'); - + $provider_ids = $secretary['providers'] ?? []; $settings = $secretary['settings']; @@ -321,7 +322,7 @@ class Secretaries_model extends EA_Model { { throw new InvalidArgumentException('The provided secretary ID was not found in the database: ' . $secretary_id); } - + $secretary['settings'] = $this->db->get_where('user_settings', ['id_users' => $secretary_id])->row_array(); unset( @@ -391,7 +392,7 @@ class Secretaries_model extends EA_Model { * @param int|null $offset Record offset. * @param string|null $order_by Order by. * @param bool $with_trashed - * + * * @return array Returns an array of secretaries. */ public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array @@ -561,7 +562,7 @@ class Secretaries_model extends EA_Model { * @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 @@ -572,7 +573,7 @@ class Secretaries_model extends EA_Model { { $this->db->where('delete_datetime IS NULL'); } - + $secretaries = $this ->db ->select()