ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $upload;
43
47 protected $rbacsystem;
48
52 protected $mainTpl;
53
57 protected $ilias;
58
61
63 protected $tree;
64
66 protected $tabs;
71 {
72 global $DIC;
73
74 $this->gui = $gui;
75 $this->ilUser = $DIC->user();
76 $this->ilCtrl = $DIC->ctrl();
77 $this->ilLng = $DIC->language();
78 $this->rbacsystem = $DIC->rbac()->system();
79 $this->mainTpl = $DIC->ui()->mainTemplate();
80 $this->upload = $DIC->upload();
81 $this->webDirectory = $DIC->filesystem()->web();
82 $this->ilias = $DIC['ilias'];
83 $this->tabs = $DIC->tabs();
84 $this->navigationHistory = $DIC['ilNavigationHistory'];
85 $this->tree = $DIC['tree'];
86 }
87
92 protected function getRoomByObjectId($objectId)
93 {
94 return ilChatroom::byObjectId($objectId);
95 }
96
101 protected function exitIfNoRoomExists($room)
102 {
103 if (!$room) {
104 $this->sendResponse(
105 array(
106 'success' => false,
107 'reason' => 'unkown room',
108 )
109 );
110 }
111 }
112
117 public function sendResponse($response)
118 {
119 echo json_encode($response);
120 exit;
121 }
122
129 protected function exitIfNoRoomPermission($room, $subRoom, $chat_user)
130 {
131 if (!$this->canModerate($room, $subRoom, $chat_user->getUserId())) {
132 $this->sendResponse(
133 array(
134 'success' => false,
135 'reason' => 'not owner of private room',
136 )
137 );
138 }
139 }
140
148 protected function canModerate($room, $subRoom, $user_id)
149 {
150 return $this->isMainRoom($subRoom) || $room->isOwnerOfPrivateRoom($user_id, $subRoom) || $this->hasPermission('moderate');
151 }
152
157 protected function isMainRoom($subRoomId)
158 {
159 return $subRoomId == 0;
160 }
161
167 public function hasPermission($permission)
168 {
169 return ilChatroom::checkUserPermissions($permission, $this->gui->ref_id);
170 }
171
178 public function execute($method)
179 {
180 $this->ilLng->loadLanguageModule('chatroom');
181
182 if (method_exists($this, $method)) {
183 return $this->$method();
184 } else {
185 return $this->executeDefault($method);
186 }
187 }
188
193 abstract public function executeDefault($requestedMethod);
194
199 public function redirectIfNoPermission($permission)
200 {
201 if (!ilChatroom::checkUserPermissions($permission, $this->gui->ref_id)) {
202 $this->ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
203 $this->ilCtrl->redirectByClass('ilrepositorygui', '');
204 }
205 }
206
212 public function isSuccessful($response)
213 {
214 $response = json_decode($response, true);
215
216 return $response !== null && array_key_exists('success', $response) && $response['success'];
217 }
218}
exit
Definition: backend.php:16
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.
redirection script todo: (a better solution should control the processing via a xml file)
$response
global $DIC
Definition: saml.php:7