ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
15 {
16 
22  public function __construct()
23  {
24  $this->handleCommand( $_REQUEST['task'] );
25  exit;
26  }
27 
36  public function getConnector()
37  {
38  require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
39  require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
40  require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
41 
42  //$settings = new ilChatroomServerSettings();
43  $settings = ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
44  $connector = new ilChatroomServerConnector( $settings );
45 
46  return $connector;
47  }
48 
54  private function handleCommand($task)
55  {
56  switch($task)
57  {
58  case 'disconnectedUsers':
59  if (isset($_REQUEST['scope'])) {
60  $this->disconnectedUsers( $_REQUEST['scope'] );
61  }
62  $this->cleanupPrivateRooms();
63  break;
64  case 'serverStarted':
65  $this->serverStarted();
66  break;
67  }
68  }
69 
70  public function cleanupPrivateRooms() {
71  $deletableRooms = ilChatroom::findDeletablePrivateRooms();
72 
73  $connector = $this->getConnector();
74 
75  foreach($deletableRooms as $deletableRoom) {
76 
77  $room = ilChatroom::byObjectId($deletableRoom['object_id']);
78 
79  $params['user'] = -1; //$chat_user->getUserId();
80  $room->closePrivateRoom($deletableRoom['proom_id'], $chat_user, $settings);
81  $query = http_build_query( $params );
82 
83  $message = json_encode( array(
84  'type' => 'private_room_deleted',
85  'timestamp' => date( 'c' ),
86  'public' => 1,
87  'id' => $deletableRoom['proom_id'],
88  'proom_id' => $deletableRoom['proom_id'],
89  'message' => array(
90  'message'=> 'room deleted',
91  'public' => '1',
92  'user' => 'system'
93  )
94  ) );
95 
96  $result = $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1) );
97 
98  }
99  }
100 
108  private function disconnectedUsers($usersByScope)
109  {
110  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
111 
112  foreach( $usersByScope as $scope => $users )
113  {
114  $users = explode( ',', $users );
115  $chatroom = ilChatroom::byRoomId( $scope );
116 
117  if( $chatroom instanceof ilChatroom && is_array( $users ) )
118  {
119  $users = array_filter( $users );
120  $userDetails = $this->getUserInformation($users);
121  $message = json_encode( array(
122  'type' => 'disconnected',
123  'users' => $userDetails,
124  'timestamp' => date( 'c' )
125  ) );
126 
127  $chatroom->disconnectUsers( $users );
128 
129  if(!isset($_REQUEST['handledAction']) || $_REQUEST['handledAction'] != 'kick')
130  {
131  $this->getConnector()->sendMessage( $chatroom->getRoomId(), $message );
132  }
133 
134  if( true || $chatroom->getSetting( 'enable_history' ) ) {
135  $messageObject = array(
136  'type' => 'disconnected',
137  'users' => $userDetails,
138  'timestamp' => date( 'c' )
139  );
140 
141  $chatroom->addHistoryEntry( $messageObject );
142  }
143  }
144  }
145  }
146 
151  private function serverStarted()
152  {
153  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
154 
156  }
157 
158  private function getUserInformation($user_ids) {
159  global $ilDB;
160 
161  $rset = $ilDB->query('SELECT userdata FROM chatroom_users WHERE ' . $ilDB->in('user_id', $user_ids, false, 'integer'));
162  $users = array();
163  while($row = $ilDB->fetchAssoc($rset)) {
164  $users[] = json_decode($row['userdata']);
165  }
166  return $users;
167  }
168 }
169 
170 ?>