ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
48 {
49 global $DIC;
50
51 $this->gui = $gui;
52 $this->ilUser = $DIC->user();
53 $this->ilCtrl = $DIC->ctrl();
54 $this->ilLng = $DIC->language();
55 $this->upload = $DIC->upload();
56 $this->webDirectory = $DIC->filesystem()->web();
57 }
58
63 protected function getRoomByObjectId($objectId)
64 {
65 return ilChatroom::byObjectId($objectId);
66 }
67
72 protected function exitIfNoRoomExists($room)
73 {
74 if (!$room) {
75 $this->sendResponse(
76 array(
77 'success' => false,
78 'reason' => 'unkown room',
79 )
80 );
81 }
82 }
83
88 public function sendResponse($response)
89 {
90 echo json_encode($response);
91 exit;
92 }
93
100 protected function exitIfNoRoomPermission($room, $subRoom, $chat_user)
101 {
102 if (!$this->canModerate($room, $subRoom, $chat_user->getUserId())) {
103 $this->sendResponse(
104 array(
105 'success' => false,
106 'reason' => 'not owner of private room',
107 )
108 );
109 }
110 }
111
119 protected function canModerate($room, $subRoom, $user_id)
120 {
121 return $this->isMainRoom($subRoom) || $room->isOwnerOfPrivateRoom($user_id, $subRoom) || $this->hasPermission('moderate');
122 }
123
128 protected function isMainRoom($subRoomId)
129 {
130 return $subRoomId == 0;
131 }
132
138 public function hasPermission($permission)
139 {
140 return ilChatroom::checkUserPermissions($permission, $this->gui->ref_id);
141 }
142
149 public function execute($method)
150 {
151 $this->ilLng->loadLanguageModule('chatroom');
152
153 if (method_exists($this, $method)) {
154 return $this->$method();
155 } else {
156 return $this->executeDefault($method);
157 }
158 }
159
164 abstract public function executeDefault($requestedMethod);
165
170 public function redirectIfNoPermission($permission)
171 {
172 if (!ilChatroom::checkUserPermissions($permission, $this->gui->ref_id)) {
173 $this->ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
174 $this->ilCtrl->redirectByClass('ilrepositorygui', '');
175 }
176 }
177
183 public function isSuccessful($response)
184 {
185 $response = json_decode($response, true);
186
187 return $response !== null && array_key_exists('success', $response) && $response['success'];
188 }
189}
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.
$response
global $DIC
Definition: saml.php:7