19declare(strict_types=1);
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',
67 $main_tpl =
$DIC->ui()->mainTemplate();
69 if (!is_array($permissions)) {
70 $permissions = [$permissions];
74 if (!$hasPermissions && $send_info) {
75 $main_tpl->setOnScreenMessage(
'failure',
$DIC->language()->txt(
'permission_denied'),
true);
80 return $hasPermissions;
90 if (!is_array($permissions)) {
91 $permissions = [$permissions];
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)
120 foreach ($permissions as $permission) {
121 if (!
$DIC->access()->checkAccessOfUser($usr_id, $permission,
'',
$ref_id)) {
133 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE object_id = %s';
135 $values = [$object_id];
136 $rset =
$DIC->database()->queryF($query, $types, $values);
138 if ($row =
$DIC->database()->fetchAssoc($rset)) {
140 $room->initialize($row);
153 $this->roomId = (
int) $rowdata[
'room_id'];
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]);
176 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE room_id = %s';
179 $values = [$room_id];
181 $rset =
$DIC->database()->queryF($query, $types, $values);
183 if ($row =
$DIC->database()->fetchAssoc($rset)) {
185 $room->initialize($row);
199 if (!$this->
object) {
203 return $this->
object->getDescription();
222 foreach ($this->availableSettings as $setting => $type) {
223 if (array_key_exists($setting,
$settings)) {
224 if ($type ===
'boolean') {
231 if (!isset($localSettings[
'room_type']) || !$localSettings[
'room_type'][1]) {
233 $localSettings[
'room_type'][1] =
'repository';
236 if ($this->roomId > 0) {
237 $DIC->database()->update(
238 self::$settingsTable,
243 $this->roomId =
$DIC->database()->nextId(self::$settingsTable);
245 $localSettings[
'room_id'] = [
250 $DIC->database()->insert(self::$settingsTable, $localSettings);
256 return match ($type) {
277 $id =
$DIC->database()->nextId(self::$historyTable);
278 $DIC->database()->insert(
299 $query =
'SELECT user_id FROM ' . self::$userTable .
' WHERE room_id = %s AND user_id = %s';
303 if (!
$DIC->database()->fetchAssoc(
$DIC->database()->queryF($query, $types, $values))) {
306 $DIC->database()->replace(
328 $query =
'SELECT ' . ($only_data ?
'userdata' :
'*') .
' FROM ' . self::$userTable .
' WHERE room_id = %s';
331 $rset =
$DIC->database()->queryF($query, $types, $values);
334 while ($row =
$DIC->database()->fetchAssoc($rset)) {
335 $users[] = $only_data ? json_decode($row[
'userdata'],
true, 512, JSON_THROW_ON_ERROR) : $row;
353 $query =
'SELECT * FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
358 $res =
$DIC->database()->queryF($query, $types, $values);
360 if ($row =
$DIC->database()->fetchAssoc(
$res)) {
361 $query =
'DELETE FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
366 $DIC->database()->manipulateF($query, $types, $values);
370 $id = $DIC->database()->nextId(self::$sessionTable);
371 $DIC->database()->insert(
383 }
while ($row =
$DIC->database()->fetchAssoc(
$res));
396 $query =
'SELECT COUNT(user_id) as cnt FROM ' . self::$userTable .
397 ' WHERE room_id = %s AND user_id = %s';
401 $res =
$DIC->database()->queryF($query, $types, $values);
403 return ($row =
$DIC->database()->fetchAssoc(
$res)) && (
int) $row[
'cnt'] === 1;
409 ?
int $restricted_session_userid =
null,
410 bool $respect_target =
true
417 'SELECT historyTable.* ' .
418 'FROM ' . self::$historyTable .
' historyTable ' . $join .
' ' .
419 'WHERE historyTable.room_id = ' . $this->
getRoomId();
423 if ($from !==
null) {
432 $query .=
' AND ' . implode(
' AND ', $filter);
434 $query .=
' ORDER BY timestamp ASC';
436 $rset =
$DIC->database()->query($query);
439 while ($row =
$DIC->database()->fetchAssoc($rset)) {
441 $message = json_decode($row[
'message'],
false, 512, JSON_THROW_ON_ERROR);
442 }
catch (JsonException) {
446 $message = json_decode(
'{}',
false, 512, JSON_THROW_ON_ERROR);
451 $row[
'message']->timestamp = $row[
'timestamp'];
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)
471 return $this->roomId;
478 $DIC->database()->replace(
507 $values = [$this->getRoomId()];
509 return $DIC->database()->manipulateF($query, $types, $values);
516 $query =
'SELECT COUNT(user_id) cnt FROM ' . self::$banTable .
' WHERE user_id = %s AND room_id = %s';
518 $values = [
$user_id, $this->getRoomId()];
520 $res =
$DIC->database()->queryF($query, $types, $values);
522 return ($row =
$DIC->database()->fetchAssoc(
$res)) && $row[
'cnt'];
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 ';
531 $values = [$this->getRoomId()];
532 $res =
$DIC->database()->queryF($query, $types, $values);
535 while ($row =
$DIC->database()->fetchAssoc(
$res)) {
536 if ($row[
'user_id'] > 0) {
537 $user =
new ilObjUser((
int) $row[
'user_id']);
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']
548 $result[] = $userdata;
559 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
561 ' ORDER BY connected DESC';
563 $DIC->database()->setLimit(1);
564 $res =
$DIC->database()->query($query);
566 if ($row =
$DIC->database()->fetchAssoc(
$res)) {
577 $query =
'SELECT * FROM ' . self::$sessionTable
578 .
' WHERE room_id = ' .
580 ' ORDER BY connected DESC';
582 $res =
$DIC->database()->query($query);
585 while ($row =
$DIC->database()->fetchAssoc(
$res)) {
596 public function sendInvitationNotification(
600 string $invitationLink =
''
604 if ($gui && $invitationLink ===
'') {
605 $invitationLink = $this->getChatURL($gui);
614 if (is_numeric($sender) && $sender > 0) {
615 $sender_id = $sender;
618 $public_name = $usr->getPublicName();
620 if ($sender->getUserId() > 0) {
621 $sender_id = $sender->getUserId();
625 $public_name = $sender->getUsername();
627 throw new InvalidArgumentException(
628 '$sender must be an instance of ilChatroomUser or an id of an ilObjUser instance'
633 $userLang->loadLanguageModule(
'mail');
635 'link' => $invitationLink,
636 'inviter_name' => $public_name,
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);
651 ChatInvitationNotificationProvider::NOTIFICATION_TYPE,
652 self::ROOM_INVITATION .
'_' . $this->getRefIdByRoomId($this->getRoomId()),
654 $notification->setHandlerParam(
'mail.sender', (
string) $sender_id);
656 $notification->notifyByUsers([$recipient_id]);
667 if (!$this->
object) {
671 return $this->
object->getTitle();
678 $query =
'SELECT COUNT(user_id) cnt FROM ' . self::$userTable .
' WHERE room_id = %s';
680 $values = [$this->roomId];
681 $res =
$DIC->database()->queryF($query, $types, $values);
683 if ($row =
$DIC->database()->fetchAssoc(
$res)) {
684 return (
int) $row[
'cnt'];
699 SELECT room_id, od.title, objr.ref_id
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
707 ON tree.child = objr.ref_id
713 $values = [1,
'chtr'];
714 $res =
$DIC->database()->queryF($query, $types, $values);
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'];
732 FROM object_reference objr
734 INNER JOIN chatroom_settings cs
735 ON cs.object_id = objr.obj_id
737 INNER JOIN object_data od
738 ON od.obj_id = cs.object_id
740 WHERE cs.room_id = %s
744 $values = [$room_id];
746 $res =
$DIC->database()->queryF($query, $types, $values);
748 $row =
$DIC->database()->fetchAssoc(
$res);
750 return (
int) ($row[
'ref_id'] ?? 0);
760 $DIC->database()->setLimit($number);
761 $rset =
$DIC->database()->queryF(
763 FROM ' . self::$historyTable .
'
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
770 ORDER BY timestamp DESC',
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)) {
791 $rset =
$DIC->database()->queryF(
793 FROM ' . self::$historyTable .
'
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]
802 while (($row =
$DIC->database()->fetchAssoc($rset))) {
803 $tmp = json_decode($row[
'message'],
false, 512, JSON_THROW_ON_ERROR);
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;
812 return $b_timestamp - $a_timestamp;
822 $DIC->database()->queryF(
823 'DELETE FROM ' . self::$historyTable .
' WHERE room_id = %s',
828 $DIC->database()->queryF(
829 'DELETE FROM ' . self::$sessionTable .
' WHERE room_id = %s AND disconnected < %s',
831 [$this->roomId, time()]
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
foreach($mandatory_scripts as $file) $timestamp
description of a localized parameter this information is used locate translations while processing no...
isProfilePictureVisible()
getUserId()
Returns Ilias User ID.
getUsername()
Returns username from Object or SESSION.
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.
saveSettings(array $settings)
getRefIdByRoomId(int $room_id)
connectUser(ilChatroomUser $user)
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)
isUserBanned(int $user_id)
getChatURL(ilChatroomObjectGUI $gui)
static byRoomId(int $room_id, bool $initObject=false)
isSubscribed(int $chat_userid)
static string $sessionTable
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 _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
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)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples