19 declare(strict_types=1);
46 $user_id = $this->
user->getId();
48 if ($this->
user->isAnonymous()) {
50 if (isset($session[$this->room->getRoomId()][
'user_id'])) {
51 return $session[$this->room->getRoomId()][
'user_id'];
54 $user_id = random_int(-99999, -20);
56 $session[$this->room->getRoomId()][
'user_id'] = $user_id;
69 if ($this->username) {
76 isset($session[$this->room->getRoomId()][
'username']) &&
77 $session[$this->room->getRoomId()][
'username']
79 return $session[$this->room->getRoomId()][
'username'];
82 return $this->
user->getLogin();
90 $this->username = htmlspecialchars($username);
105 if ($this->
user->isAnonymous()) {
120 (
string) random_int(0, 10000),
121 $this->room->getSetting(
'autogen_usernames')
127 $tmp = $this->
user->getPref(
'public_profile');
128 $this->
user->setPref(
'public_profile',
'y');
129 $public_name = $this->
user->getPublicName();
130 $this->
user->setPref(
'public_profile', $tmp);
140 $firstname = $this->
user->getFirstname();
142 return $firstname[0] .
'. ' . $this->
user->getLastname();
147 return $this->
user->getLogin();
154 $username = htmlspecialchars(trim($username));
158 $rset = $DIC->database()->query(
159 'SELECT * FROM chatroom_users WHERE ' .
160 $DIC->database()->like(
'userdata',
'text',
'%"login":"' . $username .
'%') .
161 ' AND room_id = ' . $DIC->database()->quote($this->room->getRoomId(),
'integer')
164 while (($row = $DIC->database()->fetchAssoc($rset))) {
165 $json = json_decode($row[
'userdata'],
true, 512, JSON_THROW_ON_ERROR);
166 $usernames[] = $json[
'login'];
169 for ($index = 1, $indexMax = count($usernames); $index <= $indexMax; $index++) {
170 if (in_array($uniqueName, $usernames,
true)) {
171 $uniqueName = sprintf(
'%s_%d', $username, $index);
189 FROM chatroom_users WHERE ' . $DIC->database()->in(
'user_id', $usrIds,
false,
'integer');
191 if (null !== $roomId) {
192 $query .=
' AND room_id = ' . $DIC->database()->quote($roomId,
'integer');
195 $res = $DIC->database()->query($query);
196 while ($row = $DIC->database()->fetchAssoc(
$res)) {
197 $users[] = json_decode($row[
'userdata'],
false, 512, JSON_THROW_ON_ERROR);
static get(string $a_var)
__construct(private readonly ilObjUser $user, private readonly ilChatroom $room)
getUserId()
Returns Ilias User ID.
static getUserInformation(array $usrIds, ?int $roomId=null)
setUsername(string $username)
Sets and stores given username in SESSION.
buildShortname()
Returns first letter of users firstname, followed by dot lastname.
buildUniqueUsername(string $username)
getChatNameSuggestions()
Returns an array of chat-name suggestions.
static yn2tf(string $a_yn)
getUsername()
Returns username from Object or SESSION.
static set(string $a_var, $a_val)
Set a value.