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()),
215 $query =
'SELECT user_id FROM ' . self::$userTable .
216 ' WHERE room_id = %s AND user_id = %s';
218 $types = array(
'integer',
'integer');
219 $values = array($this->roomId, $user->
getUserId());
221 if( !$ilDB->fetchAssoc( $ilDB->queryF( $query, $types, $values ) ) )
226 'room_id' => array(
'integer', $this->roomId),
227 'user_id' => array(
'integer', $user->
getUserId()),
228 'userdata' => array(
'text', json_encode( $userdata )),
229 'connected' => array(
'integer', time()),
252 $query =
'SELECT userdata FROM ' . self::$userTable .
' WHERE room_id = %s';
253 $types = array(
'integer');
254 $values = array($this->roomId);
255 $rset = $ilDB->queryF(
$query, $types, $values );
258 while(
$row = $ilDB->fetchAssoc( $rset ) )
260 $users[] = json_decode(
$row[
'userdata'] );
290 $query =
'SELECT * FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
291 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
293 $types = array(
'integer');
294 $values = array($this->roomId);
295 $rset = $ilDB->queryF(
$query, $types, $values );
297 if(
$row = $ilDB->fetchAssoc( $rset ) )
299 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE parent_id = %s';
300 $rset_prooms = $ilDB->queryF(
$query, array(
'integer'), array($this->roomId));
304 while($row_prooms = $ilDB->fetchAssoc($rset_prooms)) {
305 $prooms[] = $row_prooms[
'proom_id'];
308 if (
true || $this->
getSetting(
'enable_history' )) {
309 $query =
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = %s WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
310 $ilDB->manipulateF(
$query, array(
'integer'), array(time()));
313 $query =
'DELETE FROM ' . self::$privateSessionsTable .
' WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
314 $ilDB->manipulate(
$query);
317 $query =
'DELETE FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
318 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
320 $types = array(
'integer');
321 $values = array($this->roomId);
322 $ilDB->manipulateF(
$query, $types, $values );
330 'room_id' => array(
'integer', $this->roomId),
331 'user_id' => array(
'integer',
$row[
'user_id']),
332 'userdata' => array(
'text',
$row[
'userdata']),
333 'connected' => array(
'integer',
$row[
'connected']),
334 'disconnected' => array(
'integer', time()),
339 while(
$row = $ilDB->fetchAssoc( $rset ) );
364 $localSettings = array();
366 foreach( $this->availableSettings as $setting => $type )
368 if( isset( $settings[$setting] ) ) {
369 if ($type ==
'boolean') {
370 $settings[$setting] = (boolean)$settings[$setting];
372 $localSettings[$setting] = array($this->
phpTypeToMDBType($type), $settings[$setting]);
376 if (!$localSettings[
'room_type'][1]) {
377 $localSettings[
'room_type'][1] =
'repository';
383 self::$settingsTable,
385 array(
'room_id' => array(
'integer', $this->roomId) )
390 $this->roomId = $ilDB->nextId( self::$settingsTable );
392 $localSettings[
'room_id'] = array(
393 $this->availableSettings[
'room_id'], $this->roomId
396 $ilDB->insert( self::$settingsTable, $localSettings );
420 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE object_id = %s';
421 $types = array(
'integer');
422 $values = array($object_id);
423 $rset = $ilDB->queryF(
$query, $types, $values );
425 if(
$row = $ilDB->fetchAssoc( $rset ) )
428 $room->initialize(
$row );
440 public static function byRoomId($room_id, $initObject =
false)
444 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE room_id = %s';
446 $types = array(
'integer');
447 $values = array($room_id);
449 $rset = $ilDB->queryF(
$query, $types, $values );
451 if(
$row = $ilDB->fetchAssoc( $rset ) )
454 $room->initialize(
$row );
472 $this->roomId = $rowdata[
'room_id'];
474 foreach( $this->availableSettings as $setting => $type )
476 if( isset($rowdata[$setting]) )
478 settype($rowdata[$setting], $this->availableSettings[$setting]);
479 $this->
setSetting( $setting, $rowdata[$setting] );
506 $query =
'SELECT count(user_id) as cnt FROM ' . self::$userTable .
507 ' WHERE room_id = %s AND user_id = %s';
509 $types = array(
'integer',
'integer');
510 $values = array($this->roomId, $chat_userid);
511 $rset = $ilDB->queryF(
$query, $types, $values );
513 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
523 $query =
'SELECT count(user_id) cnt FROM ' . self::$privateRoomsAccessTable .
524 ' WHERE proom_id = %s AND user_id = %s';
526 $types = array(
'integer',
'integer');
527 $values = array($proom_id, $chat_userid);
528 $rset = $ilDB->queryF(
$query, $types, $values );
530 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
533 $query =
'SELECT count(*) cnt FROM ' . self::$privateRoomsTable .
534 ' WHERE proom_id = %s AND owner = %s';
536 $types = array(
'integer',
'integer');
537 $values = array($proom_id, $chat_userid);
538 $rset = $ilDB->queryF(
$query, $types, $values );
540 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
555 $ilDB->manipulate(
'DELETE FROM ' . self::$userTable );
556 $ilDB->manipulate(
'UPDATE ' . self::$privateRoomsTable .
' SET closed = ' . $ilDB->quote( time() ,
'integer') .
' WHERE closed = 0 OR closed IS NULL');
557 $ilDB->manipulate(
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = ' . $ilDB->quote( time() ,
'integer') .
' WHERE disconnected = 0 OR disconnected IS NULL');
575 global
$ilDB, $ilUser;
580 $join .=
' INNER JOIN ' . self::$privateSessionsTable .
581 ' pSessionTable ON pSessionTable.user_id = ' .
582 $ilDB->quote( $restricted_session_userid,
'integer' ) .
583 ' AND historyTable.sub_room = pSessionTable.proom_id AND timestamp >= pSessionTable.connected AND timestamp <= pSessionTable.disconnected ';
586 $query =
'SELECT historyTable.* FROM ' . self::$historyTable .
' historyTable ' .
587 $join .
' WHERE historyTable.room_id = ' . $this->
getRoomId();
593 $filter[] =
'timestamp >= ' . $ilDB->quote( $from->getUnixTime(),
'integer' );
598 $filter[] =
'timestamp <= ' . $ilDB->quote( $to->getUnixTime(),
'integer' );
602 $query .=
' AND ' . join(
' AND ', $filter );
603 $query .=
' ORDER BY timestamp ASC';
605 $rset = $ilDB->query(
$query );
608 while(
$row = $ilDB->fetchAssoc( $rset ) )
610 $row[
'message'] = json_decode(
$row[
'message'] );
611 $row[
'message']->timestamp =
$row[
'timestamp'];
612 if (
$row[
'message']->
public !== null && !
$row[
'message']->
public && !in_array($ilUser->getId(), explode(
',',
$row[
'recipients']))) {
624 $query =
'SELECT proom_id, title FROM ' . self::$privateRoomsTable .
' WHERE proom_id IN (
625 SELECT proom_id FROM '.self::$privateSessionsTable.
' WHERE connected >= %s AND disconnected <= %s AND user_id = %s
627 ) AND parent_id = %s';
629 $rset = $ilDB->queryF(
$query, array(
'integer',
'integer',
'integer',
'integer'), array($from->getUnixTime(), $to->getUnixTime(), $user_id, $room_id));
631 while(
$row = $ilDB->fetchAssoc( $rset ) )
650 $upload_id = $ilDB->nextId( self::$uploadTable );
655 'upload_id' => array(
'integer', $upload_id),
656 'room_id' => array(
'integer', $this->roomId),
657 'user_id' => array(
'integer', $user_id),
659 'filetype' => array(
'text', $type),
660 'timestamp' => array(
'integer', time())
679 'room_id' => array(
'integer', $this->roomId),
680 'user_id' => array(
'integer', $user_id),
681 'timestamp' => array(
'integer', time()),
682 'remark' => array(
'text',
$comment),
699 if( !is_array( $user_id ) )
700 $user_id = array($user_id);
702 $query =
'DELETE FROM ' . self::$banTable .
' WHERE room_id = %s AND ' .
703 $ilDB->in(
'user_id', $user_id,
false,
'integer' );
705 $types = array(
'integer');
708 return $ilDB->manipulateF(
$query, $types, $values );
723 $query =
'SELECT count(user_id) cnt FROM ' . self::$banTable .
724 ' WHERE user_id = %s AND room_id = %s';
726 $types = array(
'integer',
'integer');
727 $values = array($user_id, $this->
getRoomId());
729 $rset = $ilDB->queryF(
$query, $types, $values );
731 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] )
748 $query =
'SELECT * FROM ' . self::$banTable .
' WHERE room_id = %s ';
749 $types = array(
'integer');
751 $rset = $ilDB->queryF(
$query, $types, $values );
756 while(
$row = $ilDB->fetchAssoc( $rset ) )
758 if(
$row[
'user_id'] > 0 )
762 'user_id' => $user->getId(),
763 'firstname' => $user->getFirstname(),
764 'lastname' => $user->getLastname(),
765 'login' => $user->getLogin(),
766 'remark' =>
$row[
'remark']
795 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
796 $ilDB->quote( $user->
getUserId(),
'integer' ) .
797 ' ORDER BY connected DESC';
799 $ilDB->setLimit( 1 );
800 $rset = $ilDB->query(
$query );
802 if(
$row = $ilDB->fetchAssoc( $rset ) )
822 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
823 $ilDB->quote( $user->
getUserId(),
'integer' ) .
' AND room_id = '.
824 $ilDB->quote( $this->getRoomId(),
'integer' ) .
825 ' ORDER BY connected DESC';
827 $rset = $ilDB->query(
$query );
831 while(
$row = $ilDB->fetchAssoc( $rset ) )
843 $nextId = $ilDB->nextId(
'chatroom_prooms');
846 self::$privateRoomsTable,
848 'proom_id' => array(
'integer', $nextId),
849 'parent_id' => array(
'integer', $this->roomId),
850 'title' => array(
'text',
$title),
851 'owner' => array(
'integer', $owner->
getUserId()),
852 'created' => array(
'integer', time()),
853 'is_public' => array(
'integer',
$settings[
'public']),
865 'UPDATE ' . self::$privateRoomsTable .
' SET closed = %s WHERE proom_id = %s',
866 array(
'integer',
'integer'),
874 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE proom_id = %s AND owner = %s';
875 $types = array(
'integer',
'integer');
876 $values = array($proom_id, $user_id);
878 $rset = $ilDB->queryF(
$query, $types, $values);
880 if ($rset && $ilDB->fetchAssoc($rset)) {
889 $query =
'DELETE FROM ' . self::$privateRoomsAccessTable .
' WHERE user_id = %s AND proom_id = %s';
890 $types = array(
'integer',
'integer');
891 $values = array($user_id, $proom_id);
893 $ilDB->manipulateF(
$query, $types, $values);
895 $ilDB->insert(self::$privateRoomsAccessTable, array(
896 'user_id' => array(
'integer', $user_id),
897 'proom_id' => array(
'integer', $proom_id)
918 include_once
'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));
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']
1220 SELECT room_id, od.title
1223 INNER JOIN " . self::$settingsTable .
"
1224 ON object_id = od.obj_id
1226 INNER JOIN " . self::$privateRoomsTable .
" prt
1229 WHERE od.type = 'chtr'
1232 $types = array(
'integer' );
1233 $values = array( $user_id );
1235 $res = $ilDB->queryF(
$query, $types, $values );
1239 while(
$row = $ilDB->fetchAssoc(
$res ) )
1241 $room_id =
$row[
'room_id'];
1242 $rooms[$room_id] =
$row[
'title'];
1255 SELECT proom_id, parent_id
1256 FROM chatroom_prooms
1257 WHERE parent_id = %s
1262 $types = array(
'integer',
'integer' );
1263 $values = array( $parent_room, $user_id );
1265 $res = $ilDB->queryF(
$query, $types, $values );
1267 $priv_rooms = array();
1269 while(
$row = $ilDB->fetchAssoc(
$res ) )
1271 $proom_id =
$row[
'proom_id'];
1272 $priv_rooms[$proom_id] =
$row[
'parent_id'];
1291 FROM object_reference objr
1293 INNER JOIN chatroom_settings cs
1294 ON cs.object_id = objr.obj_id
1296 INNER JOIN object_data od
1297 ON od.obj_id = cs.object_id
1299 WHERE cs.room_id = %s
1302 $types = array(
'integer' );
1303 $values = array( $room_id );
1305 $res = $ilDB->queryF(
$query, $types, $values );
1309 return $row[
'ref_id'];
1318 $ilDB->setLimit($number * 2);
1319 $rset = $ilDB->queryF(
'SELECT * FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = 0 ORDER BY timestamp DESC', array(
'integer'), array($this->roomId));
1323 while((
$row = $ilDB->fetchAssoc($rset)) && $result_count < $number) {
1324 $tmp = json_decode(
$row[
'message']);
1325 if ($chatuser !== null && $tmp->public == 0 && $tmp->recipients) {
1326 if (in_array($chatuser->getUserId(), explode(
',',$tmp->recipients))) {
1331 else if ($tmp->public == 1) {
1340 public function getLastMessagesForChatViewer($number, $chatuser = null)
1347 $ilDB->setLimit($number);
1348 $rset = $ilDB->query(
1350 FROM ' . self::$historyTable .
'
1351 WHERE room_id = '.$ilDB->quote($this->roomId,
'integer').
'
1354 (' . $ilDB->like(
'message',
'text',
'%"type":"message"%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"public":1%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"recipients":null%') .
')
1356 ' . $ilDB->like(
'message',
'text',
'%"type":"%connected"%') .
')
1357 ORDER BY timestamp DESC'
1361 while((
$row = $ilDB->fetchAssoc($rset)))
1363 $tmp = json_decode(
$row[
'message']);
1373 'DELETE FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = %s',
1374 array(
'integer',
'integer'),
1375 array($this->roomId, (
int)$sub_room)
1380 'DELETE FROM ' . self::$sessionTable .
' WHERE proom_id = %s AND disconnected < %s',
1381 array(
'integer',
'integer'),
1382 array($sub_room, time())
1387 'DELETE FROM ' . self::$sessionTable .
' WHERE room_id = %s AND disconnected < %s',
1388 array(
'integer',
'integer'),
1389 array($this->roomId, time())
1394 public static function getUntrashedChatReferences()
1404 SELECT od.obj_id, od.title, ore.ref_id, od.type
1406 INNER JOIN object_reference ore ON ore.obj_id = od.obj_id
1407 INNER JOIN tree t ON t.child = ore.ref_id
1408 INNER JOIN object_reference pre ON pre.ref_id = t.parent
1409 INNER JOIN object_data pod ON pod.obj_id = pre.obj_id
1410 WHERE od.type = %s AND t.tree > 0 AND ore.deleted IS NULL
1413 $res = $ilDB->queryF(
$query, array(
'text'), array(
'chtr'));
1416 while(
$row = $ilDB->fetchAssoc(
$res))