user = $user; $this->chatPermissions = \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->getData($user->getGroupIDs()); // get user permissions if ($user->userID) { $ush = UserStorageHandler::getInstance(); // get ids $data = $ush->getField('chatUserPermissions', $user->userID); // cache does not exist or is outdated if ($data === null) { $userPermissions = [ ]; $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); $conditionBuilder->add('option_to_user.userID = ?', [ $user->userID ]); $sql = "SELECT option_to_user.objectID AS roomID, option_to_user.optionValue, acl_option.optionName AS permission FROM wcf".WCF_N."_acl_option acl_option INNER JOIN wcf".WCF_N."_acl_option_to_user option_to_user ON option_to_user.optionID = acl_option.optionID ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while (($row = $statement->fetchArray())) { $userPermissions[$row['roomID']][$row['permission']] = $row['optionValue']; } // update cache $ush->update($user->userID, 'chatUserPermissions', serialize($userPermissions)); } else { $userPermissions = unserialize($data); } foreach ($userPermissions as $roomID => $permissions) { foreach ($permissions as $name => $value) { $this->chatPermissions[$roomID][$name] = $value; } } } } public static function get(\wcf\data\user\UserProfile $user = null) { if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); if (!isset(static::$cache[$user->userID])) { static::$cache[$user->userID] = new static($user); } return static::$cache[$user->userID]; } /** * Fetches the given permission for the given room * * @param \chat\data\room\Room $room * @param string $permission * @return boolean */ public function getPermission(\chat\data\room\Room $room, $permission) { $groupPermission = str_replace([ 'user.', 'mod.' ], [ 'user.chat.', 'mod.chat.' ], $permission); if (method_exists($this->user, 'getNeverPermission') && $this->user->getNeverPermission($groupPermission)) { return false; } if (!isset($this->chatPermissions[$room->roomID][$permission])) { return $this->user->getPermission($groupPermission); } return (boolean) $this->chatPermissions[$room->roomID][$permission]; } /** * Clears the cache. */ public static function resetCache() { UserStorageHandler::getInstance()->resetAll('chatUserPermissions'); \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->reset(); } }