ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroom.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
34{
35 public const ROOM_INVITATION = 'invitation_to_room';
36 private static string $settingsTable = 'chatroom_settings';
37 private static string $historyTable = 'chatroom_history';
38 private static string $userTable = 'chatroom_users';
39 private static string $sessionTable = 'chatroom_sessions';
40 private static string $banTable = 'chatroom_bans';
41 private array $settings = [];
48 private array $availableSettings = [
49 'object_id' => 'integer',
50 'allow_anonymous' => 'boolean',
51 'allow_custom_usernames' => 'boolean',
52 'enable_history' => 'boolean',
53 'autogen_usernames' => 'string',
54 'room_type' => 'string',
55 'display_past_msgs' => 'integer',
56 ];
57 private int $roomId = 0;
58 private ?ilObjChatroom $object = null;
59
64 public static function checkUserPermissions($permissions, int $ref_id, bool $send_info = true): 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 }
82
88 public static function checkPermissionsOfUser(int $usr_id, $permissions, int $ref_id): bool
89 {
90 if (!is_array($permissions)) {
91 $permissions = [$permissions];
92 }
93
94 return self::checkPermissions($usr_id, $ref_id, $permissions);
95 }
96
100 protected static function checkPermissions(int $usr_id, int $ref_id, array $permissions): 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 }
128
129 public static function byObjectId(int $object_id): ?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 }
146
151 public function initialize(array $rowdata): 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 }
162
167 public function setSetting(string $name, $value): void
168 {
169 $this->settings[$name] = $value;
170 }
171
172 public static function byRoomId(int $room_id, bool $initObject = false): ?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 }
196
197 public function getDescription(): string
198 {
199 if (!$this->object) {
200 $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
201 }
202
203 return $this->object->getDescription();
204 }
205
206 public function getSetting(string $name)
207 {
208 return $this->settings[$name];
209 }
210
211 public function save(): void
212 {
213 $this->saveSettings($this->settings);
214 }
215
216 public function saveSettings(array $settings): 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 }
253
254 private function phpTypeToMDBType(string $type): string
255 {
256 return match ($type) {
257 'string' => ilDBConstants::T_TEXT,
258 'boolean' => ilDBConstants::T_INTEGER,
259 default => $type,
260 };
261 }
262
266 public function addHistoryEntry($message): 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 }
288
289 public function connectUser(ilChatroomUser $user): 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 }
323
324 public function getConnectedUsers(bool $only_data = true): 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 }
340
341 public function disconnectUser(int $user_id): void
342 {
343 $this->disconnectUsers([$user_id]);
344 }
345
349 public function disconnectUsers(array $userIds): 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 }
386
387 public function getSettings(): array
388 {
389 return $this->settings;
390 }
391
392 public function isSubscribed(int $chat_userid): 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 }
405
406 public function getHistory(
407 ?ilDateTime $from = null,
408 ?ilDateTime $to = null,
409 ?int $restricted_session_userid = null,
410 bool $respect_target = true
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 }
468
469 public function getRoomId(): int
470 {
471 return $this->roomId;
472 }
473
474 public function banUser(int $user_id, int $actor_id, string $comment = ''): 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 }
491
497 public function unbanUser($user_id): 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 }
511
512 public function isUserBanned(int $user_id): 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 }
524
525 public function getBannedUsers(): 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 }
554
555 public function getLastSession(ilChatroomUser $user): ?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 }
572
573 public function getSessions(ilChatroomUser $user): 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 }
591
596 public function sendInvitationNotification(
598 $sender,
599 int $recipient_id,
600 string $invitationLink = ''
601 ): void {
602 $links = [];
603
604 if ($gui && $invitationLink === '') {
605 $invitationLink = $this->getChatURL($gui);
606 }
607
608 $links[] = new ilNotificationLink(
609 new ilNotificationParameter('chat_join', [], 'chatroom'),
610 $invitationLink
611 );
612
613 if ($recipient_id > 0 && ANONYMOUS_USER_ID !== $recipient_id) {
614 if (is_numeric($sender) && $sender > 0) {
615 $sender_id = $sender;
618 $public_name = $usr->getPublicName();
619 } elseif ($sender instanceof ilChatroomUser) {
620 if ($sender->getUserId() > 0) {
621 $sender_id = $sender->getUserId();
622 } else {
623 $sender_id = ANONYMOUS_USER_ID;
624 }
625 $public_name = $sender->getUsername();
626 } else {
627 throw new InvalidArgumentException(
628 '$sender must be an instance of ilChatroomUser or an id of an ilObjUser instance'
629 );
630 }
631
632 $userLang = ilLanguageFactory::_getLanguageOfUser($recipient_id);
633 $userLang->loadLanguageModule('mail');
634 $bodyParams = [
635 'link' => $invitationLink,
636 'inviter_name' => $public_name,
637 'room_name' => $this->getTitle(),
638 'salutation' => ilMail::getSalutation($recipient_id, $userLang),
639 'BR' => "\n",
640 ];
641
642 $notification = new ilNotificationConfig(ChatInvitationNotificationProvider::NOTIFICATION_TYPE);
643 $notification->setTitleVar('chat_invitation', $bodyParams, 'chatroom');
644 $notification->setShortDescriptionVar('chat_invitation_short', $bodyParams, 'chatroom');
645 $notification->setLongDescriptionVar('chat_invitation_long', $bodyParams, 'chatroom');
646 $notification->setLinks($links);
647 $notification->setIconPath('assets/images/standard/icon_chtr.svg');
648 $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
649 $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
650 $notification->setIdentification(new NotificationIdentification(
651 ChatInvitationNotificationProvider::NOTIFICATION_TYPE,
652 self::ROOM_INVITATION . '_' . $this->getRefIdByRoomId($this->getRoomId()),
653 ));
654 $notification->setHandlerParam('mail.sender', (string) $sender_id);
655
656 $notification->notifyByUsers([$recipient_id]);
657 }
658 }
659
660 public function getChatURL(ilChatroomObjectGUI $gui): string
661 {
662 return ilLink::_getStaticLink($gui->getObject()->getRefId(), $gui->getObject()->getType());
663 }
664
665 public function getTitle(): string
666 {
667 if (!$this->object) {
668 $this->object = ilObjectFactory::getInstanceByObjId((int) $this->getSetting('object_id'));
669 }
670
671 return $this->object->getTitle();
672 }
673
674 public function countActiveUsers(): 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 }
689
694 public function getAccessibleRoomIdByTitleMap(int $user_id): 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 }
725
726 public function getRefIdByRoomId(int $room_id): 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 }
752
753 public function getLastMessages(int $number, ilChatroomUser $chatuser): 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 }
817
818 public function clearMessages(): 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 }
834}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$comment
Definition: buildRTE.php:72
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
description of a localized parameter this information is used locate translations while processing no...
Class ilChatroomUser.
getUserId()
Returns Ilias User ID.
getUsername()
Returns username from Object or SESSION.
Class ilChatroom.
addHistoryEntry($message)
getConnectedUsers(bool $only_data=true)
phpTypeToMDBType(string $type)
static string $settingsTable
static checkPermissions(int $usr_id, int $ref_id, array $permissions)
initialize(array $rowdata)
Sets $this->roomId by given array $rowdata and calls setSetting method foreach available setting in $...
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.
ilObjChatroom $object
saveSettings(array $settings)
getRefIdByRoomId(int $room_id)
connectUser(ilChatroomUser $user)
static string $userTable
setSetting(string $name, $value)
Sets given name and value as setting into $this->settings array.
getAccessibleRoomIdByTitleMap(int $user_id)
Fetches and returns a Array<Integer, String> of all accessible repository object chats in the main tr...
getHistory(?ilDateTime $from=null, ?ilDateTime $to=null, ?int $restricted_session_userid=null, bool $respect_target=true)
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
disconnectUser(int $user_id)
static string $historyTable
disconnectUsers(array $userIds)
const ROOM_INVITATION
getSetting(string $name)
isUserBanned(int $user_id)
getChatURL(ilChatroomObjectGUI $gui)
static byRoomId(int $room_id, bool $initObject=false)
static string $banTable
isSubscribed(int $chat_userid)
static string $sessionTable
array $availableSettings
getLastMessages(int $number, ilChatroomUser $chatuser)
unbanUser($user_id)
Deletes entry from banTable matching roomId and given $user_id and returns the number of affected row...
getSessions(ilChatroomUser $user)
banUser(int $user_id, int $actor_id, string $comment='')
static byObjectId(int $object_id)
getLastSession(ilChatroomUser $user)
@classDescription Date and time handling
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
User class.
static _isOffline(int $obj_id)
Type-specific implementation of general status, has to be overwritten if object type does not support...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId(int $ref_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$results
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31