ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomClearTask.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 
14 {
15 
16  private $gui;
17 
26  {
27  $this->gui = $gui;
28  }
29 
36  public function executeDefault($method)
37  {
38  global $ilUser, $ilCtrl;
39 
40  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
41  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
42 
43  if ( !ilChatroom::checkUserPermissions( array('moderate') , $this->gui->ref_id ) )
44  {
45  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
46  $ilCtrl->redirectByClass("ilrepositorygui", "");
47  }
48 
49  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
50 
51  if( $room )
52  {
53  // if user is in scope
54  $scope = $room->getRoomId();
55 
56  $chat_user = new ilChatroomUser( $ilUser, $room );
57 
58  $message = json_encode( $this->buildMessage(
59  ilUtil::stripSlashes( (int)$_REQUEST['sub'] ), $chat_user
60  ) );
61 
62  $params = array(
63  'message' => $message,
64  );
65 
66  $query = http_build_query( $params );
67  $connector = $this->gui->getConnector();
68  $response = $connector->post( $scope, $query );
69  $responseObject = json_decode( $response );
70 
71  $room->clearMessages($_REQUEST['sub']);
72  }
73  else
74  {
75  $response = json_encode( array(
76  'success' => false,
77  'reason' => 'unkown room'
78  ) );
79  }
80 
81  echo $response;
82  exit;
83  }
84 
93  private function buildMessage($messageString, ilChatroomUser $chat_user)
94  {
95  $data = new stdClass();
96 
97  $data->user = $this->gui->object->getPersonalInformation( $chat_user );
98  $data->timestamp = date( 'c' );
99  $data->type = 'clear';
100  $data->sub = $messageString;
101 
102  return $data;
103  }
104 }
105 
106 ?>