ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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 314 of file class.ilChatroomPrivateRoomTask.php.

References $data, and ilChatroomUser\getUserId().

315  {
316  $data = new stdClass();
317 
318  $data->user = $chat_user->getUserId(); //$this->gui->object->getPersonalInformation( $chat_user );
319  $data->title = $params['title'];
320  $data->timestamp = date( 'c' );
321  $data->type = 'private_room_created';
322 
323  return $data;
324  }
getUserId()
Returns Ilias User ID.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ 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(), and exit.

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  $title = $room->getUniquePrivateRoomTitle($_REQUEST['title']);
83  $connector = $this->gui->getConnector();
84  $response = $connector->createPrivateRoom($room, $title, $chat_user);
85 
86  echo json_encode($response);
87  exit;
88  }
exit
Definition: login.php:54
global $ilCtrl
Definition: ilias.php:18
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
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 90 of file class.ilChatroomPrivateRoomTask.php.

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

91  {
92  global $tpl, $ilUser, $rbacsystem;
93 
94  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
95  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
96 
97  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
98 
99  $chat_user = new ilChatroomUser($ilUser, $room);
100  $user_id = $chat_user->getUserId();
101 
102  if( !$room )
103  {
104  $response = json_encode( array(
105  'success' => false,
106  'reason' => 'unkown room'
107  ) );
108  echo json_encode( $response );
109  exit;
110  }
111  else if( !$room->isOwnerOfPrivateRoom( $user_id, $_REQUEST['sub'] ) && !$rbacsystem->checkAccess('moderate', $this->gui->getRefId()) )
112  {
113  $response = json_encode( array(
114  'success' => false,
115  'reason' => 'not owner of private room'
116  ) );
117  echo json_encode( $response );
118  exit;
119  }
120 
121  $scope = $room->getRoomId();
122  $params = array();
123 
124  $params['user'] = $chat_user->getUserId();
125  $params['id'] = $room->closePrivateRoom($_REQUEST['sub'], $chat_user, $settings);
126  $query = http_build_query( $params );
127  $connector = $this->gui->getConnector();
128 
129  if( true || $responseObject->success == true )
130  {
131  $message = json_encode( array(
132  'type' => 'private_room_deleted',
133  //'recipients' => $chat_user->getUserId(),//$users,
134  'timestamp' => date( 'c' ),
135  'public' => 1,
136  //'title' => $title,
137  'id' => $responseObject->id,
138  'proom_id' => $_REQUEST['sub'],
139  'message' => array(
140  'message' => 'room deleted',
141  'public' => '1',
142  'user' => 'system'
143  )
144  ) );
145 
146  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1) );
147  }
148 
149  $response = json_encode(array('success' => true));
150  echo $response;
151  exit;
152  }
exit
Definition: login.php:54
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
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:

◆ enter()

ilChatroomPrivateRoomTask::enter ( )

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

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

231  {
232  global $tpl, $ilUser;
233 
234  ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id );
235 
236  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
237 
238  $chat_user = new ilChatroomUser( $ilUser, $room );
239  $user_id = $chat_user->getUserId();
240 
241  if( !$room )
242  {
243  $response = json_encode( array(
244  'success' => false,
245  'reason' => 'unkown room'
246  ) );
247  echo json_encode( $response );
248  exit;
249  }
250  else if( !$room->isAllowedToEnterPrivateRoom( $chat_user->getUserId(), $_REQUEST['sub'] ) )
251  {
252  $response = json_encode( array(
253  'success' => false,
254  'reason' => 'not allowed enter to private room'
255  ) );
256 
257  echo json_encode( $response );
258  exit;
259  }
260 
261  $scope = $room->getRoomId();
262  $params = array();
263 
264  $params['user'] = $chat_user->getUserId();
265  $params['sub'] = $_REQUEST['sub'];
266  $params['message'] = json_encode( array(
267  'type' => 'private_room_entered',
268  'user' => $user_id
269  ));
270 
271 
272  $query = http_build_query( $params );
273  $connector = $this->gui->getConnector();
274  $response = $connector->enterPrivateRoom( $scope, $query );
275  $responseObject = json_decode( $response );
276 
277  $message = json_encode( array(
278  'type' => 'private_room_entered',
279  'user' => $params['user'],
280  'sub' => $params['sub']
281  ));
282 
283  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );
284 
285  if( $responseObject->success == true )
286  {
287  $room->subscribeUserToPrivateRoom( $params['sub'], $params['user'] );
288  }
289 
290  echo $response;
291  exit;
292  }
exit
Definition: login.php:54
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
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:

◆ 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 163 of file class.ilChatroomPrivateRoomTask.php.

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

164  {
165  global $tpl, $ilUser;
166 
167  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
168 
169  $chat_user = new ilChatroomUser( $ilUser, $room );
170  $user_id = $chat_user->getUserId();
171  $connector = $this->gui->getConnector();
172 
173  if( !$room )
174  {
175  $response = json_encode( array(
176  'success' => false,
177  'reason' => 'unkown room'
178  ) );
179  echo json_encode( $response );
180  exit;
181  }
182  else if( !$room->isSubscribed( $chat_user->getUserId() ) )
183  {
184  $response = json_encode( array(
185  'success' => false,
186  'reason' => 'not subscribed'
187  ) );
188  echo json_encode( $response );
189  exit;
190  }
191 
192  $scope = $room->getRoomId();
193  $params = array();
194 
195  $params['user'] = $chat_user->getUserId();
196  $params['sub'] = $_REQUEST['sub'];
197 
198  $message = json_encode( array(
199  'type' => 'private_room_left',
200  'user' => $params['user'],
201  'sub' => $params['sub']
202  ));
203 
204  $connector->sendMessage( $room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub']) );
205 
206  if( $room->userIsInPrivateRoom( $params['sub'], $params['user'] ) )
207  {
208  //$params = array_merge( $params, array('message' => $message) );
209  $query = http_build_query( $params );
210  $connector = $this->gui->getConnector();
211  $response = $connector->leavePrivateRoom( $scope, $query );
212  $responseObject = json_decode( $response );
213 /*
214  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
215  {
216  //$room->addHistoryEntry( $message, $recipient, $publicMessage );
217  }
218 */
219  $room->unsubscribeUserFromPrivateRoom( $params['sub'], $params['user'] );
220  }
221  else
222  {
223  $response = json_encode( array('success' => true, 'message' => 'was not in room') );
224  }
225 
226  echo $response;
227  exit;
228  }
exit
Definition: login.php:54
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
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:

◆ listUsers()

ilChatroomPrivateRoomTask::listUsers ( )

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

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

295  {
296  global $ilUser;
297 
298  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
299 
300  echo json_encode( $room->listUsersInPrivateRoom( $_REQUEST['sub'] ) );
301  exit;
302  }
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: