ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilChatroomPrivateRoomTask Class Reference

Class ilChatroomPrivateRoomTask. More...

+ Inheritance diagram for ilChatroomPrivateRoomTask:
+ Collaboration diagram for ilChatroomPrivateRoomTask:

Public Member Functions

 __construct (ilChatroomObjectGUI $gui)
 Constructor. More...
 
 executeDefault ($method)
 
 create ()
 Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful. More...
 
 delete ()
 
 leave ()
 Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful. More...
 
 enter ()
 
 listUsers ()
 
- Public Member Functions inherited from ilChatroomTaskHandler
 __construct (ilChatroomObjectGUI $gui)
 
 executeDefault ($requestedMethod)
 

Private Member Functions

 buildMessage ($messageString, $params, ilChatroomUser $chat_user)
 Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data. More...
 

Private Attributes

 $gui
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilChatroomPrivateRoomTask::__construct ( ilChatroomObjectGUI  $gui)

Constructor.

Sets $this->gui using given $gui

Parameters
ilChatroomObjectGUI$gui

Definition at line 27 of file class.ilChatroomPrivateRoomTask.php.

References $gui.

28  {
29  $this->gui = $gui;
30  }

Member Function Documentation

◆ buildMessage()

ilChatroomPrivateRoomTask::buildMessage (   $messageString,
  $params,
ilChatroomUser  $chat_user 
)
private

Instantiates stdClass, sets $data->user, $data->message, $data->public and $data->recipients using given $chat_user, $messageString and $params and returns $data.

Parameters
string$messageString
array$params
ilChatroomUser$chat_user
Returns
stdClass

Definition at line 324 of file class.ilChatroomPrivateRoomTask.php.

References $data, $params, and ilChatroomUser\getUserId().

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  }
getUserId()
Returns Ilias User ID.
$data
$params
Definition: example_049.php:96
+ Here is the call graph for this function:

◆ create()

ilChatroomPrivateRoomTask::create ( )

Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful.

ilTemplate $tpl ilObjUser $ilUser

Parameters
string$method

Definition at line 45 of file class.ilChatroomPrivateRoomTask.php.

References $_REQUEST, $ilCtrl, $ilUser, $tpl, ilChatroom\byObjectId(), ilChatroom\checkUserPermissions(), exit, and ilUtil\stripSlashes().

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  }
exit
Definition: login.php:54
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
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
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
+ Here is the call graph for this function:

◆ delete()

ilChatroomPrivateRoomTask::delete ( )

Definition at line 100 of file class.ilChatroomPrivateRoomTask.php.

References $_REQUEST, $ilUser, $params, $query, $tpl, ilChatroom\byObjectId(), and exit.

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  }
exit
Definition: login.php:54
global $tpl
Definition: ilias.php:8
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
+ Here is the call graph for this function:

◆ enter()

ilChatroomPrivateRoomTask::enter ( )

Definition at line 240 of file class.ilChatroomPrivateRoomTask.php.

References $_REQUEST, $ilUser, $params, $query, $tpl, ilChatroom\byObjectId(), ilChatroom\checkUserPermissions(), and exit.

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  }
exit
Definition: login.php:54
global $tpl
Definition: ilias.php:8
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
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
+ Here is the call graph for this function:

◆ executeDefault()

ilChatroomPrivateRoomTask::executeDefault (   $method)

Definition at line 32 of file class.ilChatroomPrivateRoomTask.php.

32  {
33 
34  }

◆ leave()

ilChatroomPrivateRoomTask::leave ( )

Prepares and posts message fetched from $_REQUEST['message'] to recipients fetched from $_REQUEST['recipient'] and adds an entry to history if successful.

ilTemplate $tpl ilObjUser $ilUser

Parameters
string$method

Definition at line 173 of file class.ilChatroomPrivateRoomTask.php.

References $_REQUEST, $ilUser, $params, $query, $tpl, ilChatroom\byObjectId(), and exit.

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  }
exit
Definition: login.php:54
global $tpl
Definition: ilias.php:8
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
+ Here is the call graph for this function:

◆ listUsers()

ilChatroomPrivateRoomTask::listUsers ( )

Definition at line 304 of file class.ilChatroomPrivateRoomTask.php.

References $_REQUEST, $ilUser, ilChatroom\byObjectId(), and exit.

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  }
exit
Definition: login.php:54
global $ilUser
Definition: imgupload.php:15
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
+ Here is the call graph for this function:

Field Documentation

◆ $gui

ilChatroomPrivateRoomTask::$gui
private

Definition at line 18 of file class.ilChatroomPrivateRoomTask.php.

Referenced by __construct().


The documentation for this class was generated from the following file: