/** * Returns authenticated user or null. The method is cached. * * @return WiseChatUser|null */ public function getUser() { static $cache = null; if ($this->isAuthenticated()) { if ($cache === null) { $cache = $this->usersDAO->get($this->userSessionDAO->get(self::SESSION_KEY_USER_ID)); } return $cache; } return null; }
/** * Bans an user by message ID. * * @param integer $messageId * @param WiseChatChannel $channel * @param string $durationString * * @throws Exception If the message or user was not found */ public function banByMessageId($messageId, $channel, $durationString = '1d') { $message = $this->messagesDAO->get($messageId); if ($message === null) { throw new Exception('Message was not found'); } $channelUser = $this->channelUsersDAO->getByUserIdAndChannelId($message->getUserId(), $channel->getId()); if ($channelUser !== null) { $user = $this->usersDAO->get($message->getUserId()); if ($user !== null) { $duration = $this->getDurationFromString($durationString); $this->banIpAddress($user->getIp(), $duration); return; } } throw new Exception('User was not found in this channel'); }