ILIAS  release_8 Revision v8.24
PageContentGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use InvalidArgumentException;
26use ilToolbarGUI;
27use ilTemplate;
28use ilSession;
32
38{
41
45 protected array $lightbox = [];
46
50 protected array $messages = [];
51
55 protected array $title_alerts = [];
56
57 protected ?string $page_form_action = null;
58 protected ?string $title = null;
59 protected ?string $title_desc = null;
60 protected ?string $header_action = null;
61 protected ?string $tabs_html = null;
62 protected ?string $sub_tabs_html = null;
63 protected ?string $main_content = null;
64 protected ?string $right_content = null;
65 protected ?string $left_content = null;
66 protected ?string $icon_path = null;
67 protected ?string $icon_desc = null;
68 protected ?string $filter = null;
69 protected ?string $banner_image_src = null;
70 protected ?int $file_upload_ref_id = null;
71 protected bool $is_title_hidden = false;
72 protected bool $should_display_admin_panel_arrow = false;
73 protected bool $is_admin_panel_for_bottom = false;
74 private \ILIAS\DI\UIServices $ui_service;
75
79 public function __construct(
80 string $file,
81 bool $flag1,
82 bool $flag2,
83 string $in_module = '',
85 bool $plugin = false,
86 bool $a_use_cache = true
87 ) {
88 global $DIC;
89 $this->template = new ilTemplate(
90 $file,
91 $flag1,
92 $flag2,
93 $in_module,
94 $vars,
95 $plugin,
96 $a_use_cache
97 );
98 $this->ui_service = $DIC->ui();
99 }
100
101 public function addBlockFile(string $var, string $block, string $template_name, string $in_module = null): bool
102 {
103 return $this->template->addBlockFile($var, $block, $template_name, $in_module);
104 }
105
106 public function blockExists(string $block_name): bool
107 {
108 return $this->template->blockExists($block_name);
109 }
110
111 public function removeBlockData(string $block_name): void
112 {
113 $this->template->removeBlockData($block_name);
114 }
115
116 public function setVariable(string $variable, string $value = ''): void
117 {
118 $this->template->setVariable($variable, $value);
119 }
120
121 public function setCurrentBlock(string $block_name = ilGlobalTemplateInterface::DEFAULT_BLOCK): bool
122 {
123 return $this->template->setCurrentBlock($block_name);
124 }
125
126 public function touchBlock(string $block_name): void
127 {
128 $this->template->touchBlock($block_name);
129 }
130
131 public function parseCurrentBlock(string $block_name = ilGlobalTemplateInterface::DEFAULT_BLOCK): bool
132 {
133 return $this->template->parseCurrentBlock($block_name);
134 }
135
136 public function setPageFormAction(string $page_form_action): void
137 {
138 if (!empty($page_form_action)) {
139 $this->page_form_action = $page_form_action;
140 }
141 }
142
143 public function setMainContent(string $main_content): void
144 {
145 if (!empty($main_content)) {
146 $this->main_content = $main_content;
147 }
148 }
149
150 public function addLightbox(string $lightbox_html, string $id): void
151 {
152 if (!empty($lightbox_html)) {
153 $this->lightbox[$id] = $lightbox_html;
154 }
155 }
156
157 public function setHeaderPageTitle(string $header_page_title): void
158 {
159 // property is never used.
160 }
161
162 public function setBanner(string $image_src): void
163 {
164 if (!empty($image_src)) {
165 $this->banner_image_src = $image_src;
166 }
167 }
168
169 public function getBanner(): ?string
170 {
172 }
173
174 public function setTitle(string $title, bool $is_hidden = false): void
175 {
176 if (!empty($title)) {
177 $this->title = $title;
178 $this->is_title_hidden = $is_hidden;
179 }
180 }
181
182 public function setTitleDesc(string $title_desc): void
183 {
184 $this->title_desc = $title_desc;
185 }
186
187 public function setTitleAlerts(array $title_alerts): void
188 {
189 $this->title_alerts = $title_alerts;
190 }
191
192 public function setHeaderAction(string $header_action): void
193 {
194 if (!empty($header_action)) {
195 $this->header_action = $header_action;
196 }
197 }
198
200 {
201 $this->admin_panel_commands_toolbar = $admin_panel_commands_toolbar;
202 }
203
205 {
206 $this->should_display_admin_panel_arrow = $should_display_admin_panel_arrow;
207 }
208
210 {
211 $this->is_admin_panel_for_bottom = $is_admin_panel_for_bottom;
212 }
213
214 public function setRightContent(string $content): void
215 {
216 if (!empty($content)) {
217 $this->right_content = $content;
218 }
219 }
220
221 public function setLeftContent(string $content): void
222 {
223 if (!empty($content)) {
224 $this->left_content = $content;
225 }
226 }
227
228 public function setFilter(string $filter): void
229 {
230 if (!empty($filter)) {
231 $this->filter = $filter;
232 }
233 }
234
235 protected function fillFilter(): void
236 {
237 if (null !== $this->filter) {
238 $this->template->setCurrentBlock("filter");
239 $this->template->setVariable("FILTER", trim($this->filter));
240 $this->template->parseCurrentBlock();
241 }
242 }
243
244 public function setIconPath(string $icon_path): void
245 {
246 if (!empty($icon_path)) {
247 $this->icon_path = $icon_path;
248 }
249 }
250
251 public function setIconDesc(string $icon_desc): void
252 {
253 if (!empty($icon_desc)) {
254 $this->icon_desc = $icon_desc;
255 }
256 }
257
258 public function setFileUploadRefId(int $upload_ref_id): void
259 {
260 $this->file_upload_ref_id = $upload_ref_id;
261 }
262
263 public function setOnScreenMessage(string $type, string $message, bool $should_keep = false): void
264 {
265 if (!in_array($type, ilGlobalTemplateInterface::MESSAGE_TYPES, true)) {
266 throw new InvalidArgumentException("Type '$type' is not declared in " . self::class . "::MESSAGE_TYPES and is therefore invalid.");
267 }
268
269 if (!$should_keep) {
270 $this->messages[$type] = $message;
271 } else {
273 }
274 }
275
276 public function get(string $part = ilGlobalTemplateInterface::DEFAULT_BLOCK): string
277 {
278 return $this->template->get($part);
279 }
280
281 public function renderPage(string $part, bool $a_fill_tabs): string
282 {
283 global $DIC;
284
285 $this->fillMessage();
286 $this->fillPageFormAction();
287
288 if ($a_fill_tabs) {
289 if ($this->template->blockExists("content")) {
290 // determine default screen id
291 $this->getTabsHTML();
292 }
293
294 $this->fillHeader();
295 $this->fillLeftContent();
296 $this->fillRightContent();
297 $this->fillAdminPanel();
298 $this->fillToolbar();
299 $this->fillFilter();
300 $this->setCenterColumnClass();
301
302 // these fill just plain placeholder variables in tpl.adm_content.html
303 if ($this->template->blockExists("content")) {
304 $this->template->setCurrentBlock("content");
305 $this->fillTabs();
306 $this->fillMainContent();
307 $this->fillLightbox();
308 $this->template->parseCurrentBlock();
309 }
310 }
311
313 $html = $this->template->getUnmodified();
314 } else {
315 $html = $this->template->getUnmodified($part);
316 }
317
318 // Modification of html is done inline here and can't be done
319 // by ilTemplate, because the "phase" is template_show in this
320 // case here.
321 $component_factory = $DIC["component.factory"];
322 foreach ($component_factory->getActivePluginsInSlot("uihk") as $ui_plugin) {
323 $gui_class = $ui_plugin->getUIClassInstance();
324
325 $resp = $gui_class->getHTML(
326 "",
327 "template_show",
328 [
329 "tpl_id" => '',
330 "tpl_obj" => $this,
331 "html" => $html
332 ]
333 );
334
335 if (\ilUIHookPluginGUI::KEEP !== $resp["mode"]) {
336 $html = $gui_class->modifyHTML($html, $resp);
337 }
338 }
339
340 // save language usages as late as possible
342
343 return $html;
344 }
345
346 protected function fillMessage(): void
347 {
348 $messages = [];
350 $message = $this->getMessageTextForType($type);
351 if (null !== $message) {
352 $messages[] = $this->getMessageBox($type, $message);
353 }
355 }
356
357 if (count($messages) > 0) {
358 $this->template->setVariable("MESSAGE", $this->ui_service->renderer()->render($messages));
359 }
360 }
361
362 private function getMessageBox(string $type, string $message): MessageBox
363 {
364 $box_factory = $this->ui_service->factory()->messageBox();
365 switch ($type) {
366 case 'info':
367 $box = $box_factory->info($message);
368 break;
369 case 'success':
370 $box = $box_factory->success($message);
371 break;
372 case 'question':
373 $box = $box_factory->confirmation($message);
374 break;
375 case 'failure':
376 $box = $box_factory->failure($message);
377 break;
378 default:
379 throw new InvalidArgumentException();
380 }
381
382 return $box;
383 }
384
385 protected function getMessageTextForType(string $type): ?string
386 {
387 if (ilSession::has($type)) {
388 return (string) ilSession::get($type);
389 }
390
391 return $this->messages[$type] ?? null;
392 }
393
394 protected function getTabsHTML(): void
395 {
396 global $DIC;
397
398 $ilTabs = $DIC["ilTabs"];
399
400 if ($this->template->blockExists("tabs_outer_start")) {
401 $this->sub_tabs_html = $ilTabs->getSubTabHTML();
402 $this->tabs_html = $ilTabs->getHTML(true);
403 }
404 }
405
406 protected function initHelp(): void
407 {
408 //\ilHelpGUI::initHelp($this);
409 }
410
411 protected function fillHeader(): void
412 {
413 global $DIC;
414
415 $lng = $DIC->language();
416
417 $header_tpl = new ilTemplate('tpl.il_header.html', true, true);
418
419 $header = false;
420 if (null !== $this->banner_image_src && $this->template->blockExists("banner_bl")) {
421 $header_tpl->setCurrentBlock("banner_bl");
422 $header_tpl->setVariable("BANNER_URL", $this->banner_image_src);
423 $header = true;
424 $header_tpl->parseCurrentBlock();
425 }
426
427 if (null !== $this->icon_path) {
428 $header_tpl->setCurrentBlock("header_image");
429 $header_tpl->setVariable("IMG_HEADER", $this->icon_path);
430 $header_tpl->parseCurrentBlock();
431 $header = true;
432 }
433
434 if (null !== $this->title) {
435 $title = \ilUtil::stripScriptHTML($this->title);
436 $header_tpl->setVariable("HEADER", $title);
437 if ($this->is_title_hidden) {
438 $header_tpl->touchBlock("hidden_title");
439 }
440
441 $header = true;
442 }
443
444 if ($header && !$this->is_title_hidden) {
445 $header_tpl->setCurrentBlock("header_image");
446 $header_tpl->parseCurrentBlock();
447 }
448
449 if (null !== $this->title_desc) {
450 $header_tpl->setCurrentBlock("header_desc");
451 $header_tpl->setVariable("H_DESCRIPTION", $this->title_desc);
452 $header_tpl->parseCurrentBlock();
453 }
454
455 if (null !== $this->header_action) {
456 $header_tpl->setCurrentBlock("head_action_inner");
457 $header_tpl->setVariable("HEAD_ACTION", $this->header_action);
458 $header_tpl->parseCurrentBlock();
459 }
460
461 foreach ($this->title_alerts as $alert) {
462 $header_tpl->setCurrentBlock('header_alert');
463 if (!(bool) ($alert['propertyNameVisible'] ?? false)) {
464 $this->template->setVariable('H_PROP', $alert['property'] . ':');
465 }
466 $header_tpl->setVariable('H_VALUE', $alert['value']);
467 $header_tpl->parseCurrentBlock();
468 }
469
470 // add file upload drop zone in header
471 if ($this->file_upload_ref_id !== null) {
472 $file_upload = new ilObjFileUploadDropzone(
473 $this->file_upload_ref_id,
474 $header_tpl->get()
475 );
476
477 $this->template->setVariable(
478 "IL_DROPZONE_HEADER",
479 $file_upload->getDropzoneHtml()
480 );
481 } else {
482 $this->template->setVariable("IL_HEADER", $header_tpl->get());
483 }
484 }
485
486
487 protected function setCenterColumnClass(): void
488 {
489 if (!$this->template->blockExists("center_col_width")) {
490 return;
491 }
492
493 switch (true) {
494 case (null !== $this->left_content && null !== $this->right_content):
495 $center_column_class = 'col-sm-6';
496 break;
497
498 case (null !== $this->left_content || null !== $this->right_content):
499 $center_column_class = 'col-sm-9';
500 break;
501
502 default:
503 $center_column_class = 'col-sm-12';
504 break;
505 }
506
507 if (null !== $this->left_content) {
508 $center_column_class .= " col-sm-push-3";
509 }
510
511 $this->template->setCurrentBlock("center_col_width");
512 $this->template->setVariable("CENTER_COL", $center_column_class);
513 $this->template->parseCurrentBlock();
514 }
515
516 protected function fillMainContent(): void
517 {
518 if (null !== $this->main_content) {
519 $this->template->setVariable("ADM_CONTENT", trim($this->main_content));
520 }
521 }
522
523 protected function fillLeftContent(): void
524 {
525 if (null !== $this->left_content) {
526 $this->template->setCurrentBlock("left_column");
527 $this->template->setVariable("LEFT_CONTENT", trim($this->left_content));
528
529 $left_col_class = (null === $this->right_content)
530 ? "col-sm-3 col-sm-pull-9"
531 : "col-sm-3 col-sm-pull-6";
532
533 $this->template->setVariable("LEFT_COL_CLASS", $left_col_class);
534 $this->template->parseCurrentBlock();
535 }
536 }
537
538 protected function fillRightContent(): void
539 {
540 if (null !== $this->right_content) {
541 $this->template->setCurrentBlock("right_column");
542 $this->template->setVariable("RIGHT_CONTENT", trim($this->right_content));
543 $this->template->parseCurrentBlock();
544 }
545 }
546
547 protected function fillAdminPanel(): void
548 {
549 global $DIC;
550 $lng = $DIC->language();
551
552 if (null === $this->admin_panel_commands_toolbar) {
553 return;
554 }
555
556 $current_toolbar = $this->admin_panel_commands_toolbar;
557
558 // Add arrow if desired.
559 if ($this->should_display_admin_panel_arrow) {
560 $current_toolbar->setLeadingImage(\ilUtil::getImagePath("arrow_upright.svg"), $lng->txt("actions"));
561 }
562
563 $this->fillPageFormAction();
564
565 // Add top admin bar.
566 $this->template->setCurrentBlock("adm_view_components");
567 $this->template->setVariable("ADM_PANEL1", $current_toolbar->getHTML());
568 $this->template->parseCurrentBlock();
569
570 // Add bottom admin bar if user wants one.
571 if ($this->is_admin_panel_for_bottom) {
572 $this->template->setCurrentBlock("adm_view_components2");
573
574 // Replace previously set arrow image.
575 if ($this->should_display_admin_panel_arrow) {
576 $current_toolbar->setLeadingImage(\ilUtil::getImagePath("arrow_downright.svg"), $lng->txt("actions"));
577 }
578
579 $current_toolbar->setId($current_toolbar->getId() . "2");
580 $this->template->setVariable("ADM_PANEL2", $current_toolbar->getHTML());
581 $this->template->parseCurrentBlock();
582 }
583 }
584
585 protected function fillPageFormAction(): void
586 {
587 if (null !== $this->page_form_action) {
588 $this->template->setCurrentBlock("page_form_start");
589 $this->template->setVariable("PAGE_FORM_ACTION", $this->page_form_action);
590 $this->template->parseCurrentBlock();
591 $this->template->touchBlock("page_form_end");
592 }
593 }
594
595 protected function fillToolbar(): void
596 {
597 global $DIC;
598 $ilToolbar = $DIC["ilToolbar"];
599
600 $toolbar_html = $ilToolbar->getHTML();
601 if (!empty($toolbar_html)) {
602 $this->template->setCurrentBlock("toolbar_buttons");
603 $this->template->setVariable("BUTTONS", $toolbar_html);
604 $this->template->parseCurrentBlock();
605 }
606 }
607
608 protected function fillTabs(): void
609 {
610 if ($this->template->blockExists("tabs_outer_start")) {
611 $this->template->touchBlock("tabs_outer_start");
612 $this->template->touchBlock("tabs_outer_end");
613 $this->template->touchBlock("tabs_inner_start");
614 $this->template->touchBlock("tabs_inner_end");
615
616 if (null !== $this->tabs_html) {
617 $this->template->setVariable("TABS", $this->tabs_html);
618 }
619
620 if (null !== $this->sub_tabs_html) {
621 $this->template->setVariable("SUB_TABS", $this->sub_tabs_html);
622 }
623 }
624 }
625
626 protected function fillLightbox(): void
627 {
628 $this->template->setVariable('LIGHTBOX', implode('', $this->lightbox));
629 }
630}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setTitle(string $title, bool $is_hidden=false)
setAdminPanelBottom(bool $is_admin_panel_for_bottom)
setOnScreenMessage(string $type, string $message, bool $should_keep=false)
setAdminPanelArrow(bool $should_display_admin_panel_arrow)
addBlockFile(string $var, string $block, string $template_name, string $in_module=null)
parseCurrentBlock(string $block_name=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable(string $variable, string $value='')
setAdminPanelCommandsToolbar(ilToolbarGUI $admin_panel_commands_toolbar)
addLightbox(string $lightbox_html, string $id)
renderPage(string $part, bool $a_fill_tabs)
setCurrentBlock(string $block_name=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(string $file, bool $flag1, bool $flag2, string $in_module='', string $vars=ilGlobalTemplateInterface::DEFAULT_BLOCK, bool $plugin=false, bool $a_use_cache=true)
static _saveUsages()
Store the collected language variable usages in the user session This should be called as late as pos...
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static has($a_var)
Class for advanced editing exception handling in ILIAS.
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLeadingImage(string $a_img, string $a_alt)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripScriptHTML(string $a_str, string $a_allow="", bool $a_rm_js=true)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$lng
$message
Definition: xapiexit.php:32