ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ()
 
 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
 
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'
 

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 266 of file class.ilChatroom.php.

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

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

+ Here is the call graph for this function:

◆ banUser()

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

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

474 : void
475 {
476 global $DIC;
477
478 $DIC->database()->replace(
479 self::$banTable,
480 [
481 'room_id' => [ilDBConstants::T_INTEGER, $this->roomId],
482 'user_id' => [ilDBConstants::T_INTEGER, $user_id]
483 ],
484 [
485 'actor_id' => [ilDBConstants::T_INTEGER, $actor_id],
486 'timestamp' => [ilDBConstants::T_INTEGER, time()],
487 'remark' => [ilDBConstants::T_TEXT, $comment]
488 ]
489 );
490 }
$comment
Definition: buildRTE.php:72

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

◆ byObjectId()

static ilChatroom::byObjectId ( int  $object_id)
static

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

129 : ?ilChatroom
130 {
131 global $DIC;
132
133 $query = 'SELECT * FROM ' . self::$settingsTable . ' WHERE object_id = %s';
134 $types = [ilDBConstants::T_INTEGER];
135 $values = [$object_id];
136 $rset = $DIC->database()->queryF($query, $types, $values);
137
138 if ($row = $DIC->database()->fetchAssoc($rset)) {
139 $room = new self();
140 $room->initialize($row);
141 return $room;
142 }
143
144 return null;
145 }
Class ilChatroom.

References $DIC, and ilDBConstants\T_INTEGER.

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

+ Here is the caller graph for this function:

◆ byRoomId()

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

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

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

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

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

+ 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 100 of file class.ilChatroom.php.

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

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

Referenced by checkPermissionsOfUser(), and checkUserPermissions().

+ Here is the call graph for this function:
+ Here is the caller 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 88 of file class.ilChatroom.php.

88 : bool
89 {
90 if (!is_array($permissions)) {
91 $permissions = [$permissions];
92 }
93
94 return self::checkPermissions($usr_id, $ref_id, $permissions);
95 }
static checkPermissions(int $usr_id, int $ref_id, array $permissions)

References $ref_id, and checkPermissions().

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

+ Here is the call graph for this function:
+ 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 64 of file class.ilChatroom.php.

64 : bool
65 {
66 global $DIC;
67 $main_tpl = $DIC->ui()->mainTemplate();
68
69 if (!is_array($permissions)) {
70 $permissions = [$permissions];
71 }
72
73 $hasPermissions = self::checkPermissions($DIC->user()->getId(), $ref_id, $permissions);
74 if (!$hasPermissions && $send_info) {
75 $main_tpl->setOnScreenMessage('failure', $DIC->language()->txt('permission_denied'), true);
76
77 return false;
78 }
79
80 return $hasPermissions;
81 }

References $DIC, $ref_id, and checkPermissions().

Referenced by ilObjChatroomAccess\_checkGoto(), ilObjChatroomGUI\_goto(), ilChatroomTabGUIFactory\buildTabs(), ilChatroomSettingsGUI\general(), ilChatroomGUIHandler\hasPermission(), ilObjChatroomGUI\infoScreen(), ilChatroomGUIHandler\redirectIfNoPermission(), ilChatroomSettingsGUI\saveGeneral(), and ilChatroomViewGUI\showRoom().

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

◆ clearMessages()

ilChatroom::clearMessages ( )

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

818 : void
819 {
820 global $DIC;
821
822 $DIC->database()->queryF(
823 'DELETE FROM ' . self::$historyTable . ' WHERE room_id = %s',
825 [$this->roomId]
826 );
827
828 $DIC->database()->queryF(
829 'DELETE FROM ' . self::$sessionTable . ' WHERE room_id = %s AND disconnected < %s',
831 [$this->roomId, time()]
832 );
833 }

References $DIC, and ilDBConstants\T_INTEGER.

◆ connectUser()

ilChatroom::connectUser ( ilChatroomUser  $user)

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

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

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

Referenced by ilChatroomViewGUI\showRoom().

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

◆ countActiveUsers()

ilChatroom::countActiveUsers ( )

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

674 : int
675 {
676 global $DIC;
677
678 $query = 'SELECT COUNT(user_id) cnt FROM ' . self::$userTable . ' WHERE room_id = %s';
679 $types = [ilDBConstants::T_INTEGER];
680 $values = [$this->roomId];
681 $res = $DIC->database()->queryF($query, $types, $values);
682
683 if ($row = $DIC->database()->fetchAssoc($res)) {
684 return (int) $row['cnt'];
685 }
686
687 return 0;
688 }
$res
Definition: ltiservices.php:69

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

◆ disconnectUser()

ilChatroom::disconnectUser ( int  $user_id)

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

341 : void
342 {
343 $this->disconnectUsers([$user_id]);
344 }
disconnectUsers(array $userIds)

References disconnectUsers().

+ Here is the call graph for this function:

◆ disconnectUsers()

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

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

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

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

Referenced by disconnectUser().

+ 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 694 of file class.ilChatroom.php.

694 : array
695 {
696 global $DIC;
697
698 $query = "
699 SELECT room_id, od.title, objr.ref_id
700 FROM object_data od
701 INNER JOIN " . self::$settingsTable . "
702 ON object_id = od.obj_id
703 INNER JOIN object_reference objr
704 ON objr.obj_id = od.obj_id
705 AND objr.deleted IS NULL
706 INNER JOIN tree
707 ON tree.child = objr.ref_id
708 AND tree.tree = %s
709 WHERE od.type = %s
710 ";
711
713 $values = [1, 'chtr'];
714 $res = $DIC->database()->queryF($query, $types, $values);
715
716 $rooms = [];
717 while ($row = $DIC->database()->fetchAssoc($res)) {
718 if (self::checkPermissionsOfUser($user_id, 'read', (int) $row['ref_id'])) {
719 $rooms[(int) $row['room_id']] = $row['title'];
720 }
721 }
722
723 return $rooms;
724 }

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

+ Here is the call graph for this function:

◆ getBannedUsers()

ilChatroom::getBannedUsers ( )

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

525 : array
526 {
527 global $DIC;
528
529 $query = 'SELECT chb.* FROM ' . self::$banTable . ' chb INNER JOIN usr_data ud ON chb.user_id = ud.usr_id WHERE chb.room_id = %s ';
530 $types = [ilDBConstants::T_INTEGER];
531 $values = [$this->getRoomId()];
532 $res = $DIC->database()->queryF($query, $types, $values);
533 $result = [];
534
535 while ($row = $DIC->database()->fetchAssoc($res)) {
536 if ($row['user_id'] > 0) {
537 $user = new ilObjUser((int) $row['user_id']);
538 $userdata = [
539 'user_id' => $user->getId(),
540 'firstname' => $user->getFirstname(),
541 'lastname' => $user->getLastname(),
542 'login' => $user->getLogin(),
543 'timestamp' => (int) $row['timestamp'],
544 'actor_id' => (int) $row['actor_id'],
545 'remark' => $row['remark']
546 ];
547
548 $result[] = $userdata;
549 }
550 }
551
552 return $result;
553 }
User class.

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

+ Here is the call graph for this function:

◆ getChatURL()

ilChatroom::getChatURL ( ilChatroomObjectGUI  $gui)

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

660 : string
661 {
662 return ilLink::_getStaticLink($gui->getObject()->getRefId(), $gui->getObject()->getType());
663 }

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

+ Here is the call graph for this function:

◆ getConnectedUsers()

ilChatroom::getConnectedUsers ( bool  $only_data = true)

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

324 : array
325 {
326 global $DIC;
327
328 $query = 'SELECT ' . ($only_data ? 'userdata' : '*') . ' FROM ' . self::$userTable . ' WHERE room_id = %s';
329 $types = [ilDBConstants::T_INTEGER];
330 $values = [$this->roomId];
331 $rset = $DIC->database()->queryF($query, $types, $values);
332 $users = [];
333
334 while ($row = $DIC->database()->fetchAssoc($rset)) {
335 $users[] = $only_data ? json_decode($row['userdata'], true, 512, JSON_THROW_ON_ERROR) : $row;
336 }
337
338 return $users;
339 }

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

Referenced by ilChatroomViewGUI\showRoom().

+ Here is the caller graph for this function:

◆ getDescription()

ilChatroom::getDescription ( )

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

197 : string
198 {
199 if (!$this->object) {
200 $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
201 }
202
203 return $this->object->getDescription();
204 }

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

+ 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 406 of file class.ilChatroom.php.

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

◆ getLastMessages()

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

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

753 : array
754 {
755 global $DIC;
756
757 // There is currently no way to check if a message is private or not
758 // by sql. So we fetch twice as much as we need and hope that there
759 // are not more than $number private messages.
760 $DIC->database()->setLimit($number);
761 $rset = $DIC->database()->queryF(
762 'SELECT *
763 FROM ' . self::$historyTable . '
764 WHERE room_id = %s
765 AND (
766 (JSON_VALUE(message, "$.type") = "message" AND (NOT JSON_CONTAINS_PATH(message, "one", "$.target.public") OR JSON_VALUE(message, "$.target.public") <> 0))
767 OR JSON_VALUE(message, "$.target.id") = %s
768 OR JSON_VALUE(message, "$.from.id") = %s
769 )
770 ORDER BY timestamp DESC',
772 [$this->roomId, $chatuser->getUserId(), $chatuser->getUserId()]
773 );
774
775 $result_count = 0;
776 $results = [];
777 while (($row = $DIC->database()->fetchAssoc($rset)) && $result_count < $number) {
778 $tmp = json_decode($row['message'], false, 512, JSON_THROW_ON_ERROR);
779 if (property_exists($tmp, 'target') && $tmp->target instanceof stdClass && (int) $tmp->target->public === 0) {
780 if (in_array($chatuser->getUserId(), [(int) $tmp->target->id, (int) $tmp->from->id], true)) {
781 $results[] = $tmp;
782 ++$result_count;
783 }
784 } else {
785 $results[] = $tmp;
786 ++$result_count;
787 }
788 }
789
790 if ($results !== []) {
791 $rset = $DIC->database()->queryF(
792 'SELECT *
793 FROM ' . self::$historyTable . '
794 WHERE room_id = %s
795 AND JSON_VALUE(message, "$.type") = "notice"
796 AND timestamp <= %s AND timestamp >= %s
797 ORDER BY timestamp DESC',
799 [$this->roomId, $results[0]->timestamp, $results[$result_count - 1]->timestamp]
800 );
801
802 while (($row = $DIC->database()->fetchAssoc($rset))) {
803 $tmp = json_decode($row['message'], false, 512, JSON_THROW_ON_ERROR);
804 $results[] = $tmp;
805 }
806 }
807
808 usort($results, static function (stdClass $a, stdClass $b): int {
809 $a_timestamp = strlen((string) $a->timestamp) === 13 ? ((int) substr((string) $a->timestamp, 0, -3)) : $a->timestamp;
810 $b_timestamp = strlen((string) $b->timestamp) === 13 ? ((int) substr((string) $b->timestamp, 0, -3)) : $b->timestamp;
811
812 return $b_timestamp - $a_timestamp;
813 });
814
815 return $results;
816 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$results

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

Referenced by ilChatroomViewGUI\showRoom().

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

◆ getLastSession()

ilChatroom::getLastSession ( ilChatroomUser  $user)

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

555 : ?array
556 {
557 global $DIC;
558
559 $query = 'SELECT * FROM ' . self::$sessionTable . ' WHERE user_id = ' .
560 $DIC->database()->quote($user->getUserId(), ilDBConstants::T_INTEGER) .
561 ' ORDER BY connected DESC';
562
563 $DIC->database()->setLimit(1);
564 $res = $DIC->database()->query($query);
565
566 if ($row = $DIC->database()->fetchAssoc($res)) {
567 return $row;
568 }
569
570 return null;
571 }

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

+ Here is the call graph for this function:

◆ getRefIdByRoomId()

ilChatroom::getRefIdByRoomId ( int  $room_id)

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

726 : int
727 {
728 global $DIC;
729
730 $query = "
731 SELECT objr.ref_id
732 FROM object_reference objr
733
734 INNER JOIN chatroom_settings cs
735 ON cs.object_id = objr.obj_id
736
737 INNER JOIN object_data od
738 ON od.obj_id = cs.object_id
739
740 WHERE cs.room_id = %s
741 ";
742
743 $types = [ilDBConstants::T_INTEGER];
744 $values = [$room_id];
745
746 $res = $DIC->database()->queryF($query, $types, $values);
747
748 $row = $DIC->database()->fetchAssoc($res);
749
750 return (int) ($row['ref_id'] ?? 0);
751 }

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

◆ getRoomId()

ilChatroom::getRoomId ( )

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

469 : int
470 {
471 return $this->roomId;
472 }

Referenced by ilChatroomViewGUI\showRoom().

+ Here is the caller graph for this function:

◆ getSessions()

ilChatroom::getSessions ( ilChatroomUser  $user)

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

573 : array
574 {
575 global $DIC;
576
577 $query = 'SELECT * FROM ' . self::$sessionTable
578 . ' WHERE room_id = ' .
579 $DIC->database()->quote($this->getRoomId(), ilDBConstants::T_INTEGER) .
580 ' ORDER BY connected DESC';
581
582 $res = $DIC->database()->query($query);
583
584 $result = [];
585 while ($row = $DIC->database()->fetchAssoc($res)) {
586 $result[] = $row;
587 }
588
589 return $result;
590 }

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

◆ getSetting()

ilChatroom::getSetting ( string  $name)

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

207 {
208 return $this->settings[$name];
209 }

References ILIAS\Repository\settings().

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

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

◆ getSettings()

ilChatroom::getSettings ( )

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

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

References $settings.

Referenced by ilChatroomViewGUI\readOnlyChatWindow(), and ilChatroomViewGUI\showRoom().

+ Here is the caller graph for this function:

◆ getTitle()

ilChatroom::getTitle ( )

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

665 : string
666 {
667 if (!$this->object) {
668 $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
669 }
670
671 return $this->object->getTitle();
672 }

References ilObjectFactory\getInstanceByObjId().

+ Here is the call 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 151 of file class.ilChatroom.php.

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

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

+ Here is the call graph for this function:

◆ isSubscribed()

ilChatroom::isSubscribed ( int  $chat_userid)

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

392 : bool
393 {
394 global $DIC;
395
396 $query = 'SELECT COUNT(user_id) as cnt FROM ' . self::$userTable .
397 ' WHERE room_id = %s AND user_id = %s';
398
400 $values = [$this->roomId, $chat_userid];
401 $res = $DIC->database()->queryF($query, $types, $values);
402
403 return ($row = $DIC->database()->fetchAssoc($res)) && (int) $row['cnt'] === 1;
404 }

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

Referenced by ilChatroomViewGUI\showRoom().

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

◆ isUserBanned()

ilChatroom::isUserBanned ( int  $user_id)

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

512 : bool
513 {
514 global $DIC;
515
516 $query = 'SELECT COUNT(user_id) cnt FROM ' . self::$banTable . ' WHERE user_id = %s AND room_id = %s';
518 $values = [$user_id, $this->getRoomId()];
519
520 $res = $DIC->database()->queryF($query, $types, $values);
521
522 return ($row = $DIC->database()->fetchAssoc($res)) && $row['cnt'];
523 }

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

Referenced by ilChatroomViewGUI\showRoom().

+ Here is the caller graph for this function:

◆ phpTypeToMDBType()

ilChatroom::phpTypeToMDBType ( string  $type)
private

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

254 : string
255 {
256 return match ($type) {
257 'string' => ilDBConstants::T_TEXT,
258 'boolean' => ilDBConstants::T_INTEGER,
259 default => $type,
260 };
261 }

References ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by saveSettings().

+ Here is the caller graph for this function:

◆ save()

ilChatroom::save ( )

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

211 : void
212 {
213 $this->saveSettings($this->settings);
214 }
saveSettings(array $settings)

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

+ Here is the call graph for this function:

◆ saveSettings()

ilChatroom::saveSettings ( array  $settings)

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

216 : void
217 {
218 global $DIC;
219
220 $localSettings = [];
221
222 foreach ($this->availableSettings as $setting => $type) {
223 if (array_key_exists($setting, $settings)) {
224 if ($type === 'boolean') {
225 $settings[$setting] = (bool) $settings[$setting];
226 }
227 $localSettings[$setting] = [$this->phpTypeToMDBType($type), $settings[$setting]];
228 }
229 }
230
231 if (!isset($localSettings['room_type']) || !$localSettings['room_type'][1]) {
232 $localSettings['room_type'][0] = ilDBConstants::T_TEXT;
233 $localSettings['room_type'][1] = 'repository';
234 }
235
236 if ($this->roomId > 0) {
237 $DIC->database()->update(
238 self::$settingsTable,
239 $localSettings,
240 ['room_id' => [ilDBConstants::T_INTEGER, $this->roomId]]
241 );
242 } else {
243 $this->roomId = $DIC->database()->nextId(self::$settingsTable);
244
245 $localSettings['room_id'] = [
248 ];
249
250 $DIC->database()->insert(self::$settingsTable, $localSettings);
251 }
252 }
phpTypeToMDBType(string $type)

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

Referenced by save().

+ 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 167 of file class.ilChatroom.php.

167 : void
168 {
169 $this->settings[$name] = $value;
170 }

References ILIAS\Repository\settings().

Referenced by initialize().

+ 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 497 of file class.ilChatroom.php.

497 : int
498 {
499 global $DIC;
500
501 if (!is_array($user_id)) {
502 $user_id = [$user_id];
503 }
504
505 $query = 'DELETE FROM ' . self::$banTable . ' WHERE room_id = %s AND ' . $DIC->database()->in('user_id', $user_id, false, ilDBConstants::T_INTEGER);
506 $types = [ilDBConstants::T_INTEGER];
507 $values = [$this->getRoomId()];
508
509 return $DIC->database()->manipulateF($query, $types, $values);
510 }

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

Field Documentation

◆ $availableSettings

array ilChatroom::$availableSettings
private
Initial value:
= [
'object_id' => 'integer',
'allow_anonymous' => 'boolean',
'allow_custom_usernames' => 'boolean',
'enable_history' => 'boolean',
'autogen_usernames' => 'string',
'room_type' => 'string',
'display_past_msgs' => 'integer',
]

Definition at line 48 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 58 of file class.ilChatroom.php.

◆ $roomId

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 41 of file class.ilChatroom.php.

Referenced by getSettings(), and saveSettings().

◆ $settingsTable

string ilChatroom::$settingsTable = 'chatroom_settings'
staticprivate

Definition at line 36 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: