ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomServerHandler.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5
13{
18 public function __construct()
19 {
20 $this->handleCommand($_REQUEST['task']);
21 exit;
22 }
23
28 private function handleCommand($task)
29 {
30 switch ($task) {
31 case 'disconnectedUsers':
32 if (isset($_REQUEST['scope'])) {
33 $this->disconnectedUsers($_REQUEST['scope']);
34 }
35 $this->cleanupPrivateRooms();
36 break;
37 case 'serverStarted':
38 $this->serverStarted();
39 break;
40 }
41 }
42
49 private function disconnectedUsers($usersByScope)
50 {
51 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
52
53 foreach ($usersByScope as $scope => $users) {
54 $users = explode(',', $users);
55 $chatroom = ilChatroom::byRoomId($scope);
56
57 if ($chatroom instanceof ilChatroom && is_array($users)) {
58 $users = array_filter($users);
59 $userDetails = ilChatroomUser::getUserInformation($users);
60 $message = json_encode(array(
61 'type' => 'disconnected',
62 'users' => $userDetails,
63 'timestamp' => date('c')
64 ));
65
66 $chatroom->disconnectUsers($users);
67
68 if (!isset($_REQUEST['handledAction']) || $_REQUEST['handledAction'] != 'kick') {
69 $this->getConnector()->sendMessage($chatroom->getRoomId(), $message);
70 }
71
72 if (true || $chatroom->getSetting('enable_history')) {
73 $messageObject = array(
74 'type' => 'disconnected',
75 'users' => $userDetails,
76 'timestamp' => date('c')
77 );
78
79 $chatroom->addHistoryEntry($messageObject);
80 }
81 }
82 }
83 }
84
91 public function getConnector()
92 {
93 require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
94 require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
95
96 $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
97 $connector = new ilChatroomServerConnector($settings);
98
99 return $connector;
100 }
101
102 public function cleanupPrivateRooms()
103 {
104 $deletableRooms = ilChatroom::findDeletablePrivateRooms();
105
106 $connector = $this->getConnector();
107
108 foreach ($deletableRooms as $deletableRoom) {
109 $room = ilChatroom::byObjectId($deletableRoom['object_id']);
110
111 $params['user'] = -1; //$chat_user->getUserId();
112 $room->closePrivateRoom($deletableRoom['proom_id']);
113 $query = http_build_query($params);
114
115 $message = json_encode(array(
116 'type' => 'private_room_deleted',
117 'timestamp' => date('c'),
118 'public' => 1,
119 'id' => $deletableRoom['proom_id'],
120 'proom_id' => $deletableRoom['proom_id'],
121 'message' => array(
122 'message' => 'room deleted',
123 'public' => '1',
124 'user' => 'system'
125 )
126 ));
127
128 $result = $connector->sendMessage($room->getRoomId(), $message, array('public' => 1));
129 }
130 }
131
136 private function serverStarted()
137 {
138 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
139
141 }
142}
$result
An exception for terminatinating execution or to throw for unit testing.
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.
Class ilChatroomServerConnector.
Class ilChatroomServerHandler.
disconnectedUsers($usersByScope)
Calls $chatroom->disconnectUsers for every given user in every given scope ($usersByScope),...
serverStarted()
Requires ilChatroom and calls its disconnectAllUsersFromAllRooms() method.
getConnector()
Returns connector Instantiates ilChatroomServerConnector with server settings and returns it.
handleCommand($task)
Calls command depending on given $task.
__construct()
Constructor Calls $this->handleCommand method.
static getUserInformation(array $usrIds, int $roomId=null)
Class ilChatroom.
static findDeletablePrivateRooms()
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static byRoomId($room_id, $initObject=false)
Returns ilChatroom by given $room_id.
static disconnectAllUsersFromAllRooms()
Deletes all entrys from userTable.
exit
Definition: login.php:29
$query
$message
Definition: xapiexit.php:14