ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomGUIHandler.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5
13{
17 protected $gui;
18
22 protected $ilUser;
23
27 protected $ilCtrl;
28
32 protected $ilLng;
33
37 protected $webDirectory;
38
42 protected $obj_service;
43
47 protected $upload;
48
52 protected $rbacsystem;
53
57 protected $mainTpl;
58
62 protected $ilias;
63
68
72 protected $tree;
73
77 protected $tabs;
78
83 {
84 global $DIC;
85
86 $this->gui = $gui;
87 $this->ilUser = $DIC->user();
88 $this->ilCtrl = $DIC->ctrl();
89 $this->ilLng = $DIC->language();
90 $this->rbacsystem = $DIC->rbac()->system();
91 $this->mainTpl = $DIC->ui()->mainTemplate();
92 $this->upload = $DIC->upload();
93 $this->webDirectory = $DIC->filesystem()->web();
94 $this->obj_service = $DIC->object();
95 $this->ilias = $DIC['ilias'];
96 $this->tabs = $DIC->tabs();
97 $this->navigationHistory = $DIC['ilNavigationHistory'];
98 $this->tree = $DIC['tree'];
99 }
100
107 public function execute($method)
108 {
109 $this->ilLng->loadLanguageModule('chatroom');
110
111 if (method_exists($this, $method)) {
112 return $this->$method();
113 } else {
114 return $this->executeDefault($method);
115 }
116 }
117
122 abstract public function executeDefault($requestedMethod);
123
128 public function redirectIfNoPermission($permission)
129 {
130 if (!ilChatroom::checkUserPermissions($permission, $this->gui->ref_id)) {
131 $this->ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
132 $this->ilCtrl->redirectByClass('ilrepositorygui', '');
133 }
134 }
135
141 public function isSuccessful($response)
142 {
143 $response = json_decode($response, true);
144
145 return $response !== null && array_key_exists('success', $response) && $response['success'];
146 }
147
152 protected function getRoomByObjectId($objectId)
153 {
154 return ilChatroom::byObjectId($objectId);
155 }
156
161 protected function exitIfNoRoomExists($room)
162 {
163 if (!$room) {
164 $this->sendResponse(
165 array(
166 'success' => false,
167 'reason' => 'unkown room',
168 )
169 );
170 }
171 }
172
177 public function sendResponse($response)
178 {
179 echo json_encode($response);
180 exit;
181 }
182
189 protected function exitIfNoRoomPermission($room, $subRoom, $chat_user)
190 {
191 if (!$this->canModerate($room, $subRoom, $chat_user->getUserId())) {
192 $this->sendResponse(
193 array(
194 'success' => false,
195 'reason' => 'not owner of private room',
196 )
197 );
198 }
199 }
200
208 protected function canModerate($room, $subRoom, $user_id)
209 {
210 return $this->isMainRoom($subRoom) || $room->isOwnerOfPrivateRoom(
211 $user_id,
212 $subRoom
213 ) || $this->hasPermission('moderate');
214 }
215
220 protected function isMainRoom($subRoomId)
221 {
222 return $subRoomId == 0;
223 }
224
230 public function hasPermission($permission)
231 {
232 return ilChatroom::checkUserPermissions($permission, $this->gui->ref_id);
233 }
234}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomGUIHandler.
executeDefault($requestedMethod)
canModerate($room, $subRoom, $user_id)
Checks if the user has permission to moderate a ilChatroom.
hasPermission($permission)
Checks for access with ilRbacSystem.
execute($method)
Executes given $method if existing, otherwise executes executeDefault() method.
exitIfNoRoomPermission($room, $subRoom, $chat_user)
Check if user can moderate a chatroom.
__construct(ilChatroomObjectGUI $gui)
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
sendResponse($response)
Sends a json encoded response and exits the php process.
exitIfNoRoomExists($room)
Checks if a ilChatroom exists.
isSuccessful($response)
Checks for success param in an json decoded response.
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.
This class provides processing control methods.
setParameterByClass($a_class, $a_parameter, $a_value)
Same as setParameterByClass, except that a class name is passed.
redirectByClass($a_class, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to other gui class using class name.
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
exit
Definition: login.php:29
redirection script todo: (a better solution should control the processing via a xml file)
$response