ILIAS  Release_4_2_x_branch Revision 61807
 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 
25  public function __construct(ilDBayObjectGUI $gui)
26  {
27  $this->gui = $gui;
28  }
29 
36  public function executeDefault($method)
37  {
38  global $ilUser;
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  ilUtil::redirect("repository.php");
46  }
47 
48  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
49 
50  if( $room )
51  {
52  // if user is in scope
53  $scope = $room->getRoomId();
54 
55  $chat_user = new ilChatroomUser( $ilUser, $room );
56 
57  $message = json_encode( $this->buildMessage(
58  ilUtil::stripSlashes( (int)$_REQUEST['sub'] ), $chat_user
59  ) );
60 
61  $params = array(
62  'message' => $message,
63  );
64 
65  $query = http_build_query( $params );
66  $connector = $this->gui->getConnector();
67  $response = $connector->post( $scope, $query );
68  $responseObject = json_decode( $response );
69 
70  $room->clearMessages($_REQUEST['sub']);
71  }
72  else
73  {
74  $response = json_encode( array(
75  'success' => false,
76  'reason' => 'unkown room'
77  ) );
78  }
79 
80  echo $response;
81  exit;
82  }
83 
92  private function buildMessage($messageString, ilChatroomUser $chat_user)
93  {
94  $data = new stdClass();
95 
96  $data->user = $this->gui->object->getPersonalInformation( $chat_user );
97  $data->timestamp = date( 'c' );
98  $data->type = 'clear';
99  $data->sub = $messageString;
100 
101  return $data;
102  }
103 }
104 
105 ?>