diff --git a/admin/groups.php b/admin/groups.php index 52c60a4..77a525d 100644 --- a/admin/groups.php +++ b/admin/groups.php @@ -34,7 +34,7 @@ diff --git a/admin/users.php b/admin/users.php index 032f11d..2430e12 100644 --- a/admin/users.php +++ b/admin/users.php @@ -54,7 +54,7 @@ ' : ''; ?> getRolesObject()->getFullGroup() as $userRole) { + foreach($userObject->getRolesObject()->getFullRoles() as $userRole) { $arRoles[] = $userRole['name'] . ' (' . $userRole['id'] . ')'; } echo implode(', ', $arRoles); diff --git a/core/SQL_DUMPS/user_roles.sql b/core/SQL_DUMPS/user_roles.sql index 8a4a34c..87579cd 100644 --- a/core/SQL_DUMPS/user_roles.sql +++ b/core/SQL_DUMPS/user_roles.sql @@ -31,14 +31,14 @@ SET time_zone = "+00:00"; CREATE TABLE `user_roles` ( `id` int(11) NOT NULL, `user_id` int(11) NOT NULL, - `group_id` int(11) NOT NULL + `role_id` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Дамп данных таблицы `user_groups` -- -INSERT INTO `user_roles` (`id`, `user_id`, `group_id`) VALUES +INSERT INTO `user_roles` (`id`, `user_id`, `role_id`) VALUES (1, 1, 1), -- diff --git a/core/bootstrap.php b/core/bootstrap.php index c6beeb3..0cc48f9 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -42,7 +42,7 @@ - Cache::init(ROOT_PATH . '/core/cache/', true); + Cache::init(ROOT_PATH . '/core/cache/', USE_CACHE); // очистка кэша if(isset($_REQUEST['clear_cache']) && $_REQUEST['clear_cache'] === CODE_VALUE_Y) { diff --git a/core/config.php b/core/config.php index 6308596..cf3eb42 100644 --- a/core/config.php +++ b/core/config.php @@ -1,45 +1,45 @@ user->getId() . '_getGroups'); + $cacheId = md5('Roles_' . $this->user->getId() . '_getRoles'); if (Cache::check($cacheId)) { - $userGroups = Cache::get($cacheId); + $userRoles = Cache::get($cacheId); } else { /** @var $DB DB */ $DB = DB::getInstance(); - $res = $DB->query('SELECT group_id FROM `' . self::USER_GROUPS_TABLE . '` WHERE user_id=' . $this->user->getId()); - $userGroups = []; + $res = $DB->query('SELECT role_id FROM `' . self::USER_ROLES_TABLE . '` WHERE user_id=' . $this->user->getId()); + $userRoles = []; if (!empty($res)) { foreach ($res as $row) { - $userGroups[] = $row['group_id']; + $userRoles[] = $row['role_id']; } } - Cache::set($cacheId, $userGroups); + Cache::set($cacheId, $userRoles); } - return $userGroups; + return $userRoles; } /** - * Добавляет пользователя в указанную группу + * Добавляет пользователю указанную роль * - * @param int $groupId Идентификатор группы + * @param int $roleId ID роли * * @return int|null */ - public function addToGroup(int $groupId): ?int + public function addRole(int $roleId): ?int { - $cacheId = md5('Group_' . $this->user->getId() . '_getGroups'); + $cacheId = md5('Roles_' . $this->user->getId() . '_getRoles'); Cache::del($cacheId); /** @var $DB DB */ $DB = DB::getInstance(); - return $DB->addItem(self::USER_GROUPS_TABLE, ['user_id' => $this->user->getId(), 'group_id' => $groupId]); + return $DB->addItem(self::USER_ROLES_TABLE, ['user_id' => $this->user->getId(), 'role_id' => $roleId]); } /** - * Убирает пользователя из указанной группы + * Убирает пользователю указанную роль * - * @param int $groupId Идентификатор группы + * @param int $roleId ID роли * * @return int|null */ - public function removeFromGroup(int $groupId): ?int + public function removeRole(int $roleId): ?int { - $cacheId = md5('Group_' . $this->user->getId() . '_getGroups'); + $cacheId = md5('Roles_' . $this->user->getId() . '_getRoles'); Cache::del($cacheId); /** @var $DB DB */ $DB = DB::getInstance(); - return $DB->query('DELETE FROM ' . self::USER_GROUPS_TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND group_id=' . $groupId); + return $DB->query('DELETE FROM ' . self::USER_ROLES_TABLE . ' WHERE user_id=' . $this->user->getId() . ' AND role_id=' . $roleId); } /** - * Получение полной информации о группах пользователя + * Получение полной информации о ролях пользователя * * @return array|null */ - public function getFullGroup(): ?array + public function getFullRoles(): ?array { return array_map(function ($element) { - return static::getAllGroups()[$element]; + return static::getAllRoles()[$element]; }, - $this->getGroups()); + $this->getRoles()); } /** - * Получение всех существующих групп + * Получение всех существующих ролей * * @return array|null */ - public static function getAllGroups(): ?array + public static function getAllRoles(): ?array { - $cacheId = md5('Group::getAllGroups'); + $cacheId = md5('Roles::getAllRoles'); if (Cache::check($cacheId)) { - $groups = Cache::get($cacheId); + $roles = Cache::get($cacheId); } else { /** @var $DB DB */ $DB = DB::getInstance(); - $res = $DB->query('SELECT * FROM ' . self::GROUPS_TABLE); - $groups = []; + $res = $DB->query('SELECT * FROM ' . self::ROLES_TABLE); + $roles = []; if (!empty($res)) { - foreach ($res as $group) { - $groups[$group['id']] = $group; + foreach ($res as $role) { + $roles[$role['id']] = $role; } } - Cache::set($cacheId, $groups); + Cache::set($cacheId, $roles); } - return $groups; + return $roles; } } \ No newline at end of file diff --git a/core/lib/Core/Models/User.class.php b/core/lib/Core/Models/User.class.php index e9d36cb..a2d4e7f 100644 --- a/core/lib/Core/Models/User.class.php +++ b/core/lib/Core/Models/User.class.php @@ -479,7 +479,7 @@ */ public function isAdmin(): bool { - return in_array(Roles::ADMIN_GROUP_ID, $this->getRolesObject()->getGroups()); + return in_array(Roles::ADMIN_ROLE_ID, $this->getRolesObject()->getRoles()); } /**