ILIAS  release_8 Revision v8.24
ilChatroomUser Class Reference

Class ilChatroomUser. More...

+ Collaboration diagram for ilChatroomUser:

Public Member Functions

 __construct (ilObjUser $user, ilChatroom $chatroom)
 
 enabledBroadcastTyping ()
 
 getUserId ()
 Returns Ilias User ID. More...
 
 getUsername ()
 Returns username from Object or SESSION. More...
 
 setUsername (string $username)
 Sets and stores given username in SESSION. More...
 
 getChatNameSuggestions ()
 Returns an array of chat-name suggestions. More...
 
 buildAnonymousName ()
 
 buildFullname ()
 
 buildShortname ()
 Returns first letter of users firstname, followed by dot lastname. More...
 
 buildLogin ()
 
 buildUniqueUsername (string $username)
 

Static Public Member Functions

static getUserInformation (array $usrIds, ?int $roomId=null)
 

Private Attributes

ilObjUser $user
 
ilChatroom $room
 
string $username = ''
 

Detailed Description

Class ilChatroomUser.

Author
Andreas Kordosz akord.nosp@m.osz@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 27 of file class.ilChatroomUser.php.

Constructor & Destructor Documentation

◆ __construct()

ilChatroomUser::__construct ( ilObjUser  $user,
ilChatroom  $chatroom 
)

Definition at line 33 of file class.ilChatroomUser.php.

34 {
35 $this->user = $user;
36 $this->room = $chatroom;
37 }

References $user, and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildAnonymousName()

ilChatroomUser::buildAnonymousName ( )

Definition at line 123 of file class.ilChatroomUser.php.

123 : string
124 {
125 return str_replace(
126 '#',
127 (string) random_int(0, 10000),
128 $this->room->getSetting('autogen_usernames')
129 );
130 }

Referenced by getChatNameSuggestions().

+ Here is the caller graph for this function:

◆ buildFullname()

ilChatroomUser::buildFullname ( )

Definition at line 132 of file class.ilChatroomUser.php.

132 : string
133 {
134 $tmp = $this->user->getPref('public_profile');
135 $this->user->setPref('public_profile', 'y');
136 $public_name = $this->user->getPublicName();
137 $this->user->setPref('public_profile', $tmp);
138
139 return $public_name;
140 }

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildLogin()

ilChatroomUser::buildLogin ( )

Definition at line 153 of file class.ilChatroomUser.php.

153 : string
154 {
155 return $this->user->getLogin();
156 }

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildShortname()

ilChatroomUser::buildShortname ( )

Returns first letter of users firstname, followed by dot lastname.

Returns
string

Definition at line 146 of file class.ilChatroomUser.php.

146 : string
147 {
148 $firstname = $this->user->getFirstname();
149
150 return $firstname[0] . '. ' . $this->user->getLastname();
151 }

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildUniqueUsername()

ilChatroomUser::buildUniqueUsername ( string  $username)

Definition at line 158 of file class.ilChatroomUser.php.

158 : string
159 {
160 global $DIC;
161
162 $username = htmlspecialchars(trim($username));
163 $usernames = [];
164 $uniqueName = $username;
165
166 $rset = $DIC->database()->query(
167 'SELECT * FROM chatroom_users WHERE ' .
168 $DIC->database()->like('userdata', 'text', '%"login":"' . $username . '%') .
169 ' AND room_id = ' . $DIC->database()->quote($this->room->getRoomId(), 'integer')
170 );
171
172 while (($row = $DIC->database()->fetchAssoc($rset))) {
173 $json = json_decode($row['userdata'], true, 512, JSON_THROW_ON_ERROR);
174 $usernames[] = $json['login'];
175 }
176
177 for ($index = 1, $indexMax = count($usernames); $index <= $indexMax; $index++) {
178 if (in_array($uniqueName, $usernames, true)) {
179 $uniqueName = sprintf('%s_%d', $username, $index);
180 }
181 }
182
183 return $uniqueName;
184 }
global $DIC
Definition: feed.php:28
$index
Definition: metadata.php:145

References $DIC, $index, and $username.

◆ enabledBroadcastTyping()

ilChatroomUser::enabledBroadcastTyping ( )

Definition at line 39 of file class.ilChatroomUser.php.

39 : bool
40 {
41 return ilUtil::yn2tf((string) $this->user->getPref('chat_broadcast_typing'));
42 }
static yn2tf(string $a_yn)

References ILIAS\Repository\user(), and ilUtil\yn2tf().

Referenced by ilChatroomViewGUI\showRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChatNameSuggestions()

ilChatroomUser::getChatNameSuggestions ( )

Returns an array of chat-name suggestions.

Returns
array<string, string>

Definition at line 108 of file class.ilChatroomUser.php.

108 : array
109 {
110 $options = [];
111
112 if ($this->user->isAnonymous()) {
113 $options['anonymousName'] = $this->buildAnonymousName();
114 } else {
115 $options['fullname'] = $this->buildFullname();
116 $options['shortname'] = $this->buildShortname();
117 $options['login'] = $this->buildLogin();
118 }
119
120 return $options;
121 }
buildShortname()
Returns first letter of users firstname, followed by dot lastname.

References buildAnonymousName(), buildFullname(), buildLogin(), buildShortname(), and ILIAS\Repository\user().

Referenced by ilChatroomViewGUI\showNameSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserId()

ilChatroomUser::getUserId ( )

Returns Ilias User ID.

If user is anonymous, a random negative User ID is created, stored in SESSION, and returned.

Returns
int

Definition at line 49 of file class.ilChatroomUser.php.

49 : int
50 {
51 $user_id = $this->user->getId();
52
53 if ($this->user->isAnonymous()) {
54 $session = ilSession::get('chat');
55 if (isset($session[$this->room->getRoomId()]['user_id'])) {
56 return $session[$this->room->getRoomId()]['user_id'];
57 }
58
59 $user_id = random_int(-99999, -20);
60
61 $session[$this->room->getRoomId()]['user_id'] = $user_id;
62 ilSession::set('chat', $session);
63 }
64
65 return $user_id;
66 }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
$session

References $session, ilSession\get(), ilSession\set(), and ILIAS\Repository\user().

Referenced by ilChatroom\addPrivateRoom(), ilChatroom\connectUser(), ilChatroomPrivateRoomGUI\exitIfEnterRoomIsNotAllowed(), ilChatroomGUIHandler\exitIfNoRoomModeratePermission(), ilChatroomPrivateRoomGUI\exitIfNoRoomSubscription(), ilChatroom\getLastMessages(), ilChatroom\getLastSession(), and ilChatroomViewGUI\showRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserInformation()

static ilChatroomUser::getUserInformation ( array  $usrIds,
?int  $roomId = null 
)
static
Parameters
int[]$usrIds
int | null$roomId
Returns
array

Definition at line 191 of file class.ilChatroomUser.php.

191 : array
192 {
193 global $DIC;
194
195 $users = [];
196
197 $query = '
198 SELECT userdata
199 FROM chatroom_users WHERE ' . $DIC->database()->in('user_id', $usrIds, false, 'integer');
200
201 if (null !== $roomId) {
202 $query .= ' AND room_id = ' . $DIC->database()->quote($roomId, 'integer');
203 }
204
205 $res = $DIC->database()->query($query);
206 while ($row = $DIC->database()->fetchAssoc($res)) {
207 $users[] = json_decode($row['userdata'], false, 512, JSON_THROW_ON_ERROR);
208 }
209
210 return $users;
211 }
$res
Definition: ltiservices.php:69
$query

References $DIC, $query, and $res.

◆ getUsername()

ilChatroomUser::getUsername ( )

Returns username from Object or SESSION.

If no Username is set, the login name will be returned.

Returns
string

Definition at line 73 of file class.ilChatroomUser.php.

73 : string
74 {
75 if ($this->username) {
76 return $this->username;
77 }
78
79 $session = ilSession::get('chat');
80 if (
81 is_array($session) &&
82 isset($session[$this->room->getRoomId()]['username']) &&
83 $session[$this->room->getRoomId()]['username']
84 ) {
85 return $session[$this->room->getRoomId()]['username'];
86 }
87
88 return $this->user->getLogin();
89 }

References $session, $username, ilSession\get(), and ILIAS\Repository\user().

Referenced by ilChatroom\connectUser(), and ilChatroomViewGUI\showRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUsername()

ilChatroomUser::setUsername ( string  $username)

Sets and stores given username in SESSION.

Parameters
string$username

Definition at line 95 of file class.ilChatroomUser.php.

95 : void
96 {
97 $this->username = htmlspecialchars($username);
98
99 $session = ilSession::get('chat');
100 $session[$this->room->getRoomId()]['username'] = $this->username;
101 ilSession::set('chat', $session);
102 }

References $session, $username, ilSession\get(), and ilSession\set().

+ Here is the call graph for this function:

Field Documentation

◆ $room

ilChatroom ilChatroomUser::$room
private

Definition at line 30 of file class.ilChatroomUser.php.

◆ $user

ilObjUser ilChatroomUser::$user
private

Definition at line 29 of file class.ilChatroomUser.php.

Referenced by __construct().

◆ $username

string ilChatroomUser::$username = ''
private

Definition at line 31 of file class.ilChatroomUser.php.

Referenced by buildUniqueUsername(), getUsername(), and setUsername().


The documentation for this class was generated from the following file: