ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjFooterUIHandling.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\GlobalScreen_\UI\Translator;
28use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
33
35{
36 use Hasher;
37
41
42
43 public function __construct(
44 private UIServices $ui,
45 private Services $http,
46 private ilTabsGUI $tabs_gui,
47 private Translator $translator,
48 private ilCtrlInterface $ctrl,
49 private ilErrorHandling $error,
50 private ilRbacSystem $rbac_system,
51 private int $ref_id
52 ) {
53 $this->main_tpl = $this->ui->mainTemplate();
54 $this->ui_renderer = $this->ui->renderer();
55 $this->ui_factory = $this->ui->factory();
56 }
57
58 public function outAsyncAsModal(
59 string $title,
60 string $post_url,
62 ): void {
63 $is_form = count($components) === 1 && $components[0] instanceof Form;
64 $are_interruptive = array_filter($components, fn($component): bool => $component instanceof KeyValue) !== [];
65
66 $modal = match (true) {
67 $is_form => $this->ui_factory->modal()->roundtrip(
68 $title,
69 null,
71 $post_url
72 ),
73 $are_interruptive => $this->ui_factory->modal()->interruptive(
74 $title,
75 $this->translator->translate('confirm_delete'),
76 $post_url
77 )->withAffectedItems(
78 array_map(
79 fn(KeyValue $item): \ILIAS\UI\Component\Modal\InterruptiveItem\KeyValue => $this->ui_factory->modal()->interruptiveItem()->keyValue(
80 $this->hash($item->getId()),
81 $item->getKey(),
82 $item->getValue()
83 ),
85 )
86 ),
87 default => $this->ui_factory->modal()->roundtrip(
88 $title,
90 [],
91 $post_url
92 )
93 };
94
95 $this->outAsync($modal);
96 }
97
98 public function outAsync(?Component ...$components): void
99 {
100 $components = array_filter($components, fn($component): bool => $component !== null);
101 $string = $this->ui_renderer->renderAsync($components);
102 $response = $this->http->response()->withBody(
103 Streams::ofString(
104 $string
105 )
106 );
107 $this->http->saveResponse($response);
108 $this->http->sendResponse();
109 $this->http->close();
110 }
111
112 public function out(?Component ...$components): void
113 {
114 $components = array_filter($components, fn($component): bool => $component !== null);
115
116 $this->main_tpl->setContent(
117 $this->ui_renderer->render($components)
118 );
119 }
120 public function render(?Component ...$components): string
121 {
122 $components = array_filter($components, fn($component): bool => $component !== null);
123
124 return $this->ui_renderer->render($components);
125 }
126
127 public function buildMainTabs(): void
128 {
129 $this->tabs_gui->addTab(
131 $this->translator->translate('groups'),
132 $this->ctrl->getLinkTargetByClass(
133 ilObjFooterAdministrationGUI::class,
135 )
136 );
137 $this->tabs_gui->addTab(
139 $this->translator->translate('perm_settings'),
140 $this->ctrl->getLinkTargetByClass([ilObjFooterAdministrationGUI::class, ilPermissionGUI::class], 'perm')
141 );
142 }
143
144 public function backToMainTab(): void
145 {
146 $this->tabs_gui->clearTargets();
147
148 if (
150 && $this->ctrl->getCmdClass() === strtolower(ilFooterEntriesGUI::class)
151 ) {
152 $this->tabs_gui->setBackTarget(
153 $this->translator->translate('back'),
154 $this->ctrl->getLinkTargetByClass(
155 ilFooterEntriesGUI::class,
157 )
158 );
159 return;
160 }
161
162 $this->tabs_gui->setBackTarget(
163 $this->translator->translate('back'),
164 $this->ctrl->getLinkTargetByClass(
165 ilObjFooterAdministrationGUI::class,
167 )
168 );
169 }
170
171 public function activateTab(string $tab): void
172 {
173 $this->tabs_gui->activateTab($tab);
174 }
175
176 public function requireReadable(): void
177 {
178 $this->require('read');
179 }
180
181 public function requireWritable(): void
182 {
183 $this->require('write');
184 }
185
186 public function hasPermission(string $permissions): bool
187 {
188 return $this->rbac_system->checkAccess($permissions, $this->ref_id);
189 }
190
191 public function require(string $permissions): void
192 {
193 if (!$this->hasPermission($permissions)) {
194 $this->error->raiseError($this->translator->translate('msg_no_perm_read'), $this->error->WARNING);
195 }
196 }
197
198 public function getHereAsURI(?string $cmd = null): URI
199 {
200 $uri = new URI((string) $this->http->request()->getUri());
201 if ($cmd !== null) {
202 return $uri->withParameter('cmd', $cmd);
203 }
204 return $uri;
205 }
206 public function buildURI(string $from_path): URI
207 {
208 $request = $this->http->request()->getUri();
209 return new URI($request->getScheme() . '://' . $request->getHost() . '/' . ltrim($from_path, '/'));
210 }
211
212 public function sendMessageAndRedirect(
213 string $type,
214 string $message,
215 string $target
216 ): void {
217 $this->main_tpl->setOnScreenMessage(
218 $type,
219 $message,
220 true
221 );
222 $this->ctrl->redirectToURL($target);
223 }
224
225 public function saveIdentificationsToRequest(
226 object|string $gui_class,
227 string|URLBuilderToken $token,
228 string $value
229 ): void {
230 $name = $token instanceof URLBuilderToken ? $token->getName() : $token;
231 $this->ctrl->setParameterByClass(
232 is_object($gui_class) ? $gui_class::class : $gui_class,
233 $name,
234 $this->hash($value)
235 );
236 }
237
238 public function getIdentificationsFromRequest(string|URLBuilderToken $token): array
239 {
240 if ($token === null) {
241 return [];
242 }
243
244 $query_params = $this->http->request()->getQueryParams(); // aka $_GET
245 $name = $token instanceof URLBuilderToken ? $token->getName() : $token;
246 $ids = $query_params[$name] ?? []; // array of field ids
247 $ids = is_array($ids) ? $ids : [$ids];
248
249 // all objects
250 if (($ids[0] ?? null) === 'ALL_OBJECTS') {
251 return []; // currently we cannot support all
252 }
253
254 // check interruptive items
255 if (($interruptive_items = $this->http->request()->getParsedBody()['interruptive_items'] ?? false)) {
256 foreach ($interruptive_items as $interruptive_item) {
257 $ids[] = $interruptive_item;
258 }
259 }
260
261 return array_map(fn($id): string => $this->unhash($id), $ids);
262 }
263
264}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
Class Services.
Definition: Services.php:38
error(string $a_errmsg)
return true
Error Handling & global info handling.
__construct(private UIServices $ui, private Services $http, private ilTabsGUI $tabs_gui, private Translator $translator, private ilCtrlInterface $ctrl, private ilErrorHandling $error, private ilRbacSystem $rbac_system, private int $ref_id)
outAsyncAsModal(string $title, string $post_url, ?Component ... $components)
render(?Component ... $components)
out(?Component ... $components)
outAsync(?Component ... $components)
ilGlobalTemplateInterface $main_tpl
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...
$http
Definition: deliver.php:30
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes commonalities between all forms.
Definition: Form.php:33
This is how the factory for UI elements looks.
Definition: Factory.php:38
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...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$message
Definition: xapiexit.php:31
$token
Definition: xapitoken.php:70
$response
Definition: xapitoken.php:93