ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 

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.

References $user, and user().

37  {
38  $this->user = $user;
39  $this->room = $chatroom;
40  }
user()
Definition: user.php:4
+ 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.

Referenced by getChatNameSuggestions().

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  }
+ 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.

References user().

Referenced by getChatNameSuggestions().

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  }
user()
Definition: user.php:4
+ 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.

References user().

Referenced by getChatNameSuggestions().

154  {
155  return $this->user->getLogin();
156  }
user()
Definition: user.php:4
+ 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.

References user().

Referenced by getChatNameSuggestions().

143  {
144  $firstname = $this->user->getFirstname();
145 
146  return $firstname{0} . '. ' . $this->user->getLastname();
147  }
user()
Definition: user.php:4
+ 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.

References $DIC, $index, $row, $username, and array.

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: saml.php:7
$index
Definition: metadata.php:60
Create styles array
The data for the language used.

◆ getChatNameSuggestions()

ilChatroomUser::getChatNameSuggestions ( )

Returns an array of chat-name suggestions.

Returns
array

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

References $options, array, buildAnonymousName(), buildFullname(), buildLogin(), buildShortname(), and user().

Referenced by ilChatroomViewGUI\renderFileUploadForm().

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  }
buildAnonymousName()
Returns an anonymous username containing a random number.
user()
Definition: user.php:4
buildFullname()
Returns users first & lastname.
buildShortname()
Returns first letter of users firstname, followed by dot lastname.
Create styles array
The data for the language used.
buildLogin()
Returns user login.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ 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.

References $_SESSION, and user().

Referenced by ilChatroom\addPrivateRoom(), ilChatroom\connectUser(), ilChatroom\getLastSession(), ilObjChatroom\getPersonalInformation(), and ilChatroomViewGUI\renderFileUploadForm().

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"]
user()
Definition: user.php:4
+ Here is the call graph for this function:
+ 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.

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

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

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  }
$_SESSION["AccountId"]
user()
Definition: user.php:4
+ 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.

References $_SESSION, and $username.

Referenced by ilChatroomViewGUI\renderFileUploadForm().

86  {
87  $this->username = htmlspecialchars($username);
88  $_SESSION['chat'][$this->room->getRoomId()]['username'] = $this->username;
89  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

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: