ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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...
 
 isProfilePictureVisible ()
 
 setProfilePictureVisible (bool $show_it)
 
 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 = ''
 
bool $profile_picture_visible = null
 

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

33  {
34  }

Member Function Documentation

◆ buildAnonymousName()

ilChatroomUser::buildAnonymousName ( )

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

Referenced by getChatNameSuggestions().

132  : string
133  {
134  return str_replace(
135  '#',
136  (string) random_int(0, 10000),
137  $this->room->getSetting('autogen_usernames')
138  );
139  }
+ Here is the caller graph for this function:

◆ buildFullname()

ilChatroomUser::buildFullname ( )

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

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

141  : string
142  {
143  $tmp = $this->user->getPref('public_profile');
144  $this->user->setPref('public_profile', 'y');
145  $public_name = $this->user->getPublicName();
146  $this->user->setPref('public_profile', $tmp);
147 
148  return $public_name;
149  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildLogin()

ilChatroomUser::buildLogin ( )

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

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

161  : string
162  {
163  return $this->user->getLogin();
164  }
+ 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 154 of file class.ilChatroomUser.php.

References ILIAS\Repository\user().

Referenced by getChatNameSuggestions().

154  : string
155  {
156  $firstname = $this->user->getFirstname();
157 
158  return $firstname[0] . '. ' . $this->user->getLastname();
159  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildUniqueUsername()

ilChatroomUser::buildUniqueUsername ( string  $username)

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

References $DIC, and $username.

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

◆ enabledBroadcastTyping()

ilChatroomUser::enabledBroadcastTyping ( )

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

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

Referenced by ilChatroomViewGUI\showRoom().

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

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

Referenced by ilChatroomViewGUI\showNameSelection().

117  : array
118  {
119  $options = [];
120 
121  if ($this->user->isAnonymous()) {
122  $options['anonymousName'] = $this->buildAnonymousName();
123  } else {
124  $options['fullname'] = $this->buildFullname();
125  $options['shortname'] = $this->buildShortname();
126  $options['login'] = $this->buildLogin();
127  }
128 
129  return $options;
130  }
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 45 of file class.ilChatroomUser.php.

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

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

45  : int
46  {
47  $user_id = $this->user->getId();
48 
49  if ($this->user->isAnonymous()) {
50  $session = ilSession::get('chat');
51  if (isset($session[$this->room->getRoomId()]['user_id'])) {
52  return $session[$this->room->getRoomId()]['user_id'];
53  }
54 
55  $user_id = random_int(-99999, -20);
56 
57  $session[$this->room->getRoomId()]['user_id'] = $user_id;
58  ilSession::set('chat', $session);
59  }
60 
61  return $user_id;
62  }
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 197 of file class.ilChatroomUser.php.

References $DIC, $res, and null.

197  : array
198  {
199  global $DIC;
200 
201  $users = [];
202 
203  $query = '
204  SELECT userdata
205  FROM chatroom_users WHERE ' . $DIC->database()->in('user_id', $usrIds, false, 'integer');
206 
207  if (null !== $roomId) {
208  $query .= ' AND room_id = ' . $DIC->database()->quote($roomId, 'integer');
209  }
210 
211  $res = $DIC->database()->query($query);
212  while ($row = $DIC->database()->fetchAssoc($res)) {
213  $users[] = json_decode($row['userdata'], false, 512, JSON_THROW_ON_ERROR);
214  }
215 
216  return $users;
217  }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22

◆ getUsername()

ilChatroomUser::getUsername ( )

Returns username from Object or SESSION.

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

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

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

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

68  : string
69  {
70  if ($this->username) {
71  return $this->username;
72  }
73 
74  $session = ilSession::get('chat');
75  if (
76  is_array($session) &&
77  isset($session[$this->room->getRoomId()]['username']) &&
78  $session[$this->room->getRoomId()]['username']
79  ) {
80  return $session[$this->room->getRoomId()]['username'];
81  }
82 
83  return $this->user->getPublicName();
84  }
static get(string $a_var)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isProfilePictureVisible()

ilChatroomUser::isProfilePictureVisible ( )

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

References $profile_picture_visible, ilSession\get(), and null.

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

98  : bool
99  {
100  if ($this->profile_picture_visible === null) {
101  $this->profile_picture_visible = ilSession::get('chat')[$this->room->getRoomId()]['profile-picture-visible'] ?? false;
102  }
104  }
static get(string $a_var)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setProfilePictureVisible()

ilChatroomUser::setProfilePictureVisible ( bool  $show_it)

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

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

106  : void
107  {
108  $session = ilSession::get('chat');
109  $session[$this->room->getRoomId()]['profile-picture-visible'] = $show_it;
110  ilSession::set('chat', $session);
111  }
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ setUsername()

ilChatroomUser::setUsername ( string  $username)

Sets and stores given username in SESSION.

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

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

89  : void
90  {
91  $this->username = htmlspecialchars($username);
92 
93  $session = ilSession::get('chat');
94  $session[$this->room->getRoomId()]['username'] = $this->username;
95  ilSession::set('chat', $session);
96  }
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

◆ $profile_picture_visible

bool ilChatroomUser::$profile_picture_visible = null
private

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

Referenced by isProfilePictureVisible().

◆ $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: