ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilChatroomPrivateRoomTask.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 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
6 
16 {
17 
18  private $gui;
19 
28  {
29  $this->gui = $gui;
30  }
31 
32  public function executeDefault($method) {
33 
34  }
35 
45  public function create()
46  {
47  global $tpl, $ilUser, $ilCtrl;
48 
49  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
50  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
51 
52  if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
53  {
54  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
55  $ilCtrl->redirectByClass("ilrepositorygui", "");
56  }
57 
58  $room = ilChatroom::byObjectId($this->gui->object->getId());
59 
60  $chat_user = new ilChatroomUser($ilUser, $room);
61  $user_id = $chat_user->getUserId();
62 
63  if(!$room)
64  {
65  $response = json_encode(array(
66  'success' => false,
67  'reason' => 'unkown room'
68  ));
69  echo json_encode($response);
70  exit;
71  }
72  else if(!$room->isSubscribed($chat_user->getUserId()))
73  {
74  $response = json_encode(array(
75  'success' => false,
76  'reason' => 'not subscribed'
77  ));
78  echo json_encode($response);
79  exit;
80  }
81 
82  if(!strlen($_REQUEST['title']))
83  {
84  $response = json_encode(array(
85  'success' => false,
86  'reason' => 'empty title'
87  ));
88  echo $response;
89  exit;
90  }
91 
92  $title = $room->getUniquePrivateRoomTitle(ilUtil::stripSlashes($_REQUEST['title']));
93  $connector = $this->gui->getConnector();
94  $response = $connector->createPrivateRoom($room, $title, $chat_user);
95 
96  echo json_encode($response);
97  exit;
98  }
99 
100  public function delete()
101  {
102  global $tpl, $ilUser, $rbacsystem;
103 
104  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
105  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
106 
107  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
108 
109  $chat_user = new ilChatroomUser($ilUser, $room);
110  $user_id = $chat_user->getUserId();
111 
112  if( !$room )
113  {
114  $response = json_encode( array(
115  'success' => false,
116  'reason' => 'unkown room'
117  ) );
118  echo json_encode( $response );
119  exit;
120  }
121  else if( !$room->isOwnerOfPrivateRoom( $user_id, $_REQUEST['sub'] ) && !$rbacsystem->checkAccess('moderate', $this->gui->getRefId()) )
122  {
123  $response = json_encode( array(
124  'success' => false,
125  'reason' => 'not owner of private room'
126  ) );
127  echo json_encode( $response );
128  exit;
129  }
130 
131  $scope = $room->getRoomId();
132  $params = array();
133 
134  $params['user'] = $chat_user->getUserId();
135  $params['id'] = $room->closePrivateRoom($_REQUEST['sub'], $chat_user, $settings);
136  $query = http_build_query( $params );
137  $connector = $this->gui->getConnector();
138 
139  if( true || $responseObject->success == true )
140  {
141  $message = json_encode( array(
142  'type' => 'private_room_deleted',
143  //'recipients' => $chat_user->getUserId(),//$users,
144  'timestamp' => date( 'c' ),
145  'public' => 1,
146  //'title' => $title,
147  'id' => $responseObject->id,
148  'proom_id' => $_REQUEST['sub'],
149  'message' => array(
150  'message' => 'room deleted',
151  'public' => '1',
152  'user' => 'system'
153  )
154  ) );
155 
156  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1) );
157  }
158 
159  $response = json_encode(array('success' => true));
160  echo $response;
161  exit;
162  }
163 
173  public function leave()
174  {
175  global $tpl, $ilUser;
176 
177  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
178 
179  $chat_user = new ilChatroomUser( $ilUser, $room );
180  $user_id = $chat_user->getUserId();
181  $connector = $this->gui->getConnector();
182 
183  if( !$room )
184  {
185  $response = json_encode( array(
186  'success' => false,
187  'reason' => 'unkown room'
188  ) );
189  echo json_encode( $response );
190  exit;
191  }
192  else if( !$room->isSubscribed( $chat_user->getUserId() ) )
193  {
194  $response = json_encode( array(
195  'success' => false,
196  'reason' => 'not subscribed'
197  ) );
198  echo json_encode( $response );
199  exit;
200  }
201 
202  $scope = $room->getRoomId();
203  $params = array();
204 
205  $params['user'] = $chat_user->getUserId();
206  $params['sub'] = $_REQUEST['sub'];
207 
208  $message = json_encode( array(
209  'type' => 'private_room_left',
210  'user' => $params['user'],
211  'sub' => $params['sub']
212  ));
213 
214  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );
215 
216  if( $room->userIsInPrivateRoom( $params['sub'], $params['user'] ) )
217  {
218  //$params = array_merge( $params, array('message' => $message) );
219  $query = http_build_query( $params );
220  $connector = $this->gui->getConnector();
221  $response = $connector->leavePrivateRoom( $scope, $query );
222  $responseObject = json_decode( $response );
223 /*
224  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
225  {
226  //$room->addHistoryEntry( $message, $recipient, $publicMessage );
227  }
228 */
229  $room->unsubscribeUserFromPrivateRoom( $params['sub'], $params['user'] );
230  }
231  else
232  {
233  $response = json_encode( array('success' => true, 'message' => 'was not in room') );
234  }
235 
236  echo $response;
237  exit;
238  }
239 
240  public function enter()
241  {
242  global $tpl, $ilUser;
243 
244  ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id );
245 
246  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
247 
248  $chat_user = new ilChatroomUser( $ilUser, $room );
249  $user_id = $chat_user->getUserId();
250 
251  if( !$room )
252  {
253  $response = json_encode( array(
254  'success' => false,
255  'reason' => 'unkown room'
256  ) );
257  echo json_encode( $response );
258  exit;
259  }
260  else if( !$room->isAllowedToEnterPrivateRoom( $chat_user->getUserId(), $_REQUEST['sub'] ) )
261  {
262  $response = json_encode( array(
263  'success' => false,
264  'reason' => 'not allowed enter to private room'
265  ) );
266 
267  echo json_encode( $response );
268  exit;
269  }
270 
271  $scope = $room->getRoomId();
272  $params = array();
273 
274  $params['user'] = $chat_user->getUserId();
275  $params['sub'] = $_REQUEST['sub'];
276  $params['message'] = json_encode( array(
277  'type' => 'private_room_entered',
278  'user' => $user_id
279  ));
280 
281 
282  $query = http_build_query( $params );
283  $connector = $this->gui->getConnector();
284  $response = $connector->enterPrivateRoom( $scope, $query );
285  $responseObject = json_decode( $response );
286 
287  $message = json_encode( array(
288  'type' => 'private_room_entered',
289  'user' => $params['user'],
290  'sub' => $params['sub']
291  ));
292 
293  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );
294 
295  if( $responseObject->success == true )
296  {
297  $room->subscribeUserToPrivateRoom( $params['sub'], $params['user'] );
298  }
299 
300  echo $response;
301  exit;
302  }
303 
304  public function listUsers()
305  {
306  global $ilUser;
307 
308  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
309 
310  echo json_encode( $room->listUsersInPrivateRoom( $_REQUEST['sub'] ) );
311  exit;
312  }
313 
324  private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
325  {
326  $data = new stdClass();
327 
328  $data->user = $chat_user->getUserId(); //$this->gui->object->getPersonalInformation( $chat_user );
329  $data->title = $params['title'];
330  $data->timestamp = date( 'c' );
331  $data->type = 'private_room_created';
332 
333  return $data;
334  }
335 
336 }
337 
338 ?>
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using gi...
getUserId()
Returns Ilias User ID.
exit
Definition: login.php:54
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
$data
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct(ilChatroomObjectGUI $gui)
Constructor.
create()
Prepares and posts message fetched from $_REQUEST[&#39;message&#39;] to recipients fetched from $_REQUEST[&#39;re...
Class ilChatroomPrivateRoomTask.
global $ilUser
Definition: imgupload.php:15
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
$params
Definition: example_049.php:96
leave()
Prepares and posts message fetched from $_REQUEST[&#39;message&#39;] to recipients fetched from $_REQUEST[&#39;re...