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

Class ilChatroom. More...

+ Collaboration diagram for ilChatroom:

Public Member Functions

 initialize (array $rowdata)
 Sets $this->roomId by given array $rowdata and calls setSetting method foreach available setting in $this->availableSettings. More...
 
 setSetting (string $name, $value)
 Sets given name and value as setting into $this->settings array. More...
 
 getDescription ()
 
 getSetting (string $name)
 
 save ()
 
 saveSettings (array $settings)
 
 addHistoryEntry ($message)
 
 connectUser (ilChatroomUser $user)
 
 getConnectedUsers (bool $only_data=true)
 
 disconnectUser (int $user_id)
 
 disconnectUsers (array $userIds)
 
 getSettings ()
 
 isSubscribed (int $chat_userid)
 
 getHistory (ilDateTime $from=null, ilDateTime $to=null, int $restricted_session_userid=null, bool $respect_target=true)
 
 getRoomId ()
 
 saveFileUploadToDb (int $user_id, string $filename, string $type)
 
 banUser (int $user_id, int $actor_id, string $comment='')
 
 unbanUser ($user_id)
 Deletes entry from banTable matching roomId and given $user_id and returns the number of affected rows. More...
 
 isUserBanned (int $user_id)
 
 getBannedUsers ()
 
 getLastSession (ilChatroomUser $user)
 
 getSessions (ilChatroomUser $user)
 
 getChatURL (ilChatroomObjectGUI $gui)
 
 getTitle ()
 
 countActiveUsers ()
 
 getAccessibleRoomIdByTitleMap (int $user_id)
 Fetches and returns a Array<Integer, String> of all accessible repository object chats in the main tree. More...
 
 getRefIdByRoomId (int $room_id)
 
 getLastMessages (int $number, ilChatroomUser $chatuser)
 
 clearMessages ()
 

Static Public Member Functions

static checkUserPermissions ($permissions, int $ref_id, bool $send_info=true)
 Checks user permissions by given array and ref_id. More...
 
static checkPermissionsOfUser (int $usr_id, $permissions, int $ref_id)
 Checks user permissions in question for a given user id in relation to a given ref_id. More...
 
static byObjectId (int $object_id)
 
static byRoomId (int $room_id, bool $initObject=false)
 

Data Fields

const ROOM_INVITATION = 'invitation_to_room'
 

Static Protected Member Functions

static checkPermissions (int $usr_id, int $ref_id, array $permissions)
 

Private Member Functions

 phpTypeToMDBType (string $type)
 

Private Attributes

array $settings = []
 
array $availableSettings
 
array int $roomId = 0
 
ilObjChatroom $object = null
 

Static Private Attributes

static string $settingsTable = 'chatroom_settings'
 
static string $historyTable = 'chatroom_history'
 
static string $userTable = 'chatroom_users'
 
static string $sessionTable = 'chatroom_sessions'
 
static string $banTable = 'chatroom_bans'
 
static string $uploadTable = 'chatroom_uploads'
 

Detailed Description

Class ilChatroom.

Author
Jan Posselt jposs.nosp@m.elt@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

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

Member Function Documentation

◆ addHistoryEntry()

ilChatroom::addHistoryEntry (   $message)
Parameters
string | array | stdClass$message

Definition at line 268 of file class.ilChatroom.php.

References $DIC, $id, $message, $timestamp, ILIAS\Repository\int(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

268  : void
269  {
270  global $DIC;
271 
272  $timestamp = 0;
273  if (is_array($message)) {
274  $timestamp = (int) $message['timestamp'];
275  } elseif (is_object($message)) {
276  $timestamp = (int) $message->timestamp;
277  }
278 
279  $id = $DIC->database()->nextId(self::$historyTable);
280  $DIC->database()->insert(
281  self::$historyTable,
282  [
283  'hist_id' => [ilDBConstants::T_INTEGER, $id],
284  'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
285  'message' => [ilDBConstants::T_TEXT, json_encode($message, JSON_THROW_ON_ERROR)],
286  'timestamp' => [ilDBConstants::T_INTEGER, ($timestamp > 0 ? $timestamp : time())],
287  ]
288  );
289  }
global $DIC
Definition: feed.php:28
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ banUser()

ilChatroom::banUser ( int  $user_id,
int  $actor_id,
string  $comment = '' 
)

Definition at line 493 of file class.ilChatroom.php.

References $comment, $DIC, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

493  : void
494  {
495  global $DIC;
496 
497  $DIC->database()->replace(
498  self::$banTable,
499  [
500  'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
501  'user_id' => [ilDBConstants::T_INTEGER, $user_id]
502  ],
503  [
504  'actor_id' => [ilDBConstants::T_INTEGER, $actor_id],
505  'timestamp' => [ilDBConstants::T_INTEGER, time()],
506  'remark' => [ilDBConstants::T_TEXT, $comment]
507  ]
508  );
509  }
global $DIC
Definition: feed.php:28
$comment
Definition: buildRTE.php:72

◆ byObjectId()

static ilChatroom::byObjectId ( int  $object_id)
static

Definition at line 131 of file class.ilChatroom.php.

References $DIC, and ilDBConstants\T_INTEGER.

Referenced by ilChatroomXMLWriter\__construct(), ilChatroomXMLParser\__construct(), ilChatroomBanGUI\active(), ilObjChatroomGUI\afterImport(), ilChatroomHistoryGUI\byDay(), ilChatroomHistoryGUI\bySession(), ilObjChatroom\cloneObject(), ilChatroomBanGUI\delete(), ilChatroomViewGUI\executeDefault(), ilChatroomSettingsGUI\general(), ilObjChatroomListGUI\getProperties(), ilChatroomGUIHandler\getRoomByObjectId(), ilChatroomTabGUIFactory\getTabsForCommand(), ilChatroomInviteUsersToPrivateRoomGUI\inviteById(), ilChatroomViewGUI\joinWithCustomName(), ilChatroomViewGUI\lostConnection(), ilChatroomKickGUI\main(), ilChatroomCreateGUI\save(), ilChatroomSettingsGUI\saveGeneral(), ilChatroomBanGUI\show(), and ilChatroomViewGUI\toggleAutoMessageDisplayState().

131  : ?ilChatroom
132  {
133  global $DIC;
134 
135  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE object_id = %s';
136  $types = [ilDBConstants::T_INTEGER];
137  $values = [$object_id];
138  $rset = $DIC->database()->queryF($query, $types, $values);
139 
140  if ($row = $DIC->database()->fetchAssoc($rset)) {
141  $room = new self();
142  $room->initialize($row);
143  return $room;
144  }
145 
146  return null;
147  }
global $DIC
Definition: feed.php:28
Class ilChatroom.
+ Here is the caller graph for this function:

◆ byRoomId()

static ilChatroom::byRoomId ( int  $room_id,
bool  $initObject = false 
)
static

Definition at line 174 of file class.ilChatroom.php.

References $DIC, ilObjectFactory\getInstanceByObjId(), and ilDBConstants\T_INTEGER.

Referenced by ilContactGUI\inviteToChat(), and ilContactGUI\submitInvitation().

174  : ?ilChatroom
175  {
176  global $DIC;
177 
178  $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE room_id = %s';
179 
180  $types = [ilDBConstants::T_INTEGER];
181  $values = [$room_id];
182 
183  $rset = $DIC->database()->queryF($query, $types, $values);
184 
185  if ($row = $DIC->database()->fetchAssoc($rset)) {
186  $room = new self();
187  $room->initialize($row);
188 
189  if ($initObject) {
190  $room->object = ilObjectFactory::getInstanceByObjId((int) $row['object_id']);
191  }
192 
193  return $room;
194  }
195 
196  return null;
197  }
global $DIC
Definition: feed.php:28
Class ilChatroom.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPermissions()

static ilChatroom::checkPermissions ( int  $usr_id,
int  $ref_id,
array  $permissions 
)
staticprotected
Parameters
string[]$permissions

Definition at line 101 of file class.ilChatroom.php.

References $DIC, ilObjChatroom\_getPublicRefId(), ilObjectAccess\_isOffline(), and ilObject\_lookupObjId().

101  : bool
102  {
103  global $DIC;
104 
105  $pub_ref_id = ilObjChatroom::_getPublicRefId();
106 
107  if ($pub_ref_id === $ref_id) {
108  $obj_id = ilObject::_lookupObjId($ref_id);
109  foreach ($permissions as $permission) {
110  $no_access = !$DIC->rbac()->system()->checkAccessOfUser($usr_id, $permission, $ref_id) || (
111  !$DIC->rbac()->system()->checkAccessOfUser($usr_id, 'write', $ref_id) &&
113  in_array($permission, ['read', 'visible'], true)
114  );
115 
116  if ($no_access) {
117  return false;
118  }
119  }
120  } else {
121  foreach ($permissions as $permission) {
122  if (!$DIC->access()->checkAccessOfUser($usr_id, $permission, '', $ref_id)) {
123  return false;
124  }
125  }
126  }
127 
128  return true;
129  }
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static _isOffline(int $obj_id)
Type-specific implementation of general status, has to be overwritten if object type does not support...
+ Here is the call graph for this function:

◆ checkPermissionsOfUser()

static ilChatroom::checkPermissionsOfUser ( int  $usr_id,
  $permissions,
int  $ref_id 
)
static

Checks user permissions in question for a given user id in relation to a given ref_id.

Parameters
string|string[]$permissions

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

Referenced by ilObjChatroomGUI\executeCommand(), and ilContactGUI\submitInvitation().

89  : bool
90  {
91  if (!is_array($permissions)) {
92  $permissions = [$permissions];
93  }
94 
95  return self::checkPermissions($usr_id, $ref_id, $permissions);
96  }
$ref_id
Definition: ltiauth.php:67
+ Here is the caller graph for this function:

◆ checkUserPermissions()

static ilChatroom::checkUserPermissions (   $permissions,
int  $ref_id,
bool  $send_info = true 
)
static

Checks user permissions by given array and ref_id.

Parameters
string|string[]$permissions

Definition at line 65 of file class.ilChatroom.php.

References $DIC, and $ref_id.

Referenced by ilObjChatroomAccess\_checkGoto(), ilObjChatroomGUI\_goto(), ilChatroomTabGUIFactory\buildTabs(), ilChatroomInfoGUI\executeDefault(), ilChatroomSettingsGUI\general(), ilChatroomGUIHandler\hasPermission(), ilChatroomGUIHandler\redirectIfNoPermission(), ilChatroomAdminViewGUI\saveClientSettings(), and ilChatroomViewGUI\showRoom().

65  : bool
66  {
67  global $DIC;
68  $main_tpl = $DIC->ui()->mainTemplate();
69 
70  if (!is_array($permissions)) {
71  $permissions = [$permissions];
72  }
73 
74  $hasPermissions = self::checkPermissions($DIC->user()->getId(), $ref_id, $permissions);
75  if (!$hasPermissions && $send_info) {
76  $main_tpl->setOnScreenMessage('failure', $DIC->language()->txt('permission_denied'), true);
77 
78  return false;
79  }
80 
81  return $hasPermissions;
82  }
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
+ Here is the caller graph for this function:

◆ clearMessages()

ilChatroom::clearMessages ( )

Definition at line 835 of file class.ilChatroom.php.

References $DIC, and ilDBConstants\T_INTEGER.

835  : void
836  {
837  global $DIC;
838 
839  $DIC->database()->queryF(
840  'DELETE FROM ' . self::$historyTable . ' WHERE room_id = %s',
842  [$this->roomId]
843  );
844 
845  $DIC->database()->queryF(
846  'DELETE FROM ' . self::$sessionTable . ' WHERE room_id = %s AND disconnected < %s',
848  [$this->roomId, time()]
849  );
850  }
global $DIC
Definition: feed.php:28

◆ connectUser()

ilChatroom::connectUser ( ilChatroomUser  $user)

Definition at line 291 of file class.ilChatroom.php.

References $DIC, $roomId, ilChatroomUser\getUserId(), ilChatroomUser\getUsername(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ilChatroomViewGUI\showRoom().

291  : bool
292  {
293  global $DIC;
294 
295  $userdata = [
296  'login' => $user->getUsername(),
297  'id' => $user->getUserId()
298  ];
299 
300  $query = 'SELECT user_id FROM ' . self::$userTable . ' WHERE room_id = %s AND user_id = %s';
302  $values = [$this->roomId, $user->getUserId()];
303 
304  if (!$DIC->database()->fetchAssoc($DIC->database()->queryF($query, $types, $values))) {
305  // Notice: Using replace instead of insert looks strange, because we actually know whether the selected data exists or not
306  // But we occasionally found some duplicate key errors although the data set should not exist when the following code is reached
307  $DIC->database()->replace(
308  self::$userTable,
309  [
310  'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
311  'user_id' => [ilDBConstants::T_INTEGER, $user->getUserId()]
312  ],
313  [
314  'userdata' => [ilDBConstants::T_TEXT, json_encode($userdata, JSON_THROW_ON_ERROR)],
315  'connected' => [ilDBConstants::T_INTEGER, time()],
316  ]
317  );
318 
319  return true;
320  }
321 
322  return false;
323  }
getUserId()
Returns Ilias User ID.
global $DIC
Definition: feed.php:28
getUsername()
Returns username from Object or SESSION.
array int $roomId
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countActiveUsers()

ilChatroom::countActiveUsers ( )

Definition at line 693 of file class.ilChatroom.php.

References $DIC, $res, $roomId, and ilDBConstants\T_INTEGER.

693  : int
694  {
695  global $DIC;
696 
697  $query = 'SELECT COUNT(user_id) cnt FROM ' . self::$userTable . ' WHERE room_id = %s';
698  $types = [ilDBConstants::T_INTEGER];
699  $values = [$this->roomId];
700  $res = $DIC->database()->queryF($query, $types, $values);
701 
702  if ($row = $DIC->database()->fetchAssoc($res)) {
703  return (int) $row['cnt'];
704  }
705 
706  return 0;
707  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
array int $roomId

◆ disconnectUser()

ilChatroom::disconnectUser ( int  $user_id)

Definition at line 342 of file class.ilChatroom.php.

References disconnectUsers().

342  : void
343  {
344  $this->disconnectUsers([$user_id]);
345  }
disconnectUsers(array $userIds)
+ Here is the call graph for this function:

◆ disconnectUsers()

ilChatroom::disconnectUsers ( array  $userIds)
Parameters
int[]$userIds

Definition at line 350 of file class.ilChatroom.php.

References $DIC, $id, $res, $roomId, getSetting(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by disconnectUser().

350  : void
351  {
352  global $DIC;
353 
354  $query = 'SELECT * FROM ' . self::$userTable . ' WHERE room_id = %s AND ' .
355  $DIC->database()->in('user_id', $userIds, false, ilDBConstants::T_INTEGER);
356 
357  $types = [ilDBConstants::T_INTEGER];
358  $values = [$this->roomId];
359  $res = $DIC->database()->queryF($query, $types, $values);
360 
361  if ($row = $DIC->database()->fetchAssoc($res)) {
362  $query = 'DELETE FROM ' . self::$userTable . ' WHERE room_id = %s AND ' .
363  $DIC->database()->in('user_id', $userIds, false, ilDBConstants::T_INTEGER);
364 
365  $types = [ilDBConstants::T_INTEGER];
366  $values = [$this->roomId];
367  $DIC->database()->manipulateF($query, $types, $values);
368 
369  do {
370  if ($this->getSetting('enable_history')) {
371  $id = $DIC->database()->nextId(self::$sessionTable);
372  $DIC->database()->insert(
373  self::$sessionTable,
374  [
375  'sess_id' => [ilDBConstants::T_INTEGER, $id],
376  'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
377  'user_id' => [ilDBConstants::T_INTEGER, $row['user_id']],
378  'userdata' => [ilDBConstants::T_TEXT, $row['userdata']],
379  'connected' => [ilDBConstants::T_INTEGER, $row['connected']],
380  'disconnected' => [ilDBConstants::T_INTEGER, time()]
381  ]
382  );
383  }
384  } while ($row = $DIC->database()->fetchAssoc($res));
385  }
386  }
getSetting(string $name)
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
array int $roomId
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAccessibleRoomIdByTitleMap()

ilChatroom::getAccessibleRoomIdByTitleMap ( int  $user_id)

Fetches and returns a Array<Integer, String> of all accessible repository object chats in the main tree.

Returns
array<int, string>

Definition at line 713 of file class.ilChatroom.php.

References $DIC, $res, ILIAS\Repository\int(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

713  : array
714  {
715  global $DIC;
716 
717  $query = "
718  SELECT room_id, od.title, objr.ref_id
719  FROM object_data od
720  INNER JOIN " . self::$settingsTable . "
721  ON object_id = od.obj_id
722  INNER JOIN object_reference objr
723  ON objr.obj_id = od.obj_id
724  AND objr.deleted IS NULL
725  INNER JOIN tree
726  ON tree.child = objr.ref_id
727  AND tree.tree = %s
728  WHERE od.type = %s
729  ";
730 
732  $values = [1, 'chtr'];
733  $res = $DIC->database()->queryF($query, $types, $values);
734 
735  $rooms = [];
736  while ($row = $DIC->database()->fetchAssoc($res)) {
737  if (self::checkPermissionsOfUser($user_id, 'read', (int) $row['ref_id'])) {
738  $rooms[(int) $row['room_id']] = $row['title'];
739  }
740  }
741 
742  return $rooms;
743  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getBannedUsers()

ilChatroom::getBannedUsers ( )

Definition at line 544 of file class.ilChatroom.php.

References $DIC, $res, getRoomId(), ILIAS\Repository\int(), and ilDBConstants\T_INTEGER.

544  : array
545  {
546  global $DIC;
547 
548  $query = 'SELECT chb.* FROM ' . self::$banTable . ' chb INNER JOIN usr_data ud ON chb.user_id = ud.usr_id WHERE chb.room_id = %s ';
549  $types = [ilDBConstants::T_INTEGER];
550  $values = [$this->getRoomId()];
551  $res = $DIC->database()->queryF($query, $types, $values);
552  $result = [];
553 
554  while ($row = $DIC->database()->fetchAssoc($res)) {
555  if ($row['user_id'] > 0) {
556  $user = new ilObjUser((int) $row['user_id']);
557  $userdata = [
558  'user_id' => $user->getId(),
559  'firstname' => $user->getFirstname(),
560  'lastname' => $user->getLastname(),
561  'login' => $user->getLogin(),
562  'timestamp' => (int) $row['timestamp'],
563  'actor_id' => (int) $row['actor_id'],
564  'remark' => $row['remark']
565  ];
566 
567  $result[] = $userdata;
568  }
569  }
570 
571  return $result;
572  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getChatURL()

ilChatroom::getChatURL ( ilChatroomObjectGUI  $gui)

Definition at line 679 of file class.ilChatroom.php.

References ilLink\_getStaticLink(), and ilObjectGUI\getObject().

Referenced by getSessions().

679  : string
680  {
681  return ilLink::_getStaticLink($gui->getObject()->getRefId(), $gui->getObject()->getType());
682  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConnectedUsers()

ilChatroom::getConnectedUsers ( bool  $only_data = true)

Definition at line 325 of file class.ilChatroom.php.

References $DIC, $roomId, and ilDBConstants\T_INTEGER.

Referenced by ilChatroomViewGUI\showRoom().

325  : array
326  {
327  global $DIC;
328 
329  $query = 'SELECT ' . ($only_data ? 'userdata' : '*') . ' FROM ' . self::$userTable . ' WHERE room_id = %s';
330  $types = [ilDBConstants::T_INTEGER];
331  $values = [$this->roomId];
332  $rset = $DIC->database()->queryF($query, $types, $values);
333  $users = [];
334 
335  while ($row = $DIC->database()->fetchAssoc($rset)) {
336  $users[] = $only_data ? json_decode($row['userdata'], false, 512, JSON_THROW_ON_ERROR) : $row;
337  }
338 
339  return $users;
340  }
global $DIC
Definition: feed.php:28
array int $roomId
+ Here is the caller graph for this function:

◆ getDescription()

ilChatroom::getDescription ( )

Definition at line 199 of file class.ilChatroom.php.

References ilObjectFactory\getInstanceByObjId(), and getSetting().

199  : string
200  {
201  if (!$this->object) {
202  $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
203  }
204 
205  return $this->object->getDescription();
206  }
getSetting(string $name)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

◆ getHistory()

ilChatroom::getHistory ( ilDateTime  $from = null,
ilDateTime  $to = null,
int  $restricted_session_userid = null,
bool  $respect_target = true 
)

Definition at line 407 of file class.ilChatroom.php.

References $DIC, $message, getRoomId(), and ilDBConstants\T_INTEGER.

412  : array {
413  global $DIC;
414 
415  $join = '';
416 
417  $query =
418  'SELECT historyTable.* ' .
419  'FROM ' . self::$historyTable . ' historyTable ' . $join . ' ' .
420  'WHERE historyTable.room_id = ' . $this->getRoomId();
421 
422  $filter = [];
423 
424  if ($from !== null) {
425  $filter[] = 'timestamp >= ' . $DIC->database()->quote($from->getUnixTime(), ilDBConstants::T_INTEGER);
426  }
427 
428  if ($to !== null) {
429  $filter[] = 'timestamp <= ' . $DIC->database()->quote($to->getUnixTime(), ilDBConstants::T_INTEGER);
430  }
431 
432  if ($filter) {
433  $query .= ' AND ' . implode(' AND ', $filter);
434  }
435  $query .= ' ORDER BY timestamp ASC';
436 
437  $rset = $DIC->database()->query($query);
438  $result = [];
439 
440  while ($row = $DIC->database()->fetchAssoc($rset)) {
441  try {
442  $message = json_decode($row['message'], false, 512, JSON_THROW_ON_ERROR);
443  } catch (JsonException) {
444  $message = null;
445  } finally {
446  if ($message === null) {
447  $message = json_decode('{}', false, 512, JSON_THROW_ON_ERROR);
448  }
449  }
450 
451  $row['message'] = $message;
452  $row['message']->timestamp = $row['timestamp'];
453  if (
454  $respect_target &&
455  property_exists($row['message'], 'target') &&
456  $row['message']->target !== null &&
457  !$row['message']->target->public && (
458  !isset($row['recipients']) ||
459  !in_array($DIC->user()->getId(), explode(',', (string) $row['recipients']), false)
460  )
461  ) {
462  continue;
463  }
464 
465  $result[] = $row;
466  }
467  return $result;
468  }
global $DIC
Definition: feed.php:28
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ getLastMessages()

ilChatroom::getLastMessages ( int  $number,
ilChatroomUser  $chatuser 
)

Definition at line 772 of file class.ilChatroom.php.

References Vendor\Package\$a, Vendor\Package\$b, $DIC, $results, $roomId, ilChatroomUser\getUserId(), ILIAS\Repository\int(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ilChatroomViewGUI\showRoom().

772  : array
773  {
774  global $DIC;
775 
776  // There is currently no way to check if a message is private or not
777  // by sql. So we fetch twice as much as we need and hope that there
778  // are not more than $number private messages.
779  $DIC->database()->setLimit($number);
780  $rset = $DIC->database()->query(
781  'SELECT *
782  FROM ' . self::$historyTable . '
783  WHERE room_id = ' . $DIC->database()->quote($this->roomId, ilDBConstants::T_INTEGER) . '
784  AND (
785  (' . $DIC->database()->like('message', ilDBConstants::T_TEXT, '%"type":"message"%') . ' AND NOT ' . $DIC->database()->like('message', ilDBConstants::T_TEXT, '%"public":0%') . ')
786  OR ' . $DIC->database()->like('message', ilDBConstants::T_TEXT, '%"target":{%"id":"' . $chatuser->getUserId() . '"%') . '
787  OR ' . $DIC->database()->like('message', ilDBConstants::T_TEXT, '%"from":{"id":' . $chatuser->getUserId() . '%') . '
788  )
789  ORDER BY timestamp DESC'
790  );
791 
792  $result_count = 0;
793  $results = [];
794  while (($row = $DIC->database()->fetchAssoc($rset)) && $result_count < $number) {
795  $tmp = json_decode($row['message'], false, 512, JSON_THROW_ON_ERROR);
796  if (property_exists($tmp, 'target') && $tmp->target instanceof stdClass && (int) $tmp->target->public === 0) {
797  if (in_array($chatuser->getUserId(), [(int) $tmp->target->id, (int) $tmp->from->id], true)) {
798  $results[] = $tmp;
799  ++$result_count;
800  }
801  } else {
802  $results[] = $tmp;
803  ++$result_count;
804  }
805  }
806 
807  if ($results !== []) {
808  $rset = $DIC->database()->queryF(
809  'SELECT *
810  FROM ' . self::$historyTable . '
811  WHERE room_id = %s
812  AND ' . $DIC->database()->like('message', ilDBConstants::T_TEXT, '%%"type":"notice"%%') . '
813  AND timestamp <= %s AND timestamp >= %s
814  ORDER BY timestamp DESC',
816  [$this->roomId, $results[0]->timestamp, $results[$result_count - 1]->timestamp]
817  );
818 
819  while (($row = $DIC->database()->fetchAssoc($rset))) {
820  $tmp = json_decode($row['message'], false, 512, JSON_THROW_ON_ERROR);
821  $results[] = $tmp;
822  }
823  }
824 
825  usort($results, static function (stdClass $a, stdClass $b): int {
826  $a_timestamp = strlen((string) $a->timestamp) === 13 ? ((int) substr((string) $a->timestamp, 0, -3)) : $a->timestamp;
827  $b_timestamp = strlen((string) $b->timestamp) === 13 ? ((int) substr((string) $b->timestamp, 0, -3)) : $b->timestamp;
828 
829  return $b_timestamp - $a_timestamp;
830  });
831 
832  return $results;
833  }
getUserId()
Returns Ilias User ID.
global $DIC
Definition: feed.php:28
$results
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
array int $roomId
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastSession()

ilChatroom::getLastSession ( ilChatroomUser  $user)

Definition at line 574 of file class.ilChatroom.php.

References $DIC, $res, ilChatroomUser\getUserId(), and ilDBConstants\T_INTEGER.

574  : ?array
575  {
576  global $DIC;
577 
578  $query = 'SELECT * FROM ' . self::$sessionTable . ' WHERE user_id = ' .
579  $DIC->database()->quote($user->getUserId(), ilDBConstants::T_INTEGER) .
580  ' ORDER BY connected DESC';
581 
582  $DIC->database()->setLimit(1);
583  $res = $DIC->database()->query($query);
584 
585  if ($row = $DIC->database()->fetchAssoc($res)) {
586  return $row;
587  }
588 
589  return null;
590  }
$res
Definition: ltiservices.php:69
getUserId()
Returns Ilias User ID.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getRefIdByRoomId()

ilChatroom::getRefIdByRoomId ( int  $room_id)

Definition at line 745 of file class.ilChatroom.php.

References $DIC, $res, and ilDBConstants\T_INTEGER.

Referenced by getSessions().

745  : int
746  {
747  global $DIC;
748 
749  $query = "
750  SELECT objr.ref_id
751  FROM object_reference objr
752 
753  INNER JOIN chatroom_settings cs
754  ON cs.object_id = objr.obj_id
755 
756  INNER JOIN object_data od
757  ON od.obj_id = cs.object_id
758 
759  WHERE cs.room_id = %s
760  ";
761 
762  $types = [ilDBConstants::T_INTEGER];
763  $values = [$room_id];
764 
765  $res = $DIC->database()->queryF($query, $types, $values);
766 
767  $row = $DIC->database()->fetchAssoc($res);
768 
769  return (int) ($row['ref_id'] ?? 0);
770  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getRoomId()

ilChatroom::getRoomId ( )

Definition at line 470 of file class.ilChatroom.php.

References $roomId.

Referenced by getBannedUsers(), getHistory(), getSessions(), isUserBanned(), ilChatroomViewGUI\showRoom(), and unbanUser().

470  : int
471  {
472  return $this->roomId;
473  }
array int $roomId
+ Here is the caller graph for this function:

◆ getSessions()

ilChatroom::getSessions ( ilChatroomUser  $user)

Definition at line 592 of file class.ilChatroom.php.

References $DIC, $res, ilLanguageFactory\_getLanguageOfUser(), ANONYMOUS_USER_ID, getChatURL(), ilObjectFactory\getInstanceByObjId(), getRefIdByRoomId(), getRoomId(), ilMail\getSalutation(), getTitle(), and ilDBConstants\T_INTEGER.

592  : array
593  {
594  global $DIC;
595 
596  $query = 'SELECT * FROM ' . self::$sessionTable
597  . ' WHERE room_id = ' .
598  $DIC->database()->quote($this->getRoomId(), ilDBConstants::T_INTEGER) .
599  ' ORDER BY connected DESC';
600 
601  $res = $DIC->database()->query($query);
602 
603  $result = [];
604  while ($row = $DIC->database()->fetchAssoc($res)) {
605  $result[] = $row;
606  }
607 
608  return $result;
609  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getSetting()

ilChatroom::getSetting ( string  $name)

Definition at line 208 of file class.ilChatroom.php.

References ILIAS\Repository\settings().

Referenced by disconnectUsers(), getDescription(), getTitle(), and ilChatroomViewGUI\showRoom().

209  {
210  return $this->settings[$name];
211  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroom::getSettings ( )

Definition at line 388 of file class.ilChatroom.php.

References $settings.

388  : array
389  {
390  return $this->settings;
391  }

◆ getTitle()

ilChatroom::getTitle ( )

Definition at line 684 of file class.ilChatroom.php.

References ilObjectFactory\getInstanceByObjId(), and getSetting().

Referenced by getSessions().

684  : string
685  {
686  if (!$this->object) {
687  $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
688  }
689 
690  return $this->object->getTitle();
691  }
getSetting(string $name)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize()

ilChatroom::initialize ( array  $rowdata)

Sets $this->roomId by given array $rowdata and calls setSetting method foreach available setting in $this->availableSettings.

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

References ILIAS\Repository\int(), and setSetting().

153  : void
154  {
155  $this->roomId = (int) $rowdata['room_id'];
156 
157  foreach ($this->availableSettings as $setting => $type) {
158  if (isset($rowdata[$setting])) {
159  settype($rowdata[$setting], $this->availableSettings[$setting]);
160  $this->setSetting($setting, $rowdata[$setting]);
161  }
162  }
163  }
setSetting(string $name, $value)
Sets given name and value as setting into $this->settings array.
+ Here is the call graph for this function:

◆ isSubscribed()

ilChatroom::isSubscribed ( int  $chat_userid)

Definition at line 393 of file class.ilChatroom.php.

References $DIC, $res, $roomId, and ilDBConstants\T_INTEGER.

Referenced by ilChatroomViewGUI\showRoom().

393  : bool
394  {
395  global $DIC;
396 
397  $query = 'SELECT COUNT(user_id) as cnt FROM ' . self::$userTable .
398  ' WHERE room_id = %s AND user_id = %s';
399 
401  $values = [$this->roomId, $chat_userid];
402  $res = $DIC->database()->queryF($query, $types, $values);
403 
404  return ($row = $DIC->database()->fetchAssoc($res)) && (int) $row['cnt'] === 1;
405  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
array int $roomId
+ Here is the caller graph for this function:

◆ isUserBanned()

ilChatroom::isUserBanned ( int  $user_id)

Definition at line 531 of file class.ilChatroom.php.

References $DIC, $res, getRoomId(), and ilDBConstants\T_INTEGER.

Referenced by ilChatroomViewGUI\showRoom().

531  : bool
532  {
533  global $DIC;
534 
535  $query = 'SELECT COUNT(user_id) cnt FROM ' . self::$banTable . ' WHERE user_id = %s AND room_id = %s';
537  $values = [$user_id, $this->getRoomId()];
538 
539  $res = $DIC->database()->queryF($query, $types, $values);
540 
541  return ($row = $DIC->database()->fetchAssoc($res)) && $row['cnt'];
542  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phpTypeToMDBType()

ilChatroom::phpTypeToMDBType ( string  $type)
private

Definition at line 256 of file class.ilChatroom.php.

References ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by saveSettings().

256  : string
257  {
258  return match ($type) {
259  'string' => ilDBConstants::T_TEXT,
260  'boolean' => ilDBConstants::T_INTEGER,
261  default => $type,
262  };
263  }
+ Here is the caller graph for this function:

◆ save()

ilChatroom::save ( )

Definition at line 213 of file class.ilChatroom.php.

References saveSettings(), and ILIAS\Repository\settings().

213  : void
214  {
215  $this->saveSettings($this->settings);
216  }
saveSettings(array $settings)
+ Here is the call graph for this function:

◆ saveFileUploadToDb()

ilChatroom::saveFileUploadToDb ( int  $user_id,
string  $filename,
string  $type 
)

Definition at line 475 of file class.ilChatroom.php.

References $DIC, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

475  : void
476  {
477  global $DIC;
478 
479  $upload_id = $DIC->database()->nextId(self::$uploadTable);
480  $DIC->database()->insert(
481  self::$uploadTable,
482  [
483  'upload_id' => [ilDBConstants::T_INTEGER, $upload_id],
484  'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
485  'user_id' => [ilDBConstants::T_INTEGER, $user_id],
486  'filename' => [ilDBConstants::T_TEXT, $filename],
487  'filetype' => [ilDBConstants::T_TEXT, $type],
488  'timestamp' => [ilDBConstants::T_INTEGER, time()]
489  ]
490  );
491  }
global $DIC
Definition: feed.php:28
$filename
Definition: buildRTE.php:78

◆ saveSettings()

ilChatroom::saveSettings ( array  $settings)

Definition at line 218 of file class.ilChatroom.php.

References $DIC, $roomId, phpTypeToMDBType(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by save().

218  : void
219  {
220  global $DIC;
221 
222  $localSettings = [];
223 
224  foreach ($this->availableSettings as $setting => $type) {
225  if (array_key_exists($setting, $settings)) {
226  if ($type === 'boolean') {
227  $settings[$setting] = (bool) $settings[$setting];
228  }
229  $localSettings[$setting] = [$this->phpTypeToMDBType($type), $settings[$setting]];
230  }
231  }
232 
233  if (!isset($localSettings['room_type']) || !$localSettings['room_type'][1]) {
234  $localSettings['room_type'][0] = ilDBConstants::T_TEXT;
235  $localSettings['room_type'][1] = 'repository';
236  }
237 
238  if ($this->roomId > 0) {
239  $DIC->database()->update(
240  self::$settingsTable,
241  $localSettings,
242  ['room_id' => [ilDBConstants::T_INTEGER, $this->roomId]]
243  );
244  } else {
245  $this->roomId = $DIC->database()->nextId(self::$settingsTable);
246 
247  $localSettings['room_id'] = [
250  ];
251 
252  $DIC->database()->insert(self::$settingsTable, $localSettings);
253  }
254  }
phpTypeToMDBType(string $type)
global $DIC
Definition: feed.php:28
array int $roomId
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSetting()

ilChatroom::setSetting ( string  $name,
  $value 
)

Sets given name and value as setting into $this->settings array.

Parameters
mixed$value

Definition at line 169 of file class.ilChatroom.php.

References ILIAS\Repository\settings().

Referenced by initialize().

169  : void
170  {
171  $this->settings[$name] = $value;
172  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unbanUser()

ilChatroom::unbanUser (   $user_id)

Deletes entry from banTable matching roomId and given $user_id and returns the number of affected rows.

Parameters
int|int[]$user_id

Definition at line 516 of file class.ilChatroom.php.

References $DIC, getRoomId(), and ilDBConstants\T_INTEGER.

516  : int
517  {
518  global $DIC;
519 
520  if (!is_array($user_id)) {
521  $user_id = [$user_id];
522  }
523 
524  $query = 'DELETE FROM ' . self::$banTable . ' WHERE room_id = %s AND ' . $DIC->database()->in('user_id', $user_id, false, ilDBConstants::T_INTEGER);
525  $types = [ilDBConstants::T_INTEGER];
526  $values = [$this->getRoomId()];
527 
528  return $DIC->database()->manipulateF($query, $types, $values);
529  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Field Documentation

◆ $availableSettings

array ilChatroom::$availableSettings
private
Initial value:
= [
'object_id' => 'integer'

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

◆ $banTable

string ilChatroom::$banTable = 'chatroom_bans'
staticprivate

Definition at line 40 of file class.ilChatroom.php.

◆ $historyTable

string ilChatroom::$historyTable = 'chatroom_history'
staticprivate

Definition at line 37 of file class.ilChatroom.php.

◆ $object

ilObjChatroom ilChatroom::$object = null
private

Definition at line 59 of file class.ilChatroom.php.

◆ $roomId

array int ilChatroom::$roomId = 0
private

◆ $sessionTable

string ilChatroom::$sessionTable = 'chatroom_sessions'
staticprivate

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

◆ $settings

array ilChatroom::$settings = []
private

Definition at line 42 of file class.ilChatroom.php.

Referenced by getSettings().

◆ $settingsTable

string ilChatroom::$settingsTable = 'chatroom_settings'
staticprivate

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

◆ $uploadTable

string ilChatroom::$uploadTable = 'chatroom_uploads'
staticprivate

Definition at line 41 of file class.ilChatroom.php.

◆ $userTable

string ilChatroom::$userTable = 'chatroom_users'
staticprivate

Definition at line 38 of file class.ilChatroom.php.

◆ ROOM_INVITATION

const ilChatroom::ROOM_INVITATION = 'invitation_to_room'

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


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