19 declare(strict_types=1);
50 'object_id' =>
'integer',
51 'allow_anonymous' =>
'boolean',
52 'allow_custom_usernames' =>
'boolean',
53 'enable_history' =>
'boolean',
54 'autogen_usernames' =>
'string',
55 'room_type' =>
'string',
56 'display_past_msgs' =>
'integer',
68 $main_tpl = $DIC->ui()->mainTemplate();
70 if (!is_array($permissions)) {
71 $permissions = [$permissions];
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);
81 return $hasPermissions;
91 if (!is_array($permissions)) {
92 $permissions = [$permissions];
95 return self::checkPermissions($usr_id, $ref_id, $permissions);
107 if ($pub_ref_id === $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)
121 foreach ($permissions as $permission) {
122 if (!$DIC->access()->checkAccessOfUser($usr_id, $permission,
'', $ref_id)) {
135 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE object_id = %s';
137 $values = [$object_id];
138 $rset = $DIC->database()->queryF($query, $types, $values);
140 if ($row = $DIC->database()->fetchAssoc($rset)) {
142 $room->initialize($row);
155 $this->roomId = (
int) $rowdata[
'room_id'];
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]);
178 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE room_id = %s';
181 $values = [$room_id];
183 $rset = $DIC->database()->queryF($query, $types, $values);
185 if ($row = $DIC->database()->fetchAssoc($rset)) {
187 $room->initialize($row);
201 if (!$this->
object) {
205 return $this->
object->getDescription();
224 foreach ($this->availableSettings as $setting => $type) {
225 if (array_key_exists($setting, $settings)) {
226 if ($type ===
'boolean') {
227 $settings[$setting] = (bool) $settings[$setting];
229 $localSettings[$setting] = [$this->
phpTypeToMDBType($type), $settings[$setting]];
233 if (!isset($localSettings[
'room_type']) || !$localSettings[
'room_type'][1]) {
235 $localSettings[
'room_type'][1] =
'repository';
238 if ($this->roomId > 0) {
239 $DIC->database()->update(
240 self::$settingsTable,
245 $this->roomId = $DIC->database()->nextId(self::$settingsTable);
247 $localSettings[
'room_id'] = [
252 $DIC->database()->insert(self::$settingsTable, $localSettings);
258 return match ($type) {
279 $id = $DIC->database()->nextId(self::$historyTable);
280 $DIC->database()->insert(
300 $query =
'SELECT user_id FROM ' . self::$userTable .
' WHERE room_id = %s AND user_id = %s';
304 if (!$DIC->database()->fetchAssoc($DIC->database()->queryF($query, $types, $values))) {
307 $DIC->database()->replace(
329 $query =
'SELECT ' . ($only_data ?
'userdata' :
'*') .
' FROM ' . self::$userTable .
' WHERE room_id = %s';
332 $rset = $DIC->database()->queryF($query, $types, $values);
335 while ($row = $DIC->database()->fetchAssoc($rset)) {
336 $users[] = $only_data ? json_decode($row[
'userdata'],
false, 512, JSON_THROW_ON_ERROR) : $row;
354 $query =
'SELECT * FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
359 $res = $DIC->database()->queryF($query, $types, $values);
361 if ($row = $DIC->database()->fetchAssoc(
$res)) {
362 $query =
'DELETE FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
367 $DIC->database()->manipulateF($query, $types, $values);
371 $id = $DIC->database()->nextId(self::$sessionTable);
372 $DIC->database()->insert(
384 }
while ($row = $DIC->database()->fetchAssoc(
$res));
397 $query =
'SELECT COUNT(user_id) as cnt FROM ' . self::$userTable .
398 ' WHERE room_id = %s AND user_id = %s';
402 $res = $DIC->database()->queryF($query, $types, $values);
404 return ($row = $DIC->database()->fetchAssoc(
$res)) && (
int) $row[
'cnt'] === 1;
410 int $restricted_session_userid = null,
411 bool $respect_target =
true 418 'SELECT historyTable.* ' .
419 'FROM ' . self::$historyTable .
' historyTable ' . $join .
' ' .
420 'WHERE historyTable.room_id = ' . $this->
getRoomId();
424 if ($from !== null) {
433 $query .=
' AND ' . implode(
' AND ', $filter);
435 $query .=
' ORDER BY timestamp ASC';
437 $rset = $DIC->database()->query($query);
440 while ($row = $DIC->database()->fetchAssoc($rset)) {
442 $message = json_decode($row[
'message'],
false, 512, JSON_THROW_ON_ERROR);
447 $message = json_decode(
'{}',
false, 512, JSON_THROW_ON_ERROR);
452 $row[
'message']->timestamp = $row[
'timestamp'];
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)
479 $upload_id = $DIC->database()->nextId(self::$uploadTable);
480 $DIC->database()->insert(
497 $DIC->database()->replace(
520 if (!is_array($user_id)) {
521 $user_id = [$user_id];
524 $query =
'DELETE FROM ' . self::$banTable .
' WHERE room_id = %s AND ' . $DIC->database()->in(
'user_id', $user_id,
false,
ilDBConstants::T_INTEGER);
528 return $DIC->database()->manipulateF($query, $types, $values);
535 $query =
'SELECT COUNT(user_id) cnt FROM ' . self::$banTable .
' WHERE user_id = %s AND room_id = %s';
537 $values = [$user_id, $this->
getRoomId()];
539 $res = $DIC->database()->queryF($query, $types, $values);
541 return ($row = $DIC->database()->fetchAssoc(
$res)) && $row[
'cnt'];
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 ';
551 $res = $DIC->database()->queryF($query, $types, $values);
554 while ($row = $DIC->database()->fetchAssoc(
$res)) {
555 if ($row[
'user_id'] > 0) {
556 $user =
new ilObjUser((
int) $row[
'user_id']);
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']
567 $result[] = $userdata;
578 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
580 ' ORDER BY connected DESC';
582 $DIC->database()->setLimit(1);
583 $res = $DIC->database()->query($query);
585 if ($row = $DIC->database()->fetchAssoc(
$res)) {
596 $query =
'SELECT * FROM ' . self::$sessionTable
597 .
' WHERE room_id = ' .
599 ' ORDER BY connected DESC';
601 $res = $DIC->database()->query($query);
604 while ($row = $DIC->database()->fetchAssoc(
$res)) {
615 public function sendInvitationNotification(
619 string $invitationLink =
'' 623 if ($gui && $invitationLink ===
'') {
633 if (is_numeric($sender) && $sender > 0) {
634 $sender_id = $sender;
637 $public_name = $usr->getPublicName();
639 if ($sender->getUserId() > 0) {
640 $sender_id = $sender->getUserId();
644 $public_name = $sender->getUsername();
647 '$sender must be an instance of ilChatroomUser or an id of an ilObjUser instance' 652 $userLang->loadLanguageModule(
'mail');
654 'link' => $invitationLink,
655 'inviter_name' => $public_name,
661 $notification =
new ilNotificationConfig(ChatInvitationNotificationProvider::NOTIFICATION_TYPE);
662 $notification->setTitleVar(
'chat_invitation', $bodyParams,
'chatroom');
663 $notification->setShortDescriptionVar(
'chat_invitation_short', $bodyParams,
'chatroom');
664 $notification->setLongDescriptionVar(
'chat_invitation_long', $bodyParams,
'chatroom');
665 $notification->setLinks($links);
666 $notification->setIconPath(
'templates/default/images/standard/icon_chtr.svg');
667 $notification->setValidForSeconds(ilNotificationConfig::TTL_LONG);
668 $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
670 ChatInvitationNotificationProvider::NOTIFICATION_TYPE,
673 $notification->setHandlerParam(
'mail.sender', (
string) $sender_id);
675 $notification->notifyByUsers([$recipient_id]);
686 if (!$this->
object) {
690 return $this->
object->getTitle();
697 $query =
'SELECT COUNT(user_id) cnt FROM ' . self::$userTable .
' WHERE room_id = %s';
700 $res = $DIC->database()->queryF($query, $types, $values);
702 if ($row = $DIC->database()->fetchAssoc(
$res)) {
703 return (
int) $row[
'cnt'];
718 SELECT room_id, od.title, objr.ref_id 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 726 ON tree.child = objr.ref_id 732 $values = [1,
'chtr'];
733 $res = $DIC->database()->queryF($query, $types, $values);
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'];
751 FROM object_reference objr 753 INNER JOIN chatroom_settings cs 754 ON cs.object_id = objr.obj_id 756 INNER JOIN object_data od 757 ON od.obj_id = cs.object_id 759 WHERE cs.room_id = %s 763 $values = [$room_id];
765 $res = $DIC->database()->queryF($query, $types, $values);
767 $row = $DIC->database()->fetchAssoc(
$res);
769 return (
int) ($row[
'ref_id'] ?? 0);
779 $DIC->database()->setLimit($number);
780 $rset = $DIC->database()->query(
782 FROM ' . self::$historyTable .
' 789 ORDER BY timestamp DESC' 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)) {
808 $rset = $DIC->database()->queryF(
810 FROM ' . self::$historyTable .
' 813 AND timestamp <= %s AND timestamp >= %s 814 ORDER BY timestamp DESC',
819 while (($row = $DIC->database()->fetchAssoc($rset))) {
820 $tmp = json_decode($row[
'message'],
false, 512, JSON_THROW_ON_ERROR);
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;
829 return $b_timestamp - $a_timestamp;
839 $DIC->database()->queryF(
840 'DELETE FROM ' . self::$historyTable .
' WHERE room_id = %s',
845 $DIC->database()->queryF(
846 'DELETE FROM ' . self::$sessionTable .
' WHERE room_id = %s AND disconnected < %s',
848 [$this->roomId, time()]
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static checkPermissions(int $usr_id, int $ref_id, array $permissions)
getUserId()
Returns Ilias User ID.
description of a localized parameter this information is used locate translations while processing no...
getRefIdByRoomId(int $room_id)
banUser(int $user_id, int $actor_id, string $comment='')
getLastSession(ilChatroomUser $user)
getLastMessages(int $number, ilChatroomUser $chatuser)
disconnectUsers(array $userIds)
static string $historyTable
getConnectedUsers(bool $only_data=true)
phpTypeToMDBType(string $type)
setSetting(string $name, $value)
Sets given name and value as setting into $this->settings array.
static _lookupObjId(int $ref_id)
saveFileUploadToDb(int $user_id, string $filename, string $type)
getHistory(ilDateTime $from=null, ilDateTime $to=null, int $restricted_session_userid=null, bool $respect_target=true)
static string $settingsTable
addHistoryEntry($message)
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.
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
getChatURL(ilChatroomObjectGUI $gui)
isSubscribed(int $chat_userid)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
getSessions(ilChatroomUser $user)
static _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
isUserBanned(int $user_id)
static byRoomId(int $room_id, bool $initObject=false)
unbanUser($user_id)
Deletes entry from banTable matching roomId and given $user_id and returns the number of affected row...
connectUser(ilChatroomUser $user)
foreach($mandatory_scripts as $file) $timestamp
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _isOffline(int $obj_id)
Type-specific implementation of general status, has to be overwritten if object type does not support...
static byObjectId(int $object_id)
disconnectUser(int $user_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static string $sessionTable
getUsername()
Returns username from Object or SESSION.
getAccessibleRoomIdByTitleMap(int $user_id)
Fetches and returns a Array<Integer, String> of all accessible repository object chats in the main tr...
initialize(array $rowdata)
Sets $this->roomId by given array $rowdata and calls setSetting method foreach available setting in $...
saveSettings(array $settings)
static string $uploadTable