ILIAS  release_7 Revision v7.30-3-g800a261c036
ilChatroomUser Class Reference

Class ilChatroomUser. More...

+ Collaboration diagram for ilChatroomUser:

Public Member Functions

 __construct (ilObjUser $user, ilChatroom $chatroom)
 Constructor Requires ilObjUser and sets $this->user and $this->room using given $user and $chatroom. More...
 
 getUserId ()
 Returns Ilias User ID. More...
 
 getUsername ()
 Returns username from Object or SESSION. More...
 
 setUsername ($username)
 Sets and stores given username in SESSION. More...
 
 getChatNameSuggestions ()
 Returns an array of chat-name suggestions. More...
 
 buildAnonymousName ()
 Returns an anonymous username containing a random number. More...
 
 buildFullname ()
 Returns users first & lastname. More...
 
 buildShortname ()
 Returns first letter of users firstname, followed by dot lastname. More...
 
 buildLogin ()
 Returns user login. More...
 
 buildUniqueUsername ($username)
 

Static Public Member Functions

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

Private Attributes

 $user
 
 $username
 
 $room
 

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 12 of file class.ilChatroomUser.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor Requires ilObjUser and sets $this->user and $this->room using given $user and $chatroom.

Parameters
ilObjUser$user
ilChatroom$chatroom

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

37 {
38 $this->user = $user;
39 $this->room = $chatroom;
40 }
user()
Definition: user.php:4

References $user, and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildAnonymousName()

ilChatroomUser::buildAnonymousName ( )

Returns an anonymous username containing a random number.

Returns
string

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

115 {
116 $anonymous_name = str_replace(
117 '#',
118 mt_rand(0, 10000),
119 $this->room->getSetting('autogen_usernames')
120 );
121
122 return $anonymous_name;
123 }

Referenced by getChatNameSuggestions().

+ Here is the caller graph for this function:

◆ buildFullname()

ilChatroomUser::buildFullname ( )

Returns users first & lastname.

Returns
string

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

130 {
131 $tmp = $this->user->getPref('public_profile');
132 $this->user->setPref('public_profile', 'y');
133 $pn = $this->user->getPublicName();
134 $this->user->setPref('public_profile', $tmp);
135 return $pn;
136 }

References user().

Referenced by getChatNameSuggestions().

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

◆ buildLogin()

ilChatroomUser::buildLogin ( )

Returns user login.

Returns
string

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

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

References 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 142 of file class.ilChatroomUser.php.

143 {
144 $firstname = $this->user->getFirstname();
145
146 return $firstname[0] . '. ' . $this->user->getLastname();
147 }

References user().

Referenced by getChatNameSuggestions().

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

◆ buildUniqueUsername()

ilChatroomUser::buildUniqueUsername (   $username)
Parameters
string$username
Returns
string

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

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

References $DIC, $index, and $username.

◆ getChatNameSuggestions()

ilChatroomUser::getChatNameSuggestions ( )

Returns an array of chat-name suggestions.

Returns
array

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

96 {
97 $options = array();
98
99 if ($this->user->isAnonymous()) {
100 $options['anonymousName'] = $this->buildAnonymousName();
101 } else {
102 $options['fullname'] = $this->buildFullname();
103 $options['shortname'] = $this->buildShortname();
104 $options['login'] = $this->buildLogin();
105 }
106
107 return $options;
108 }
buildFullname()
Returns users first & lastname.
buildAnonymousName()
Returns an anonymous username containing a random number.
buildShortname()
Returns first letter of users firstname, followed by dot lastname.
buildLogin()
Returns user login.

References buildAnonymousName(), buildFullname(), buildLogin(), buildShortname(), and 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.

Parameters
ilObjUser$user
Returns
integer

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

49 {
50 $user_id = $this->user->getId();
51
52 if ($this->user->isAnonymous()) {
53 if (isset($_SESSION['chat'][$this->room->getRoomId()]['user_id'])) {
54 return $_SESSION['chat'][$this->room->getRoomId()]['user_id'];
55 } else {
56 $user_id = mt_rand(-99999, -20);
57 $_SESSION['chat'][$this->room->getRoomId()]['user_id'] = $user_id;
58 return $user_id;
59 }
60 } else {
61 return $user_id;
62 }
63 }
$_SESSION["AccountId"]

References $_SESSION, and user().

Referenced by ilChatroom\addPrivateRoom(), ilChatroom\connectUser(), ilChatroom\getLastSession(), ilObjChatroom\getPersonalInformation(), 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
array$usrIds
int | null$roomId
Returns
array

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

195 : array
196 {
197 global $DIC;
198
199 $users = [];
200
201 $query = '
202 SELECT userdata
203 FROM chatroom_users WHERE ' . $DIC->database()->in('user_id', $usrIds, false, 'integer');
204
205 if (null !== $roomId) {
206 $query .= ' AND room_id = ' . $DIC->database()->quote($roomId, 'integer');
207 }
208
209 $res = $DIC->database()->query($query);
210 while ($row = $DIC->database()->fetchAssoc($res)) {
211 $users[] = json_decode($row['userdata']);
212 }
213
214 return $users;
215 }
$query
foreach($_POST as $key=> $value) $res

References $DIC, $query, and $res.

Referenced by ilChatroomServerHandler\disconnectedUsers().

+ Here is the caller graph for this function:

◆ 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 70 of file class.ilChatroomUser.php.

71 {
72 if ($this->username) {
73 return $this->username;
74 } elseif ($_SESSION['chat'][$this->room->getRoomId()]['username']) {
75 return $_SESSION['chat'][$this->room->getRoomId()]['username'];
76 } else {
77 return $this->user->getLogin();
78 }
79 }

References $_SESSION, $username, and user().

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

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

◆ setUsername()

ilChatroomUser::setUsername (   $username)

Sets and stores given username in SESSION.

Parameters
string$username

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

86 {
87 $this->username = htmlspecialchars($username);
88 $_SESSION['chat'][$this->room->getRoomId()]['username'] = $this->username;
89 }

References $_SESSION, and $username.

Field Documentation

◆ $room

ilChatroomUser::$room
private

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

◆ $user

ilChatroomUser::$user
private

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

Referenced by __construct().

◆ $username

ilChatroomUser::$username
private

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

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


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