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