From 1412003d5e5ea43b81f34b23fd2ece929cb24e9c Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Mon, 18 Apr 2022 17:41:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D1=8D=D1=88=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20?= =?UTF-8?q?=D0=AE=D0=B7=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.php | 10 ++++++++++ core/lib/Core/Models/User.class.php | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/config.php b/core/config.php index d1724f7..fd91268 100644 --- a/core/config.php +++ b/core/config.php @@ -1,4 +1,10 @@ id = $id; } @@ -65,8 +66,15 @@ */ public function getAllUserData(): ?array { - $result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]); - if ($result) { + $cacheId = md5('User_getAllUserData_' . $this->id); + if(Cache::check($cacheId)) { + $result = Cache::get($cacheId); + } else { + $result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]); + Cache::set($cacheId, $result); + } + + if (!empty($result)) { return $result; } else { return null; @@ -360,14 +368,10 @@ * * @return bool */ - public static function isAdmin(): bool + public function isAdmin(): bool { - if (self::isUser()) { - if (self::getFields(self::$id)['access_level'] == 'admin') { - return true; - } else { - return false; - } + if ($this->getAllUserData()['access_level'] == self::ACCESS_ADMIN) { + return true; } else { return false; }