ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_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 = $this->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 
85  private function getUserInformation($user_ids)
86  {
87  global $DIC;
88 
89  $rset = $DIC->database()->query('SELECT userdata FROM chatroom_users WHERE ' . $DIC->database()->in('user_id', $user_ids, false, 'integer'));
90  $users = array();
91  while ($row = $DIC->database()->fetchAssoc($rset)) {
92  $users[] = json_decode($row['userdata']);
93  }
94  return $users;
95  }
96 
103  public function getConnector()
104  {
105  require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
106  require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
107 
108  $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
109  $connector = new ilChatroomServerConnector($settings);
110 
111  return $connector;
112  }
113 
114  public function cleanupPrivateRooms()
115  {
116  $deletableRooms = ilChatroom::findDeletablePrivateRooms();
117 
118  $connector = $this->getConnector();
119 
120  foreach ($deletableRooms as $deletableRoom) {
121  $room = ilChatroom::byObjectId($deletableRoom['object_id']);
122 
123  $params['user'] = -1; //$chat_user->getUserId();
124  $room->closePrivateRoom($deletableRoom['proom_id']);
125  $query = http_build_query($params);
126 
127  $message = json_encode(array(
128  'type' => 'private_room_deleted',
129  'timestamp' => date('c'),
130  'public' => 1,
131  'id' => $deletableRoom['proom_id'],
132  'proom_id' => $deletableRoom['proom_id'],
133  'message' => array(
134  'message' => 'room deleted',
135  'public' => '1',
136  'user' => 'system'
137  )
138  ));
139 
140  $result = $connector->sendMessage($room->getRoomId(), $message, array('public' => 1));
141  }
142  }
143 
148  private function serverStarted()
149  {
150  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
151 
153  }
154 }
$params
Definition: disable.php:11
handleCommand($task)
Calls command depending on given $task.
Class ilChatroomServerHandler.
$result
global $DIC
Definition: saml.php:7
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
getConnector()
Returns connector Instantiates ilChatroomServerConnector with server settings and returns it...
static byRoomId($room_id, $initObject=false)
Returns ilChatroom by given $room_id.
serverStarted()
Requires ilChatroom and calls its disconnectAllUsersFromAllRooms() method.
catch(Exception $e) $message
Class ilChatroomServerConnector.
static findDeletablePrivateRooms()
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
__construct()
Constructor Calls $this->handleCommand method.
$query
static disconnectAllUsersFromAllRooms()
Deletes all entrys from userTable.
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
Class ilChatroom.
disconnectedUsers($usersByScope)
Calls $chatroom->disconnectUsers for every given user in every given scope ($usersByScope), sends corresponding status messages to chatroom and adds event in history.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.