From 0bf753c2b3de80465f4e8b092e2228928683f90e Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:58:03 +0400 Subject: [PATCH] add getByEmail --- src/models/Administrator.php | 45 +++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/models/Administrator.php b/src/models/Administrator.php index e68da2f..ddfafe7 100644 --- a/src/models/Administrator.php +++ b/src/models/Administrator.php @@ -77,9 +77,6 @@ public function save(): void $inserted_record = self::first($user_data, 'user'); -// utility::show("inserted record: "); -// Utility::show($inserted_record); - if (!$inserted_record) { return; } @@ -95,6 +92,48 @@ public function save(): void $this->insert($admin_data, $this->table); } + + /** + * Returns the Administrator object corresponding to the given email. + * + * @param string $email The email of the administrator. + * @return ?Administrator The Client object if found, otherwise null. + */ + public static function getByEmail(string $email): ?Administrator + { + $query = << $email]); + + // Check if the result is empty + if (!$result) { + return null; + } + + // Create a new Administrator object + $administrator = new Administrator( + email: $email, + first_name: $result->first_name, + last_name: $result->last_name, + plain_password: "dummy", + phone_no: $result->phone_no, + job_title: $result->job_title, + is_super_admin: filter_var($result->is_super_admin, FILTER_SANITIZE_NUMBER_INT) + ); + + // Set the user ID and password hash + $administrator->user_id = $result->user_id; + $administrator->password = $result->password; + + return $administrator; + } + public function getJobTitle(): string { return $this->job_title;