ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
26 {
27 $this->gui = $gui;
28 }
29
36 public function executeDefault($method)
37 {
42 global $ilUser, $ilCtrl;
43
44 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
45 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
46
47 if(!ilChatroom::checkUserPermissions(array('read', 'moderate'), $this->gui->ref_id))
48 {
49 $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
50 $ilCtrl->redirectByClass('ilrepositorygui', '');
51 }
52
53 $room = ilChatroom::byObjectId($this->gui->object->getId());
54
55 if($room)
56 {
57 // if user is in scope
58 $scope = $room->getRoomId();
59
60 $chat_user = new ilChatroomUser($ilUser, $room);
61
62 $messageObject = $this->buildMessage(
63 ilUtil::stripSlashes($_REQUEST['user']), $chat_user
64 );
65
66 $message = json_encode($messageObject);
67
68 $params = array(
69 'message' => $message,
70 'userToKick' => $_REQUEST['user']
71 );
72
73 $query = http_build_query($params);
74 $connector = $this->gui->getConnector();
75 $response = $connector->kick($scope, $query);
76 $responseObject = json_decode($response);
77
78 if($responseObject->success == true)
79 {
80 $room->addHistoryEntry($messageObject, '', 1);
81
82 $message = json_encode(array(
83 'type' => 'userjustkicked',
84 'user' => $params['userToKick'],
85 'sub' => 0
86 ));
87
88 $connector->sendMessage($room->getRoomId(), $message, array(
89 'public' => 1,
90 'sub' => 0
91 ));
92
93 // 2013-09-11: Should already been done by the chat server
94 $room->disconnectUser($params['userToKick']);
95 }
96 }
97 else
98 {
99 $response = json_encode(array(
100 'success' => false,
101 'reason' => 'unkown room'
102 ));
103 }
104
105 echo $response;
106 exit;
107 }
108
117 private function buildMessage($messageString, ilChatroomUser $chat_user)
118 {
119 $data = new stdClass();
120
121 $data->user = $this->gui->object->getPersonalInformation( $chat_user );
122 $data->userToKick = $messageString;
123 $data->timestamp = date( 'c' );
124 $data->type = 'kick';
125
126 return $data;
127 }
128
134 public function sub()
135 {
136 global $ilUser, $ilCtrl;
137
138 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
139 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
140
141 $room = ilChatroom::byObjectId($this->gui->object->getId());
142
143 if($room)
144 {
145 if(!$room->isOwnerOfPrivateRoom($ilUser->getId(), $_REQUEST['sub']))
146 {
147 if(!ilChatroom::checkPermissionsOfUser($ilUser->getId(), array('read', 'moderate'), $this->gui->ref_id))
148 {
149 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
150 $ilCtrl->redirectByClass("ilrepositorygui", "");
151 }
152 }
153
154 $scope = $room->getRoomId();
155 $params = array();
156 $params['user'] = $_REQUEST['user'];
157 $params['sub'] = $_REQUEST['sub'];
158
159 if($room->userIsInPrivateRoom($params['sub'], $params['user']))
160 {
161 $query = http_build_query($params);
162 $connector = $this->gui->getConnector();
163 $response = $connector->leavePrivateRoom($scope, $query);
164 $responseObject = json_decode($response);
165 /*
166 if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
167 {
168 //$room->addHistoryEntry( $message, $recipient, $publicMessage );
169 }
170 */
171 $room->unsubscribeUserFromPrivateRoom($params['sub'], $params['user']);
172 $this->recantInvitation($params['sub'], $params['user']);
173
174 $message = json_encode(array(
175 'type' => 'userjustkicked',
176 'user' => $params['user'],
177 'sub' => $params['sub']
178 ));
179
180 $connector->sendMessage($room->getRoomId(), $message, array(
181 'public' => 1,
182 'sub' => 0
183 ));
184 }
185 else
186 {
187 $response = json_encode(array(
188 'success' => true,
189 'message' => 'was not in room'
190 ));
191 }
192
193 echo $response;
194 exit;
195 }
196 }
197
205 public function recantInvitation($subroom_id, $user_id)
206 {
207 global $ilDB;
208
209 $query = "
210 SELECT proom_id
211 FROM chatroom_proomaccess
212 WHERE proom_id = %s
213 AND user_id = %s
214 ";
215
216 $types = array( 'integer', 'integer' );
217 $values = array( $subroom_id, $user_id );
218
219 $res = $ilDB->queryF( $query, $types, $values );
220
221 if( $row = $ilDB->fetchAssoc( $res ) )
222 {
223 $delete = "
224 DELETE
225 FROM chatroom_proomaccess
226 WHERE proom_id = %s
227 AND user_id = %s
228 ";
229
230 $ilDB->manipulateF( $delete, $types, $values );
231 }
232 }
233
234}
235
236?>
Class ilChatroomKickTask.
sub()
Kicks user from subroom into mainroom.
buildMessage($messageString, ilChatroomUser $chat_user)
Instantiates stdClass, sets $data->user and $data->userToKick using given $messageString and $chat_us...
recantInvitation($subroom_id, $user_id)
Recant invitation for given $user_id in given $subroom_id.
__construct(ilChatroomObjectGUI $gui)
Constructor.
executeDefault($requestedMethod)
Class ilChatroomUser.
static checkPermissionsOfUser($usr_id, $permissions, $ref_id)
Checks user permissions in question for a given user id in relation to a given ref_id.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$data
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilDB
global $ilUser
Definition: imgupload.php:15