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)))
229 'room_id' => array(
'integer', $this->roomId),
230 'user_id' => array(
'integer', $user->
getUserId())
233 'userdata' => array(
'text', json_encode($userdata)),
234 'connected' => array(
'integer', time()),
257 $query =
'SELECT userdata FROM ' . self::$userTable .
' WHERE room_id = %s';
258 $types = array(
'integer');
259 $values = array($this->roomId);
260 $rset = $ilDB->queryF( $query, $types, $values );
263 while(
$row = $ilDB->fetchAssoc( $rset ) )
265 $users[] = json_decode(
$row[
'userdata'] );
295 $query =
'SELECT * FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
296 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
298 $types = array(
'integer');
299 $values = array($this->roomId);
300 $rset = $ilDB->queryF( $query, $types, $values );
302 if(
$row = $ilDB->fetchAssoc( $rset ) )
304 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE parent_id = %s';
305 $rset_prooms = $ilDB->queryF($query, array(
'integer'), array($this->roomId));
309 while($row_prooms = $ilDB->fetchAssoc($rset_prooms)) {
310 $prooms[] = $row_prooms[
'proom_id'];
313 if (
true || $this->
getSetting(
'enable_history' )) {
314 $query =
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = %s WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
315 $ilDB->manipulateF($query, array(
'integer'), array(time()));
318 $query =
'DELETE FROM ' . self::$privateSessionsTable .
' WHERE ' . $ilDB->in(
'user_id', $userIds,
false,
'integer') .
' AND ' . $ilDB->in(
'proom_id', $prooms,
false,
'integer');
319 $ilDB->manipulate($query);
322 $query =
'DELETE FROM ' . self::$userTable .
' WHERE room_id = %s AND ' .
323 $ilDB->in(
'user_id', $userIds,
false,
'integer' );
325 $types = array(
'integer');
326 $values = array($this->roomId);
327 $ilDB->manipulateF( $query, $types, $values );
335 'room_id' => array(
'integer', $this->roomId),
336 'user_id' => array(
'integer',
$row[
'user_id']),
337 'userdata' => array(
'text',
$row[
'userdata']),
338 'connected' => array(
'integer',
$row[
'connected']),
339 'disconnected' => array(
'integer', time()),
344 while(
$row = $ilDB->fetchAssoc( $rset ) );
369 $localSettings = array();
371 foreach( $this->availableSettings as $setting => $type )
373 if( isset( $settings[$setting] ) ) {
374 if ($type ==
'boolean') {
375 $settings[$setting] = (boolean)$settings[$setting];
377 $localSettings[$setting] = array($this->
phpTypeToMDBType($type), $settings[$setting]);
381 if (!$localSettings[
'room_type'][1]) {
382 $localSettings[
'room_type'][1] =
'repository';
388 self::$settingsTable,
390 array(
'room_id' => array(
'integer', $this->roomId) )
395 $this->roomId = $ilDB->nextId( self::$settingsTable );
397 $localSettings[
'room_id'] = array(
398 $this->availableSettings[
'room_id'], $this->roomId
401 $ilDB->insert( self::$settingsTable, $localSettings );
425 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE object_id = %s';
426 $types = array(
'integer');
427 $values = array($object_id);
428 $rset = $ilDB->queryF( $query, $types, $values );
430 if(
$row = $ilDB->fetchAssoc( $rset ) )
433 $room->initialize(
$row );
445 public static function byRoomId($room_id, $initObject =
false)
449 $query =
'SELECT * FROM ' . self::$settingsTable .
' WHERE room_id = %s';
451 $types = array(
'integer');
452 $values = array($room_id);
454 $rset = $ilDB->queryF( $query, $types, $values );
456 if(
$row = $ilDB->fetchAssoc( $rset ) )
459 $room->initialize(
$row );
477 $this->roomId = $rowdata[
'room_id'];
479 foreach( $this->availableSettings as $setting => $type )
481 if( isset($rowdata[$setting]) )
483 settype($rowdata[$setting], $this->availableSettings[$setting]);
484 $this->
setSetting( $setting, $rowdata[$setting] );
511 $query =
'SELECT count(user_id) as cnt FROM ' . self::$userTable .
512 ' WHERE room_id = %s AND user_id = %s';
514 $types = array(
'integer',
'integer');
515 $values = array($this->roomId, $chat_userid);
516 $rset = $ilDB->queryF( $query, $types, $values );
518 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
528 $query =
'SELECT count(user_id) cnt FROM ' . self::$privateRoomsAccessTable .
529 ' WHERE proom_id = %s AND user_id = %s';
531 $types = array(
'integer',
'integer');
532 $values = array($proom_id, $chat_userid);
533 $rset = $ilDB->queryF( $query, $types, $values );
535 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
538 $query =
'SELECT count(*) cnt FROM ' . self::$privateRoomsTable .
539 ' WHERE proom_id = %s AND owner = %s';
541 $types = array(
'integer',
'integer');
542 $values = array($proom_id, $chat_userid);
543 $rset = $ilDB->queryF( $query, $types, $values );
545 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
560 $ilDB->manipulate(
'DELETE FROM ' . self::$userTable );
561 $ilDB->manipulate(
'UPDATE ' . self::$privateRoomsTable .
' SET closed = ' . $ilDB->quote( time() ,
'integer') .
' WHERE closed = 0 OR closed IS NULL');
562 $ilDB->manipulate(
'UPDATE ' . self::$privateSessionsTable .
' SET disconnected = ' . $ilDB->quote( time() ,
'integer') .
' WHERE disconnected = 0 OR disconnected IS NULL');
585 $join .=
' INNER JOIN ' . self::$privateSessionsTable .
586 ' pSessionTable ON pSessionTable.user_id = ' .
587 $ilDB->quote( $restricted_session_userid,
'integer' ) .
588 ' AND historyTable.sub_room = pSessionTable.proom_id AND timestamp >= pSessionTable.connected AND timestamp <= pSessionTable.disconnected ';
591 $query =
'SELECT historyTable.* FROM ' . self::$historyTable .
' historyTable ' .
592 $join .
' WHERE historyTable.room_id = ' . $this->
getRoomId();
598 $filter[] =
'timestamp >= ' . $ilDB->quote( $from->getUnixTime(),
'integer' );
603 $filter[] =
'timestamp <= ' . $ilDB->quote( $to->getUnixTime(),
'integer' );
607 $query .=
' AND ' . join(
' AND ', $filter );
608 $query .=
' ORDER BY timestamp ASC';
610 $rset = $ilDB->query( $query );
613 while(
$row = $ilDB->fetchAssoc( $rset ) )
615 $row[
'message'] = json_decode(
$row[
'message'] );
616 $row[
'message']->timestamp =
$row[
'timestamp'];
617 if (
$row[
'message']->
public !== null && !
$row[
'message']->
public && !in_array($ilUser->getId(), explode(
',',
$row[
'recipients']))) {
629 $query =
'SELECT proom_id, title FROM ' . self::$privateRoomsTable .
' WHERE proom_id IN (
630 SELECT proom_id FROM '.self::$privateSessionsTable.
' WHERE connected >= %s AND disconnected <= %s AND user_id = %s
632 ) AND parent_id = %s';
634 $rset = $ilDB->queryF($query, array(
'integer',
'integer',
'integer',
'integer'), array($from->getUnixTime(), $to->getUnixTime(), $user_id, $room_id));
636 while(
$row = $ilDB->fetchAssoc( $rset ) )
655 $upload_id = $ilDB->nextId( self::$uploadTable );
660 'upload_id' => array(
'integer', $upload_id),
661 'room_id' => array(
'integer', $this->roomId),
662 'user_id' => array(
'integer', $user_id),
664 'filetype' => array(
'text', $type),
665 'timestamp' => array(
'integer', time())
684 'room_id' => array(
'integer', $this->roomId),
685 'user_id' => array(
'integer', $user_id),
686 'timestamp' => array(
'integer', time()),
687 'remark' => array(
'text',
$comment),
704 if( !is_array( $user_id ) )
705 $user_id = array($user_id);
707 $query =
'DELETE FROM ' . self::$banTable .
' WHERE room_id = %s AND ' .
708 $ilDB->in(
'user_id', $user_id,
false,
'integer' );
710 $types = array(
'integer');
713 return $ilDB->manipulateF( $query, $types, $values );
728 $query =
'SELECT count(user_id) cnt FROM ' . self::$banTable .
729 ' WHERE user_id = %s AND room_id = %s';
731 $types = array(
'integer',
'integer');
732 $values = array($user_id, $this->
getRoomId());
734 $rset = $ilDB->queryF( $query, $types, $values );
736 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] )
753 $query =
'SELECT * FROM ' . self::$banTable .
' WHERE room_id = %s ';
754 $types = array(
'integer');
756 $rset = $ilDB->queryF( $query, $types, $values );
761 while(
$row = $ilDB->fetchAssoc( $rset ) )
763 if(
$row[
'user_id'] > 0 )
767 'user_id' => $user->getId(),
768 'firstname' => $user->getFirstname(),
769 'lastname' => $user->getLastname(),
770 'login' => $user->getLogin(),
771 'remark' =>
$row[
'remark']
800 $query =
'SELECT * FROM ' . self::$sessionTable .
' WHERE user_id = ' .
801 $ilDB->quote( $user->
getUserId(),
'integer' ) .
802 ' ORDER BY connected DESC';
804 $ilDB->setLimit( 1 );
805 $rset = $ilDB->query( $query );
807 if(
$row = $ilDB->fetchAssoc( $rset ) )
827 $query =
'SELECT * FROM ' . self::$sessionTable
828 .
' WHERE room_id = '.
829 $ilDB->quote( $this->
getRoomId(),
'integer' ) .
830 ' ORDER BY connected DESC';
832 $rset = $ilDB->query( $query );
836 while(
$row = $ilDB->fetchAssoc( $rset ) )
848 $nextId = $ilDB->nextId(
'chatroom_prooms');
851 self::$privateRoomsTable,
853 'proom_id' => array(
'integer', $nextId),
854 'parent_id' => array(
'integer', $this->roomId),
855 'title' => array(
'text', $title),
856 'owner' => array(
'integer', $owner->
getUserId()),
857 'created' => array(
'integer', time()),
858 'is_public' => array(
'integer',
$settings[
'public']),
870 'UPDATE ' . self::$privateRoomsTable .
' SET closed = %s WHERE proom_id = %s',
871 array(
'integer',
'integer'),
879 $query =
'SELECT proom_id FROM ' . self::$privateRoomsTable .
' WHERE proom_id = %s AND owner = %s';
880 $types = array(
'integer',
'integer');
881 $values = array($proom_id, $user_id);
883 $rset = $ilDB->queryF($query, $types, $values);
885 if ($rset && $ilDB->fetchAssoc($rset)) {
895 public function inviteUserToPrivateRoom($user_id, $proom_id)
902 $query =
'DELETE FROM ' . self::$privateRoomsAccessTable .
' WHERE user_id = %s AND proom_id = %s';
903 $types = array(
'integer',
'integer');
904 $values = array($user_id, $proom_id);
906 $ilDB->manipulateF($query, $types, $values);
908 $ilDB->insert(self::$privateRoomsAccessTable, array(
909 'user_id' => array(
'integer', $user_id),
910 'proom_id' => array(
'integer', $proom_id)
922 include_once
'Services/Link/classes/class.ilLink.php';
949 public function sendInvitationNotification($gui, $sender, $recipient_id, $subScope = 0, $invitationLink =
'')
956 if($gui && !$invitationLink)
958 $invitationLink = $this->
getChatURL($gui, $subScope);
961 if($recipient_id > 0 && !in_array(ANONYMOUS_USER_ID, array($recipient_id)))
963 if(is_numeric($sender) && $sender > 0)
965 $sender_id = $sender;
970 $public_name = $usr->getPublicName();
974 if($sender->getUserId() > 0)
976 $sender_id = $sender->getUserId();
980 $sender_id = ANONYMOUS_USER_ID;
982 $public_name = $sender->getUsername();
986 throw new InvalidArgumentException(
'$sender must be an instance of ilChatroomUser or an id of an ilObjUser instance');
989 $lng->loadLanguageModule(
'mail');
993 'link' => $invitationLink,
994 'inviter_name' => $public_name,
996 'salutation' => $lng->txt(
'mail_salutation_' . $recipient->getGender()) .
' ' . $recipient->getFullname()
1004 require_once
'Services/Notifications/classes/class.ilNotificationConfig.php';
1006 $notification->setTitleVar(
'chat_invitation', $bodyParams,
'chatroom');
1007 $notification->setShortDescriptionVar(
'chat_invitation_short', $bodyParams,
'chatroom');
1008 $notification->setLongDescriptionVar(
'chat_invitation_long', $bodyParams,
'chatroom');
1009 $notification->setAutoDisable(
false);
1010 $notification->setLink($invitationLink);
1011 $notification->setIconPath(
'templates/default/images/icon_chtr_s.png');
1012 $notification->setValidForSeconds(0);
1014 $notification->setHandlerParam(
'mail.sender', $sender_id);
1016 $notification->notifyByUsers(array($recipient_id));
1023 $this->inviteUserToPrivateRoom($user_id, $proom_id);
1029 $query =
'SELECT title FROM ' . self::$privateRoomsTable .
' WHERE proom_id = %s';
1030 $types = array(
'integer');
1031 $values = array($proom_id);
1033 $rset = $ilDB->queryF($query, $types, $values);
1035 if (
$row = $ilDB->fetchAssoc($rset)) {
1036 return $row[
'title'];
1047 SELECT roomtable.title, roomtable.proom_id, accesstable.user_id id, roomtable.owner owner FROM ' . self::$privateRoomsTable .
' roomtable
1048 LEFT JOIN '.self::$privateRoomsAccessTable.
' accesstable ON roomtable.proom_id = accesstable.proom_id AND accesstable.user_id = %s
1049 WHERE parent_id = %s AND (closed = 0 OR closed IS NULL) AND (accesstable.user_id IS NOT NULL OR roomtable.owner = %s)';
1050 $types = array(
'integer',
'integer',
'integer');
1051 $values = array($userid, $this->roomId, $userid);
1052 $rset = $ilDB->queryF( $query, $types, $values );
1055 while(
$row = $ilDB->fetchAssoc( $rset ) )
1068 $query =
'SELECT user_id FROM ' . self::$privateSessionsTable .
' WHERE proom_id = %s AND disconnected = 0 OR disconnected IS NULL';
1069 $types = array(
'integer');
1070 $values = array($private_room_id);
1071 $rset = $ilDB->queryF( $query, $types, $values );
1075 while (
$row = $ilDB->fetchAssoc($rset)) {
1076 $users[] =
$row[
'user_id'];
1086 $query =
'SELECT proom_id id FROM ' . self::$privateSessionsTable .
' WHERE user_id = %s AND proom_id = %s AND disconnected = 0 OR disconnected IS NULL';
1087 $types = array(
'integer',
'integer');
1088 $values = array($user_id, $room_id);
1089 $rset = $ilDB->queryF( $query, $types, $values );
1090 if ($ilDB->fetchAssoc($rset))
1101 self::$privateSessionsTable,
1103 'proom_id' => array(
'integer', $room_id),
1104 'user_id' => array(
'integer', $user_id),
1105 'connected' => array(
'integer', time()),
1106 'disconnected' => array(
'integer', 0),
1123 self::$privateSessionsTable,
1125 'disconnected' => array(
'integer', time())
1128 'proom_id' => array(
'integer', $room_id),
1129 'user_id' => array(
'integer', $user_id),
1137 $query =
'SELECT count(user_id) as cnt FROM ' . self::$userTable .
1138 ' WHERE room_id = %s';
1140 $types = array(
'integer');
1141 $values = array($this->roomId);
1142 $rset = $ilDB->queryF( $query, $types, $values );
1144 if( $rset && (
$row = $ilDB->fetchAssoc( $rset )) &&
$row[
'cnt'] == 1 )
1153 $query =
'SELECT title FROM ' . self::$privateRoomsTable .
' WHERE parent_id = %s and closed = 0';
1154 $rset = $ilDB->queryF($query, array(
'integer'), array($this->roomId));
1158 while(
$row = $ilDB->fetchAssoc($rset)) {
1159 $titles[] =
$row[
'title'];
1165 if(!in_array($title . $suffix, $titles)) {
1172 $suffix =
' (' . $i .
')';
1182 SELECT private_rooms.proom_id id, MIN(disconnected) min_disconnected, MAX(disconnected) max_disconnected
1183 FROM ' . self::$privateSessionsTable .
' private_sessions
1184 INNER JOIN '.self::$privateRoomsTable.
' private_rooms
1185 ON private_sessions.proom_id = private_rooms.proom_id
1187 GROUP BY private_rooms.proom_id
1188 HAVING MIN(disconnected) > 0 AND MAX(disconnected) < %s';
1189 $rset = $ilDB->queryF(
1192 array(time() + 60 * 5)
1197 while (
$row = $ilDB->fetchAssoc($rset)) {
1198 $rooms[
$row[
'id']] = $row[
'id'];
1201 $query =
'SELECT DISTINCT proom_id, room_id, object_id FROM ' . self::$privateRoomsTable
1202 .
' INNER JOIN ' . self::$settingsTable .
' ON parent_id = room_id '
1203 .
' WHERE ' . $ilDB->in(
'proom_id', $rooms,
false,
'integer');
1205 $rset = $ilDB->query($query);
1207 while(
$row = $ilDB->fetchAssoc($rset)) {
1209 'proom_id' =>
$row[
'proom_id'],
1210 'room_id' =>
$row[
'room_id'],
1211 'object_id' =>
$row[
'object_id']
1226 public function getAllRooms($user_id)
1234 SELECT room_id, od.title
1237 INNER JOIN " . self::$settingsTable .
"
1238 ON object_id = od.obj_id
1240 INNER JOIN " . self::$privateRoomsTable .
" prt
1243 WHERE od.type = 'chtr'
1246 $types = array(
'integer');
1247 $values = array($user_id);
1249 $res = $ilDB->queryF($query, $types, $values);
1253 while(
$row = $ilDB->fetchAssoc(
$res))
1255 $room_id =
$row[
'room_id'];
1256 $rooms[$room_id] =
$row[
'title'];
1269 SELECT proom_id, parent_id
1270 FROM chatroom_prooms
1271 WHERE parent_id = %s
1276 $types = array(
'integer',
'integer' );
1277 $values = array( $parent_room, $user_id );
1279 $res = $ilDB->queryF( $query, $types, $values );
1281 $priv_rooms = array();
1283 while(
$row = $ilDB->fetchAssoc(
$res ) )
1285 $proom_id =
$row[
'proom_id'];
1286 $priv_rooms[$proom_id] =
$row[
'parent_id'];
1305 FROM object_reference objr
1307 INNER JOIN chatroom_settings cs
1308 ON cs.object_id = objr.obj_id
1310 INNER JOIN object_data od
1311 ON od.obj_id = cs.object_id
1313 WHERE cs.room_id = %s
1316 $types = array(
'integer' );
1317 $values = array( $room_id );
1319 $res = $ilDB->queryF( $query, $types, $values );
1323 return $row[
'ref_id'];
1332 $ilDB->setLimit($number * 2);
1333 $rset = $ilDB->queryF(
'SELECT * FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = 0 ORDER BY timestamp DESC', array(
'integer'), array($this->roomId));
1337 while((
$row = $ilDB->fetchAssoc($rset)) && $result_count < $number) {
1338 $tmp = json_decode(
$row[
'message']);
1339 if ($chatuser !== null && $tmp->public == 0 && $tmp->recipients) {
1340 if (in_array($chatuser->getUserId(), explode(
',',$tmp->recipients))) {
1345 else if ($tmp->public == 1) {
1354 public function getLastMessagesForChatViewer($number, $chatuser = null)
1361 $ilDB->setLimit($number);
1362 $rset = $ilDB->query(
1364 FROM ' . self::$historyTable .
'
1365 WHERE room_id = '.$ilDB->quote($this->roomId,
'integer').
'
1368 (' . $ilDB->like(
'message',
'text',
'%"type":"message"%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"public":1%') .
' AND ' . $ilDB->like(
'message',
'text',
'%"recipients":null%') .
')
1370 ' . $ilDB->like(
'message',
'text',
'%"type":"%connected"%') .
')
1371 ORDER BY timestamp DESC'
1375 while((
$row = $ilDB->fetchAssoc($rset)))
1377 $tmp = json_decode(
$row[
'message']);
1378 if($tmp->type !=
'message' &&
$row[
'timestamp'] && !is_numeric($tmp->timestamp))
1380 $tmp->timestamp =
$row[
'timestamp'] * 1000;
1391 'DELETE FROM ' . self::$historyTable .
' WHERE room_id = %s AND sub_room = %s',
1392 array(
'integer',
'integer'),
1393 array($this->roomId, (
int)$sub_room)
1398 'DELETE FROM ' . self::$sessionTable .
' WHERE proom_id = %s AND disconnected < %s',
1399 array(
'integer',
'integer'),
1400 array($sub_room, time())
1405 'DELETE FROM ' . self::$sessionTable .
' WHERE room_id = %s AND disconnected < %s',
1406 array(
'integer',
'integer'),
1407 array($this->roomId, time())
1412 public static function getUntrashedChatReferences()
1422 SELECT od.obj_id, od.title, ore.ref_id, od.type, odp.title parent_title
1424 INNER JOIN object_reference ore ON ore.obj_id = od.obj_id
1425 INNER JOIN tree t ON t.child = ore.ref_id
1426 INNER JOIN tree p ON p.child = t.parent
1427 INNER JOIN object_reference orep ON orep.ref_id = p.child
1428 INNER JOIN object_data odp ON odp.obj_id = orep.obj_id
1429 INNER JOIN object_reference pre ON pre.ref_id = t.parent
1430 INNER JOIN object_data pod ON pod.obj_id = pre.obj_id
1431 WHERE od.type = %s AND t.tree > 0 AND ore.deleted IS NULL
1434 $res = $ilDB->queryF($query, array(
'text'), array(
'chtr'));
1437 while(
$row = $ilDB->fetchAssoc(
$res))