ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomGUIHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\Refinery\Factory as Refinery;
28use ILIAS\UI\Factory as UIFactory;
29use ILIAS\UI\Renderer as UIRenderer;
30
38{
39 protected ilObjUser $ilUser;
41 protected ilLanguage $ilLng;
47 protected ILIAS $ilias;
49 protected ilTree $tree;
50 protected ilTabsGUI $tabs;
51 protected UIFactory $uiFactory;
52 protected UIRenderer $uiRenderer;
54 protected Refinery $refinery;
56
60 public function __construct(protected ilChatroomObjectGUI $gui)
61 {
63 global $DIC;
64 $this->ilUser = $DIC->user();
65 $this->ilCtrl = $DIC->ctrl();
66 $this->ilLng = $DIC->language();
67 $this->rbacsystem = $DIC->rbac()->system();
68 $this->mainTpl = $DIC->ui()->mainTemplate();
69 $this->upload = $DIC->upload();
70 $this->webDirectory = $DIC->filesystem()->web();
71 $this->obj_service = $DIC->object();
72 $this->ilias = $DIC['ilias'];
73 $this->tabs = $DIC->tabs();
74 $this->navigationHistory = $DIC['ilNavigationHistory'];
75 $this->tree = $DIC['tree'];
76 $this->uiFactory = $DIC->ui()->factory();
77 $this->uiRenderer = $DIC->ui()->renderer();
78 $this->http = $DIC->http();
79 $this->refinery = $DIC->refinery();
80 $this->file_delivery = $DIC['file_delivery'];
81 }
82
87 protected function getRequestValue(string $key, Transformation $trafo, $default = null)
88 {
89 if ($this->http->wrapper()->query()->has($key)) {
90 return $this->http->wrapper()->query()->retrieve($key, $trafo);
91 }
92
93 if ($this->http->wrapper()->post()->has($key)) {
94 return $this->http->wrapper()->post()->retrieve($key, $trafo);
95 }
96
97 return $default;
98 }
99
100 protected function hasRequestValue(string $key): bool
101 {
102 if ($this->http->wrapper()->query()->has($key)) {
103 return true;
104 }
105
106 return $this->http->wrapper()->post()->has($key);
107 }
108
109 public function execute(string $method): void
110 {
111 $this->ilLng->loadLanguageModule('chatroom');
112
113 if (is_callable([$this, $method])) {
114 $this->$method();
115 return;
116 }
117
118 $this->executeDefault($method);
119 }
120
121 abstract public function executeDefault(string $requestedMethod): void;
122
127 public function redirectIfNoPermission($permission): void
128 {
129 if (!ilChatroom::checkUserPermissions($permission, $this->gui->getRefId())) {
130 $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
131 $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
132 }
133 }
134
140 public function isSuccessful($response): bool
141 {
142 if (!is_string($response)) {
143 return false;
144 }
145
146 $response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
147
148 return $response !== null && array_key_exists('success', $response) && $response['success'];
149 }
150
151 protected function getRoomByObjectId(int $objectId): ?ilChatroom
152 {
153 return ilChatroom::byObjectId($objectId);
154 }
155
159 protected function exitIfNoRoomExists(?ilChatroom $room): void
160 {
161 if (null === $room) {
162 $this->sendJSONResponse([
163 'success' => false,
164 'reason' => 'unknown room',
165 ]);
166 }
167 }
168
172 protected function sendJSONResponse($response): void
173 {
174 $this->sendResponse(json_encode($response), 'application/json');
175 }
176
180 protected function sendResponse(string $content, string $type): void
181 {
182 $this->http->saveResponse(
183 $this->http->response()
184 ->withHeader(ResponseHeader::CONTENT_TYPE, $type)
185 ->withBody(Streams::ofString($content))
186 );
187 $this->http->sendResponse();
188 $this->http->close();
189 }
190
191 public function hasPermission(string $permission): bool
192 {
193 return ilChatroom::checkUserPermissions($permission, $this->gui->getRefId());
194 }
195}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
Class ilChatroomGUIHandler.
ilGlobalTemplateInterface $mainTpl
ILIAS FileDelivery Services $file_delivery
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
exitIfNoRoomExists(?ilChatroom $room)
Checks if a ilChatroom exists.
executeDefault(string $requestedMethod)
sendResponse(string $content, string $type)
Sends a response and exits the php process.
ilNavigationHistory $navigationHistory
sendJSONResponse($response)
Sends a json encoded response and exits the php process.
isSuccessful($response)
Checks for success param in an json decoded response.
getRequestValue(string $key, Transformation $trafo, $default=null)
Class ilChatroom.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static byObjectId(int $object_id)
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
language handling
Last visited history for repository items.
User class.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const ROOT_FOLDER_ID
Definition: constants.php:32
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
Interface GlobalHttpState.
Interface ResponseHeader.
A transformation is a function from one datatype to another.
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26
$response
Definition: xapitoken.php:93