ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomBanTask.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.ilChatroomUser.php';
5 
15 {
16 
17  private $gui;
18 
27  public function __construct(ilDBayObjectGUI $gui)
28  {
29  $this->gui = $gui;
30  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
31  }
32 
38  public function show()
39  {
40  //global $lng, $ilCtrl;
41  global $ilCtrl;
42 
43  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
44 
45  ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id );
46 
47  $this->gui->switchToVisibleMode();
48 
49  require_once 'Modules/Chatroom/classes/class.ilBannedUsersTableGUI.php';
50 
51  $table = new ilBannedUsersTableGUI( $this->gui, 'ban-show' );
52  $table->setFormAction( $ilCtrl->getFormAction( $this->gui, 'ban-show' ) );
53 
54  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
55 
56  if( $room )
57  {
58  $table->setData( $room->getBannedUsers() );
59  }
60 
61  $this->gui->tpl->setVariable( 'ADM_CONTENT', $table->getHTML() );
62  }
63 
69  public function delete()
70  {
71  global $ilCtrl;
72 
73  $users = $_REQUEST['banned_user_id'];
74 
75  if( !is_array( $users ) )
76  {
77  return;
78  }
79 
80  $room = ilChatroom::byObjectId( $this->gui->object->getId() );
81  $room->unbanUser( $users );
82 
83  $ilCtrl->redirect( $this->gui, 'ban-show' );
84  }
85 
91  public function executeDefault($method)
92  {
93  $this->show();
94  }
95 
101  public function active()
102  {
103  global $ilUser, $ilCtrl;
104 
105  if ( !ilChatroom::checkUserPermissions( array('read', 'moderate') , $this->gui->ref_id ) )
106  {
107  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
108  $ilCtrl->redirectByClass("ilrepositorygui", "");
109  }
110 
111  $room = ilChatroom::byObjectId($this->gui->object->getId());
112 
113  if($room)
114  {
115  // if user is in scope
116  $scope = $room->getRoomId();
117 
118  $chat_user = new ilChatroomUser($ilUser, $room);
119 
120  $messageObject = $this->buildMessage(
122  $chat_user
123  );
124 
125  $message = json_encode($messageObject);
126 
127 
128  $params = array(
129  'message' => $message,
130  'userToKick' => $_REQUEST['user']
131  );
132 
133  $query = http_build_query($params);
134  $connector = $this->gui->getConnector();
135  $response = $connector->kick($scope, $query);
136  $responseObject = json_decode($response);
137 
138  $room->banUser($_REQUEST['user']);
139 
140  if($responseObject->success == true)
141  {
142  $room->addHistoryEntry($messageObject, '', 1);
143 
144  $message = json_encode(array(
145  'type' => 'userjustkicked',
146  'user' => $params['userToKick'],
147  'sub' => 0
148  ));
149 
150  $connector->sendMessage($room->getRoomId(), $message, array(
151  'public' => 1,
152  'sub' => 0
153  ));
154 
155  // 2013-09-11: Should already been done by the chat server
156  $room->disconnectUser($params['userToKick']);
157  }
158  }
159  else
160  {
161  $response = json_encode(array(
162  'success' => false,
163  'reason' => 'unkown room'
164  ));
165  }
166 
167  echo $response;
168  exit;
169  }
170 
179  private function buildMessage($messageString, ilChatroomUser $user)
180  {
181  $data = new stdClass();
182 
183  $data->user = $this->gui->object->getPersonalInformation( $user );
184  $data->userToKick = $messageString;
185  $data->timestamp = date( 'c' );
186  $data->type = 'kick';
187 
188  return $data;
189  }
190 
191 }
192 
193 ?>