35 'object_id' =>
'integer',
36 'allow_anonymous' =>
'boolean',
37 'allow_custom_usernames' =>
'boolean',
38 'enable_history' =>
'boolean',
39 'restrict_history' =>
'boolean',
40 'autogen_usernames' =>
'string',
41 'room_type' =>
'string',
42 'allow_private_rooms' =>
'integer',
43 'display_past_msgs' =>
'integer',
44 'private_rooms_enabled' =>
'boolean'
57 return $this->
object->getTitle();
69 global $rbacsystem,
$lng;
71 if( !is_array($permissions) )
73 $permissions = array( $permissions );
76 foreach( $permissions as $permission )
78 if( !$rbacsystem->checkAccess( $permission,
$ref_id ) )
103 global $rbacsystem,
$lng;
105 if( !is_array($permissions) )
107 $permissions = array( $permissions );
110 foreach( $permissions as $permission )
112 if( !$rbacsystem->checkAccessOfUser(
$usr_id, $permission,
$ref_id ) )
128 return $this->
object->getDescription();
139 return $this->settings[$name];
150 $this->settings[$name] = $value;
176 if (is_array($message)) {
177 $subRoom = (int) $message[
'sub'];
179 else if (is_object($message)) {
180 $subRoom = (int) $message->sub;
186 'room_id' => array(
'integer', $this->roomId),
187 'sub_room' => array(
'integer', $subRoom),
188 'message' => array(
'text', json_encode($message)),
189 'timestamp' => array(
'integer', time()),
218 $query =
'SELECT user_id FROM ' . self::$userTable .
' WHERE room_id = %s AND user_id = %s';
219 $types = array(
'integer',
'integer');
220 $values = array($this->roomId, $user->
getUserId());
222 if(!$ilDB->fetchAssoc($ilDB->queryF($query, $types, $values)))
227 'room_id' => array(
'integer', $this->roomId),
228 'user_id' => array(
'integer', $user->
getUserId()),
229 'userdata' => array(
'text', json_encode($userdata)),
230 'connected' => array(
'integer', time()),
253 $query =
'SELECT userdata FROM ' . self::$userTable .
' WHERE room_id = %s';
254 $types = array(
'integer');
255 $values = array($this->roomId);
256 $rset = $ilDB->queryF( $query, $types, $values );
259 while(
$row = $ilDB->fetchAssoc( $rset ) )
261 $users[] = json_decode(
$row[
'userdata'] );
291 $query =
'SELECT * FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
292 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
294 $types = array(
'integer');
295 $values = array($this->roomId);
296 $rset = $ilDB->queryF( $query, $types, $values );
298 if(
$row = $ilDB->fetchAssoc( $rset ) )
300 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE parent_id = %s';
301 $rset_prooms = $ilDB->queryF($query, array(
'integer'), array($this->roomId));
305 while($row_prooms = $ilDB->fetchAssoc($rset_prooms)) {
306 $prooms[] = $row_prooms[
'proom_id'];
309 if (
true || $this->
getSetting(
'enable_history' )) {
310 $query =
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = %s WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
311 $ilDB->manipulateF($query, array(
'integer'), array(time()));
314 $query =
'DELETE FROM ' . self::$privateSessionsTable .
' WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
315 $ilDB->manipulate($query);
318 $query =
'DELETE FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
319 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
321 $types = array(
'integer');
322 $values = array($this->roomId);
323 $ilDB->manipulateF( $query, $types, $values );
331 'room_id' => array(
'integer', $this->roomId),
332 'user_id' => array(
'integer',
$row[
'user_id']),
333 'userdata' => array(
'text',
$row[
'userdata']),
334 'connected' => array(
'integer',
$row[
'connected']),
335 'disconnected' => array(
'integer', time()),
340 while(
$row = $ilDB->fetchAssoc( $rset ) );
365 $localSettings = array();
367 foreach( $this->availableSettings as $setting => $type )
369 if( isset( $settings[$setting] ) ) {
370 if ($type ==
'boolean') {
371 $settings[$setting] = (boolean)$settings[$setting];
373 $localSettings[$setting] = array($this->
phpTypeToMDBType($type), $settings[$setting]);
377 if (!$localSettings[
'room_type'][1]) {
378 $localSettings[
'room_type'][1] =
'repository';
384 self::$settingsTable,
386 array(
'room_id' => array(
'integer', $this->roomId) )
391 $this->roomId = $ilDB->nextId( self::$settingsTable );
393 $localSettings[
'room_id'] = array(
394 $this->availableSettings[
'room_id'], $this->roomId
397 $ilDB->insert( self::$settingsTable, $localSettings );
421 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE object_id = %s';
422 $types = array(
'integer');
423 $values = array($object_id);
424 $rset = $ilDB->queryF( $query, $types, $values );
426 if(
$row = $ilDB->fetchAssoc( $rset ) )
429 $room->initialize(
$row );
441 public static function byRoomId($room_id, $initObject =
false)
445 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE room_id = %s';
447 $types = array(
'integer');
448 $values = array($room_id);
450 $rset = $ilDB->queryF( $query, $types, $values );
452 if(
$row = $ilDB->fetchAssoc( $rset ) )
455 $room->initialize(
$row );
473 $this->roomId = $rowdata[
'room_id'];
475 foreach( $this->availableSettings as $setting => $type )
477 if( isset($rowdata[$setting]) )
479 settype($rowdata[$setting], $this->availableSettings[$setting]);
480 $this->
setSetting( $setting, $rowdata[$setting] );
507 $query =
'SELECT count(user_id) as cnt FROM ' . self::$userTable .
508 ' WHERE room_id = %s AND user_id = %s';
510 $types = array(
'integer',
'integer');
511 $values = array($this->roomId, $chat_userid);
512 $rset = $ilDB->queryF( $query, $types, $values );
514 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
524 $query =
'SELECT count(user_id) cnt FROM ' . self::$privateRoomsAccessTable .
525 ' WHERE proom_id = %s AND user_id = %s';
527 $types = array(
'integer',
'integer');
528 $values = array($proom_id, $chat_userid);
529 $rset = $ilDB->queryF( $query, $types, $values );
531 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
534 $query =
'SELECT count(*) cnt FROM ' . self::$privateRoomsTable .
535 ' WHERE proom_id = %s AND owner = %s';
537 $types = array(
'integer',
'integer');
538 $values = array($proom_id, $chat_userid);
539 $rset = $ilDB->queryF( $query, $types, $values );
541 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
556 $ilDB->manipulate(
'DELETE FROM ' . self::$userTable );
557 $ilDB->manipulate(
'UPDATE ' . self::$privateRoomsTable .
' SET closed = ' . $ilDB->quote( time() ,
'integer') .
' WHERE closed = 0 OR closed IS NULL');
558 $ilDB->manipulate(
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = ' . $ilDB->quote( time() ,
'integer') .
' WHERE disconnected = 0 OR disconnected IS NULL');
581 $join .=
' INNER JOIN ' . self::$privateSessionsTable .
582 ' pSessionTable ON pSessionTable.user_id = ' .
583 $ilDB->quote( $restricted_session_userid,
'integer' ) .
584 ' AND historyTable.sub_room = pSessionTable.proom_id AND timestamp >= pSessionTable.connected AND timestamp <= pSessionTable.disconnected ';
587 $query =
'SELECT historyTable.* FROM ' . self::$historyTable .
' historyTable ' .
588 $join .
' WHERE historyTable.room_id = ' . $this->
getRoomId();
594 $filter[] =
'timestamp >= ' . $ilDB->quote( $from->getUnixTime(),
'integer' );
599 $filter[] =
'timestamp <= ' . $ilDB->quote( $to->getUnixTime(),
'integer' );
603 $query .=
' AND ' . join(
' AND ', $filter );
604 $query .=
' ORDER BY timestamp ASC';
606 $rset = $ilDB->query( $query );
609 while(
$row = $ilDB->fetchAssoc( $rset ) )
611 $row[
'message'] = json_decode(
$row[
'message'] );
612 $row[
'message']->timestamp =
$row[
'timestamp'];
613 if (
$row[
'message']->
public !== null && !
$row[
'message']->
public && !in_array($ilUser->getId(), explode(
',',
$row[
'recipients']))) {
625 $query =
'SELECT proom_id, title FROM ' . self::$privateRoomsTable .
' WHERE proom_id IN (
626 SELECT proom_id FROM '.self::$privateSessionsTable.
' WHERE connected >= %s AND disconnected <= %s AND user_id = %s
628 ) AND parent_id = %s';
630 $rset = $ilDB->queryF($query, array(
'integer',
'integer',
'integer',
'integer'), array($from->getUnixTime(), $to->getUnixTime(), $user_id, $room_id));
632 while(
$row = $ilDB->fetchAssoc( $rset ) )
651 $upload_id = $ilDB->nextId( self::$uploadTable );
656 'upload_id' => array(
'integer', $upload_id),
657 'room_id' => array(
'integer', $this->roomId),
658 'user_id' => array(
'integer', $user_id),
660 'filetype' => array(
'text', $type),
661 'timestamp' => array(
'integer', time())
680 'room_id' => array(
'integer', $this->roomId),
681 'user_id' => array(
'integer', $user_id),
682 'timestamp' => array(
'integer', time()),
683 'remark' => array(
'text',
$comment),
700 if( !is_array( $user_id ) )
701 $user_id = array($user_id);
703 $query =
'DELETE FROM ' . self::$banTable .
' WHERE room_id = %s AND ' .
704 $ilDB->in(
'user_id', $user_id,
false,
'integer' );
706 $types = array(
'integer');
709 return $ilDB->manipulateF( $query, $types, $values );
724 $query =
'SELECT count(user_id) cnt FROM ' . self::$banTable .
725 ' WHERE user_id = %s AND room_id = %s';
727 $types = array(
'integer',
'integer');
728 $values = array($user_id, $this->
getRoomId());
730 $rset = $ilDB->queryF( $query, $types, $values );
732 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] )
749 $query =
'SELECT * FROM ' . self::$banTable .
' WHERE room_id = %s ';
750 $types = array(
'integer');
752 $rset = $ilDB->queryF( $query, $types, $values );
757 while(
$row = $ilDB->fetchAssoc( $rset ) )
759 if(
$row[
'user_id'] > 0 )
763 'user_id' => $user->getId(),
764 'firstname' => $user->getFirstname(),
765 'lastname' => $user->getLastname(),
766 'login' => $user->getLogin(),
767 'remark' =>
$row[
'remark']
796 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
797 $ilDB->quote( $user->
getUserId(),
'integer' ) .
798 ' ORDER BY connected DESC';
800 $ilDB->setLimit( 1 );
801 $rset = $ilDB->query( $query );
803 if(
$row = $ilDB->fetchAssoc( $rset ) )
823 $query =
'SELECT * FROM ' . self::$sessionTable
824 .
' WHERE room_id = '.
825 $ilDB->quote( $this->
getRoomId(),
'integer' ) .
826 ' ORDER BY connected DESC';
828 $rset = $ilDB->query( $query );
832 while(
$row = $ilDB->fetchAssoc( $rset ) )
844 $nextId = $ilDB->nextId(
'chatroom_prooms');
847 self::$privateRoomsTable,
849 'proom_id' => array(
'integer', $nextId),
850 'parent_id' => array(
'integer', $this->roomId),
851 'title' => array(
'text',
$title),
852 'owner' => array(
'integer', $owner->
getUserId()),
853 'created' => array(
'integer', time()),
854 'is_public' => array(
'integer',
$settings[
'public']),
866 'UPDATE ' . self::$privateRoomsTable .
' SET closed = %s WHERE proom_id = %s',
867 array(
'integer',
'integer'),
875 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE proom_id = %s AND owner = %s';
876 $types = array(
'integer',
'integer');
877 $values = array($proom_id, $user_id);
879 $rset = $ilDB->queryF($query, $types, $values);
881 if ($rset && $ilDB->fetchAssoc($rset)) {
891 public function inviteUserToPrivateRoom($user_id, $proom_id)
898 $query =
'DELETE FROM ' . self::$privateRoomsAccessTable .
' WHERE user_id = %s AND proom_id = %s';
899 $types = array(
'integer',
'integer');
900 $values = array($user_id, $proom_id);
902 $ilDB->manipulateF($query, $types, $values);
904 $ilDB->insert(self::$privateRoomsAccessTable, array(
905 'user_id' => array(
'integer', $user_id),
906 'proom_id' => array(
'integer', $proom_id)
918 include_once
'Services/Link/classes/class.ilLink.php';
945 public function sendInvitationNotification($gui, $sender, $recipient_id, $subScope = 0, $invitationLink =
'')
952 if($gui && !$invitationLink)
954 $invitationLink = $this->
getChatURL($gui, $subScope);
957 if($recipient_id > 0 && !in_array(ANONYMOUS_USER_ID, array($recipient_id)))
959 if(is_numeric($sender) && $sender > 0)
961 $sender_id = $sender;
966 $public_name = $usr->getPublicName();
970 if($sender->getUserId() > 0)
972 $sender_id = $sender->getUserId();
976 $sender_id = ANONYMOUS_USER_ID;
978 $public_name = $sender->getUsername();
982 throw new InvalidArgumentException(
'$sender must be an instance of ilChatroomUser or an id of an ilObjUser instance');
985 $lng->loadLanguageModule(
'mail');
989 'link' => $invitationLink,
990 'inviter_name' => $public_name,
992 'salutation' => $lng->txt(
'mail_salutation_' . $recipient->getGender()) .
' ' . $recipient->getFullname()
1000 require_once
'Services/Notifications/classes/class.ilNotificationConfig.php';
1002 $notification->setTitleVar(
'chat_invitation', $bodyParams,
'chatroom');
1003 $notification->setShortDescriptionVar(
'chat_invitation_short', $bodyParams,
'chatroom');
1004 $notification->setLongDescriptionVar(
'chat_invitation_long', $bodyParams,
'chatroom');
1005 $notification->setAutoDisable(
false);
1006 $notification->setLink($invitationLink);
1007 $notification->setIconPath(
'templates/default/images/icon_chtr_s.png');
1008 $notification->setValidForSeconds(0);
1010 $notification->setHandlerParam(
'mail.sender', $sender_id);
1012 $notification->notifyByUsers(array($recipient_id));
1019 $this->inviteUserToPrivateRoom($user_id, $proom_id);
1025 $query =
'SELECT title FROM ' . self::$privateRoomsTable .
' WHERE proom_id = %s';
1026 $types = array(
'integer');
1027 $values = array($proom_id);
1029 $rset = $ilDB->queryF($query, $types, $values);
1031 if (
$row = $ilDB->fetchAssoc($rset)) {
1032 return $row[
'title'];
1043 SELECT roomtable.title, roomtable.proom_id, accesstable.user_id id, roomtable.owner owner FROM ' . self::$privateRoomsTable .
' roomtable
1044 LEFT JOIN '.self::$privateRoomsAccessTable.
' accesstable ON roomtable.proom_id = accesstable.proom_id AND accesstable.user_id = %s
1045 WHERE parent_id = %s AND (closed = 0 OR closed IS NULL) AND (accesstable.user_id IS NOT NULL OR roomtable.owner = %s)';
1046 $types = array(
'integer',
'integer',
'integer');
1047 $values = array($userid, $this->roomId, $userid);
1048 $rset = $ilDB->queryF( $query, $types, $values );
1051 while(
$row = $ilDB->fetchAssoc( $rset ) )
1064 $query =
'SELECT user_id FROM ' . self::$privateSessionsTable .
' WHERE proom_id = %s AND disconnected = 0 OR disconnected IS NULL';
1065 $types = array(
'integer');
1066 $values = array($private_room_id);
1067 $rset = $ilDB->queryF( $query, $types, $values );
1071 while (
$row = $ilDB->fetchAssoc($rset)) {
1072 $users[] =
$row[
'user_id'];
1082 $query =
'SELECT proom_id id FROM ' . self::$privateSessionsTable .
' WHERE user_id = %s AND proom_id = %s AND disconnected = 0 OR disconnected IS NULL';
1083 $types = array(
'integer',
'integer');
1084 $values = array($user_id, $room_id);
1085 $rset = $ilDB->queryF( $query, $types, $values );
1086 if ($ilDB->fetchAssoc($rset))
1097 self::$privateSessionsTable,
1099 'proom_id' => array(
'integer', $room_id),
1100 'user_id' => array(
'integer', $user_id),
1101 'connected' => array(
'integer', time()),
1102 'disconnected' => array(
'integer', 0),
1119 self::$privateSessionsTable,
1121 'disconnected' => array(
'integer', time())
1124 'proom_id' => array(
'integer', $room_id),
1125 'user_id' => array(
'integer', $user_id),
1133 $query =
'SELECT count(user_id) as cnt FROM ' . self::$userTable .
1134 ' WHERE room_id = %s';
1136 $types = array(
'integer');
1137 $values = array($this->roomId);
1138 $rset = $ilDB->queryF( $query, $types, $values );
1140 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
1149 $query =
'SELECT title FROM ' . self::$privateRoomsTable .
' WHERE parent_id = %s and closed = 0';
1150 $rset = $ilDB->queryF($query, array(
'integer'), array($this->roomId));
1154 while(
$row = $ilDB->fetchAssoc($rset)) {
1155 $titles[] =
$row[
'title'];
1161 if(!in_array(
$title . $suffix, $titles)) {
1168 $suffix =
' (' . $i .
')';
1177 $query =
'SELECT private_rooms.proom_id id, MIN(disconnected) min_disconnected, MAX(disconnected) max_disconnected FROM ' . self::$privateSessionsTable .
' private_sessions INNER JOIN '.self::$privateRoomsTable.
' private_rooms ON private_sessions.proom_id = private_rooms.proom_id WHERE closed = 0 GROUP BY private_rooms.proom_id HAVING min_disconnected > 0 AND max_disconnected < %s';
1178 $rset = $ilDB->queryF(
1181 array(time() + 60 * 5)
1186 while (
$row = $ilDB->fetchAssoc($rset)) {
1187 $rooms[] =
$row[
'id'];
1190 $query =
'SELECT DISTINCT proom_id, room_id, object_id FROM ' . self::$privateRoomsTable
1191 .
' INNER JOIN ' . self::$settingsTable .
' ON parent_id = room_id '
1192 .
' WHERE ' . $ilDB->in(
'proom_id', $rooms,
false,
'integer');
1194 $rset = $ilDB->query($query);
1196 while(
$row = $ilDB->fetchAssoc($rset)) {
1198 'proom_id' =>
$row[
'proom_id'],
1199 'room_id' =>
$row[
'room_id'],
1200 'object_id' =>
$row[
'object_id']
1215 public function getAllRooms($user_id)
1223 SELECT room_id, od.title
1226 INNER JOIN " . self::$settingsTable .
"
1227 ON object_id = od.obj_id
1229 INNER JOIN " . self::$privateRoomsTable .
" prt
1232 WHERE od.type = 'chtr'
1235 $types = array(
'integer');
1236 $values = array($user_id);
1238 $res = $ilDB->queryF($query, $types, $values);
1242 while(
$row = $ilDB->fetchAssoc(
$res))
1244 $room_id =
$row[
'room_id'];
1245 $rooms[$room_id] =
$row[
'title'];
1258 SELECT proom_id, parent_id
1259 FROM chatroom_prooms
1260 WHERE parent_id = %s
1265 $types = array(
'integer',
'integer' );
1266 $values = array( $parent_room, $user_id );
1268 $res = $ilDB->queryF( $query, $types, $values );
1270 $priv_rooms = array();
1272 while(
$row = $ilDB->fetchAssoc(
$res ) )
1274 $proom_id =
$row[
'proom_id'];
1275 $priv_rooms[$proom_id] =
$row[
'parent_id'];
1294 FROM object_reference objr
1296 INNER JOIN chatroom_settings cs
1297 ON cs.object_id = objr.obj_id
1299 INNER JOIN object_data od
1300 ON od.obj_id = cs.object_id
1302 WHERE cs.room_id = %s
1305 $types = array(
'integer' );
1306 $values = array( $room_id );
1308 $res = $ilDB->queryF( $query, $types, $values );
1312 return $row[
'ref_id'];
1321 $ilDB->setLimit($number * 2);
1322 $rset = $ilDB->queryF(
'SELECT * FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = 0 ORDER BY timestamp DESC', array(
'integer'), array($this->roomId));
1326 while((
$row = $ilDB->fetchAssoc($rset)) && $result_count < $number) {
1327 $tmp = json_decode(
$row[
'message']);
1328 if ($chatuser !== null && $tmp->public == 0 && $tmp->recipients) {
1329 if (in_array($chatuser->getUserId(), explode(
',',$tmp->recipients))) {
1334 else if ($tmp->public == 1) {
1343 public function getLastMessagesForChatViewer($number, $chatuser = null)
1350 $ilDB->setLimit($number);
1351 $rset = $ilDB->query(
1353 FROM ' . self::$historyTable .
'
1354 WHERE room_id = '.$ilDB->quote($this->roomId,
'integer').
'
1357 (' . $ilDB->like(
'message',
'text',
'%"type":"message"%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"public":1%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"recipients":null%') .
')
1359 ' . $ilDB->like(
'message',
'text',
'%"type":"%connected"%') .
')
1360 ORDER BY timestamp DESC'
1364 while((
$row = $ilDB->fetchAssoc($rset)))
1366 $tmp = json_decode(
$row[
'message']);
1367 if($tmp->type !=
'message' &&
$row[
'timestamp'] && !is_numeric($tmp->timestamp))
1369 $tmp->timestamp =
$row[
'timestamp'] * 1000;
1380 'DELETE FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = %s',
1381 array(
'integer',
'integer'),
1382 array($this->roomId, (
int)$sub_room)
1387 'DELETE FROM ' . self::$sessionTable .
' WHERE proom_id = %s AND disconnected < %s',
1388 array(
'integer',
'integer'),
1389 array($sub_room, time())
1394 'DELETE FROM ' . self::$sessionTable .
' WHERE room_id = %s AND disconnected < %s',
1395 array(
'integer',
'integer'),
1396 array($this->roomId, time())
1401 public static function getUntrashedChatReferences()
1411 SELECT od.obj_id, od.title, ore.ref_id, od.type
1413 INNER JOIN object_reference ore ON ore.obj_id = od.obj_id
1414 INNER JOIN tree t ON t.child = ore.ref_id
1415 INNER JOIN object_reference pre ON pre.ref_id = t.parent
1416 INNER JOIN object_data pod ON pod.obj_id = pre.obj_id
1417 WHERE od.type = %s AND t.tree > 0 AND ore.deleted IS NULL
1420 $res = $ilDB->queryF($query, array(
'text'), array(
'chtr'));
1423 while(
$row = $ilDB->fetchAssoc(
$res))