ILIAS  Release_4_2_x_branch Revision 61807
 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;
104 
105  if(!ilChatroom::checkUserPermissions(array('read', 'moderate'), $this->gui->ref_id))
106  {
107  ilUtil::redirect("repository.php");
108  }
109 
110  $room = ilChatroom::byObjectId($this->gui->object->getId());
111 
112  if($room)
113  {
114  // if user is in scope
115  $scope = $room->getRoomId();
116 
117  $chat_user = new ilChatroomUser($ilUser, $room);
118 
119  $messageObject = $this->buildMessage(
121  $chat_user
122  );
123 
124  $message = json_encode($messageObject);
125 
126 
127  $params = array(
128  'message' => $message,
129  'userToKick' => $_REQUEST['user']
130  );
131 
132  $query = http_build_query($params);
133  $connector = $this->gui->getConnector();
134  $response = $connector->kick($scope, $query);
135  $responseObject = json_decode($response);
136 
137  $room->banUser($_REQUEST['user']);
138 
139  if($responseObject->success == true)
140  {
141  $room->addHistoryEntry($messageObject, '', 1);
142 
143  $message = json_encode(array(
144  'type' => 'userjustkicked',
145  'user' => $params['userToKick'],
146  'sub' => 0
147  ));
148 
149 
150  $connector->sendMessage($room->getRoomId(), $message, array(
151  'public' => 1,
152  'sub' => 0
153  ));
154  $room->disconnectUser(new ilObjUser($params['userToKick']));
155  }
156  }
157  else
158  {
159  $response = json_encode(array(
160  'success' => false,
161  'reason' => 'unkown room'
162  ));
163  }
164 
165  echo $response;
166  exit;
167  }
168 
177  private function buildMessage($messageString, ilChatroomUser $user)
178  {
179  $data = new stdClass();
180 
181  $data->user = $this->gui->object->getPersonalInformation( $user );
182  $data->userToKick = $messageString;
183  $data->timestamp = date( 'c' );
184  $data->type = 'kick';
185 
186  return $data;
187  }
188 
189 }
190 
191 ?>