ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilChatroomUser Class Reference

Class ilChatroomUser. More...

+ Collaboration diagram for ilChatroomUser:

Public Member Functions

 __construct (private readonly ilObjUser $user, private readonly ilChatroom $room)
 
 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

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 ( private readonly ilObjUser  $user,
private readonly ilChatroom  $room 
)

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

32  {
33  }

Member Function Documentation

◆ buildAnonymousName()

ilChatroomUser::buildAnonymousName ( )

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

Referenced by getChatNameSuggestions().

116  : string
117  {
118  return str_replace(
119  '#',
120  (string) random_int(0, 10000),
121  $this->room->getSetting('autogen_usernames')
122  );
123  }
+ Here is the caller graph for this function:

◆ buildFullname()

ilChatroomUser::buildFullname ( )

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

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

125  : string
126  {
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);
131 
132  return $public_name;
133  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildLogin()

ilChatroomUser::buildLogin ( )

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

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

145  : string
146  {
147  return $this->user->getLogin();
148  }
+ 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.

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

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

138  : string
139  {
140  $firstname = $this->user->getFirstname();
141 
142  return $firstname[0] . '. ' . $this->user->getLastname();
143  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildUniqueUsername()

ilChatroomUser::buildUniqueUsername ( string  $username)

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

References $DIC, and $username.

150  : string
151  {
152  global $DIC;
153 
154  $username = htmlspecialchars(trim($username));
155  $usernames = [];
156  $uniqueName = $username;
157 
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')
162  );
163 
164  while (($row = $DIC->database()->fetchAssoc($rset))) {
165  $json = json_decode($row['userdata'], true, 512, JSON_THROW_ON_ERROR);
166  $usernames[] = $json['login'];
167  }
168 
169  for ($index = 1, $indexMax = count($usernames); $index <= $indexMax; $index++) {
170  if (in_array($uniqueName, $usernames, true)) {
171  $uniqueName = sprintf('%s_%d', $username, $index);
172  }
173  }
174 
175  return $uniqueName;
176  }
global $DIC
Definition: feed.php:28

◆ enabledBroadcastTyping()

ilChatroomUser::enabledBroadcastTyping ( )

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

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

Referenced by ilChatroomViewGUI\showRoom().

35  : bool
36  {
37  return ilUtil::yn2tf((string) $this->user->getPref('chat_broadcast_typing'));
38  }
static yn2tf(string $a_yn)
+ 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 101 of file class.ilChatroomUser.php.

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

Referenced by ilChatroomViewGUI\showNameSelection().

101  : array
102  {
103  $options = [];
104 
105  if ($this->user->isAnonymous()) {
106  $options['anonymousName'] = $this->buildAnonymousName();
107  } else {
108  $options['fullname'] = $this->buildFullname();
109  $options['shortname'] = $this->buildShortname();
110  $options['login'] = $this->buildLogin();
111  }
112 
113  return $options;
114  }
buildShortname()
Returns first letter of users firstname, followed by dot lastname.
+ 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.

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

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

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

44  : int
45  {
46  $user_id = $this->user->getId();
47 
48  if ($this->user->isAnonymous()) {
49  $session = ilSession::get('chat');
50  if (isset($session[$this->room->getRoomId()]['user_id'])) {
51  return $session[$this->room->getRoomId()]['user_id'];
52  }
53 
54  $user_id = random_int(-99999, -20);
55 
56  $session[$this->room->getRoomId()]['user_id'] = $user_id;
57  ilSession::set('chat', $session);
58  }
59 
60  return $user_id;
61  }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
+ 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

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

References $DIC, and $res.

Referenced by ilChatroomViewGUI\lostConnection().

181  : array
182  {
183  global $DIC;
184 
185  $users = [];
186 
187  $query = '
188  SELECT userdata
189  FROM chatroom_users WHERE ' . $DIC->database()->in('user_id', $usrIds, false, 'integer');
190 
191  if (null !== $roomId) {
192  $query .= ' AND room_id = ' . $DIC->database()->quote($roomId, 'integer');
193  }
194 
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);
198  }
199 
200  return $users;
201  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ 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.

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

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

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

67  : string
68  {
69  if ($this->username) {
70  return $this->username;
71  }
72 
73  $session = ilSession::get('chat');
74  if (
75  is_array($session) &&
76  isset($session[$this->room->getRoomId()]['username']) &&
77  $session[$this->room->getRoomId()]['username']
78  ) {
79  return $session[$this->room->getRoomId()]['username'];
80  }
81 
82  return $this->user->getLogin();
83  }
static get(string $a_var)
+ 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.

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

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

88  : void
89  {
90  $this->username = htmlspecialchars($username);
91 
92  $session = ilSession::get('chat');
93  $session[$this->room->getRoomId()]['username'] = $this->username;
94  ilSession::set('chat', $session);
95  }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

Field Documentation

◆ $username

string ilChatroomUser::$username = ''
private

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

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


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