ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomKickTask.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('read', '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  $messageObject = $this->buildMessage(
58  ilUtil::stripSlashes($_REQUEST['user']), $chat_user
59  );
60 
61  $message = json_encode($messageObject);
62 
63  $params = array(
64  'message' => $message,
65  'userToKick' => $_REQUEST['user']
66  );
67 
68  $query = http_build_query($params);
69  $connector = $this->gui->getConnector();
70  $response = $connector->kick($scope, $query);
71  $responseObject = json_decode($response);
72 
73  if($responseObject->success == true)
74  {
75  $room->addHistoryEntry($messageObject, '', 1);
76 
77  $message = json_encode(array(
78  'type' => 'userjustkicked',
79  'user' => $params['userToKick'],
80  'sub' => 0
81  ));
82 
83  $connector->sendMessage($room->getRoomId(), $message, array(
84  'public' => 1,
85  'sub' => 0
86  ));
87  $room->disconnectUser(new ilObjUser($params['userToKick']));
88  }
89  }
90  else
91  {
92  $response = json_encode(array(
93  'success' => false,
94  'reason' => 'unkown room'
95  ));
96  }
97 
98  echo $response;
99  exit;
100  }
101 
110  private function buildMessage($messageString, ilChatroomUser $chat_user)
111  {
112  $data = new stdClass();
113 
114  $data->user = $this->gui->object->getPersonalInformation( $chat_user );
115  $data->userToKick = $messageString;
116  $data->timestamp = date( 'c' );
117  $data->type = 'kick';
118 
119  return $data;
120  }
121 
127  public function sub()
128  {
129  global $ilUser;
130 
131  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
132  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
133 
134  $room = ilChatroom::byObjectId($this->gui->object->getId());
135 
136  if($room)
137  {
138  if(!$room->isOwnerOfPrivateRoom($ilUser->getId(), $_REQUEST['sub']))
139  {
140  if(!ilChatroom::checkPermissionsOfUser($ilUser->getId(), array('read', 'moderate'), $this->gui->ref_id))
141  {
142  ilUtil::redirect("repository.php");
143  }
144  }
145 
146  $scope = $room->getRoomId();
147  $params = array();
148  $params['user'] = $_REQUEST['user'];
149  $params['sub'] = $_REQUEST['sub'];
150 
151  if($room->userIsInPrivateRoom($params['sub'], $params['user']))
152  {
153  $query = http_build_query($params);
154  $connector = $this->gui->getConnector();
155  $response = $connector->leavePrivateRoom($scope, $query);
156  $responseObject = json_decode($response);
157  /*
158  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
159  {
160  //$room->addHistoryEntry( $message, $recipient, $publicMessage );
161  }
162  */
163  $room->unsubscribeUserFromPrivateRoom($params['sub'], $params['user']);
164  $this->recantInvitation($params['sub'], $params['user']);
165 
166  $message = json_encode(array(
167  'type' => 'userjustkicked',
168  'user' => $params['user'],
169  'sub' => $params['sub']
170  ));
171 
172  $connector->sendMessage($room->getRoomId(), $message, array(
173  'public' => 1,
174  'sub' => 0
175  ));
176  }
177  else
178  {
179  $response = json_encode(array(
180  'success' => true,
181  'message' => 'was not in room'
182  ));
183  }
184 
185  echo $response;
186  exit;
187  }
188  }
189 
197  public function recantInvitation($subroom_id, $user_id)
198  {
199  global $ilDB;
200 
201  $query = "
202  SELECT proom_id
203  FROM chatroom_proomaccess
204  WHERE proom_id = %s
205  AND user_id = %s
206  ";
207 
208  $types = array( 'integer', 'integer' );
209  $values = array( $subroom_id, $user_id );
210 
211  $res = $ilDB->queryF( $query, $types, $values );
212 
213  if( $row = $ilDB->fetchAssoc( $res ) )
214  {
215  $delete = "
216  DELETE
217  FROM chatroom_proomaccess
218  WHERE proom_id = %s
219  AND user_id = %s
220  ";
221 
222  $ilDB->manipulateF( $delete, $types, $values );
223  }
224  }
225 
226 }
227 
228 ?>