ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilContainerRenderer.php
Go to the documentation of this file.
1<?php
2
21
28{
29 protected const UNIQUE_SEPARATOR = "-";
30 protected \ILIAS\Container\Content\ItemManager $item_manager;
32 protected ilObjUser $user;
33 protected \ILIAS\Containter\Content\ObjectiveRenderer $objective_renderer;
34 protected \ILIAS\Containter\Content\ItemRenderer $item_renderer;
35 protected \ILIAS\Container\Content\ItemPresentationManager $item_presentation;
36 protected bool $admin_panel;
37
38 protected ilLanguage $lng;
42
43 // switches
45 protected bool $enable_multi_download;
46 protected bool $active_block_ordering;
47
48 // properties
49 protected array $type_blocks = [];
50 protected array $custom_blocks = [];
51 protected array $items = [];
52 protected array $hidden_items = [];
53 protected array $block_items = [];
54 protected array $details = [];
55 protected array $item_ids = [];
56
57 // block (unique) ids
58 protected array $rendered_blocks = [];
59 protected int $bl_cnt = 0;
60
61 // ordering
62 protected array $block_pos = [];
63 protected array $block_custom_pos = [];
64 protected int $order_cnt = 0;
65
66 protected array $show_more = [];
67 protected int $view_mode;
68 protected \ILIAS\DI\UIServices $ui;
69 protected ilCtrl $ctrl;
70 protected ?Closure $block_prefix_closure = null;
71 protected ?Closure $block_postfix_closure = null;
72 protected ?Closure $item_hidden_closure = null;
73 protected ?Closure $item_modifier_closure = null;
74 protected \ILIAS\Container\Content\BlockSessionRepository $block_repo;
75
76 public function __construct(
77 \ILIAS\Container\Content\ItemPresentationManager $item_presentation,
78 bool $a_enable_manage_select_all = false,
79 bool $a_enable_multi_download = false,
80 bool $a_active_block_ordering = false,
81 array $a_block_custom_positions = [],
82 ?ilContainerGUI $container_gui_obj = null,
84 bool $admin_panel = false
85 ) {
86 global $DIC;
87
88 $this->item_presentation = $item_presentation;
89 $this->admin_panel = $admin_panel;
90 $this->lng = $DIC->language();
91 $this->settings = $DIC->settings();
92 $this->ui = $DIC->ui();
93 $this->obj_definition = $DIC["objDefinition"];
94 $this->enable_manage_select_all = $a_enable_manage_select_all;
95 $this->enable_multi_download = $a_enable_multi_download;
96 $this->active_block_ordering = $a_active_block_ordering;
97 $this->block_custom_pos = $a_block_custom_positions;
98 $this->view_mode = $a_view_mode;
100 $obj = $container_gui_obj;
101 $this->container_gui = $obj;
102 $this->ctrl = $DIC->ctrl();
103 $this->user = $DIC->user();
104 $this->access = $DIC->access();
105
106 $this->item_renderer = $DIC->container()
107 ->internal()
108 ->gui()
109 ->content()
110 ->itemRenderer(
111 $this->container_gui,
112 $a_view_mode
113 );
114 $this->objective_renderer = $DIC->container()
115 ->internal()
116 ->gui()
117 ->content()
118 ->objectiveRenderer(
119 $this->container_gui,
120 $a_view_mode,
121 clone $this
122 );
123 $this->block_repo = $DIC
124 ->container()
125 ->internal()
126 ->repo()
127 ->content()
128 ->block();
129 $this->item_manager = $DIC
130 ->container()
131 ->internal()
132 ->domain()
133 ->content()
134 ->items($this->container_gui->getObject());
135 }
136
137 public function setBlockPrefixClosure(Closure $f): void
138 {
139 $this->block_prefix_closure = $f;
140 }
141
142 public function setBlockPostfixClosure(Closure $f): void
143 {
144 $this->block_postfix_closure = $f;
145 }
146
147 public function setItemHiddenClosure(Closure $f): void
148 {
149 $this->item_hidden_closure = $f;
150 }
151
152 public function setItemModifierClosure(Closure $f): void
153 {
154 $this->item_renderer->setItemModifierClosure($f);
155 $this->item_modifier_closure = $f;
156 }
157
158 protected function getViewMode(): int
159 {
160 return $this->view_mode;
161 }
162
163 //
164 // blocks
165 //
166
167 public function addTypeBlock(
168 string $a_type,
169 ?string $a_prefix = null,
170 ?string $a_postfix = null
171 ): bool {
172 if ($a_type !== "itgr" &&
173 !$this->hasTypeBlock($a_type)) {
174 $this->type_blocks[$a_type] = [
175 "prefix" => $a_prefix
176 ,"postfix" => $a_postfix
177 ];
178 return true;
179 }
180 return false;
181 }
182
183 public function hasTypeBlock(string $a_type): bool
184 {
185 return array_key_exists($a_type, $this->type_blocks);
186 }
187
192 public function addCustomBlock(
193 $a_id,
194 string $a_caption,
195 ?string $a_actions = null,
196 array $a_data = []
197 ): bool {
198 if (!$this->hasCustomBlock($a_id)) {
199 $this->custom_blocks[$a_id] = [
200 "caption" => $a_caption
201 ,"actions" => $a_actions
202 ,"data" => $a_data
203 ];
204 return true;
205 }
206 return false;
207 }
208
213 public function hasCustomBlock($a_id): bool
214 {
215 return array_key_exists($a_id, $this->custom_blocks);
216 }
217
222 public function isValidBlock($a_id): bool
223 {
224 return ($this->hasTypeBlock($a_id) ||
225 $this->hasCustomBlock($a_id));
226 }
227
228
229 //
230 // items
231 //
232
238 public function hideItem($a_id): void
239 {
240 // see hasItem();
241 $this->hidden_items[$a_id] = true;
242
243 // #16629 - do not remove hidden items from other blocks
244 // $this->removeItem($a_id);
245 }
246
251 public function removeItem($a_id): void
252 {
253 if (!$this->hasItem($a_id)) {
254 return;
255 }
256
257 unset($this->item_ids[$a_id], $this->hidden_items[$a_id]);
258
259 foreach (array_keys($this->items) as $item_id) {
260 $parts = explode(self::UNIQUE_SEPARATOR, $item_id);
261 if (array_pop($parts) == $a_id) {
262 unset($this->items[$item_id]);
263 }
264 }
265
266 foreach ($this->block_items as $block_id => $items) {
267 foreach ($items as $idx => $item_id) {
268 $parts = explode(self::UNIQUE_SEPARATOR, $item_id);
269 if (array_pop($parts) == $a_id) {
270 unset($this->block_items[$block_id][$idx]);
271 if (!count($this->block_items[$block_id])) {
272 unset($this->block_items[$block_id]);
273 }
274 break;
275 }
276 }
277 }
278 }
279
285 public function hasItem($a_id): bool
286 {
287 return (array_key_exists($a_id, $this->item_ids) ||
288 array_key_exists($a_id, $this->hidden_items));
289 }
290
298 public function addItemToBlock(
299 $a_block_id,
300 string $a_item_type,
301 $a_item_id,
302 $a_item_html,
303 bool $a_force = false
304 ): bool {
305 if ($a_item_type !== "itgr" &&
306 $this->isValidBlock($a_block_id) &&
307 (!$this->hasItem($a_item_id) || $a_force)) {
308 if (is_string($a_item_html) && trim($a_item_html) === "") {
309 return false;
310 }
311 if (!$a_item_html) {
312 return false;
313 }
314
315
316 // #16563 - item_id (== ref_id) is NOT unique, adding parent block id
317 $uniq_id = $a_block_id . self::UNIQUE_SEPARATOR . $a_item_id;
318
319 $this->items[$uniq_id] = [
320 "type" => $a_item_type
321 ,"html" => $a_item_html
322 ];
323
324 // #18326
325 $this->addItemId($a_item_id);
326 $this->block_items[$a_block_id][] = $uniq_id;
327 return true;
328 }
329 return false;
330 }
331
335 public function addItemId($a_item_id): void
336 {
337 $this->item_ids[$a_item_id] = true;
338 }
339
344 public function addShowMoreButton($a_block_id): void
345 {
346 $this->show_more[] = $a_block_id;
347 }
348
349 public function addDetailsLevel(
350 int $a_level,
351 string $a_url,
352 bool $a_active = false
353 ): void {
354 $this->details[$a_level] = [
355 "url" => $a_url
356 ,"active" => $a_active
357 ];
358 }
359
360 public function resetDetails(): void
361 {
362 $this->details = [];
363 }
364
365
366 //
367 // render
368 //
369
373 public function setBlockPosition(
374 $a_block_id,
375 int $a_pos
376 ): void {
377 if ($this->isValidBlock($a_block_id)) {
378 $this->block_pos[$a_block_id] = $a_pos;
379 }
380 }
381
382 public function getHTML(): string
383 {
384 $valid = false;
385
386 $block_tpl = $this->initBlockTemplate();
387
388 foreach ($this->processBlockPositions() as $block_id) {
389 if (array_key_exists($block_id, $this->custom_blocks) && $this->renderHelperCustomBlock(
390 $block_tpl,
391 $block_id
392 )) {
393 $this->addSeparatorRow($block_tpl);
394 $valid = true;
395 }
396 if (array_key_exists($block_id, $this->type_blocks) && $this->renderHelperTypeBlock(
397 $block_tpl,
398 $block_id
399 )) {
400 $this->addSeparatorRow($block_tpl);
401 $valid = true;
402 }
403 }
404
405 if ($valid) {
406 $this->renderDetails($block_tpl);
407
408 return $block_tpl->get();
409 }
410 return "";
411 }
412
413 public function renderSingleTypeBlock(string $a_type, bool $exhausted = false): string
414 {
415 $block_tpl = $this->initBlockTemplate();
416 if ($this->renderHelperTypeBlock($block_tpl, $a_type, true, $exhausted)) {
417 return $block_tpl->get();
418 }
419 return "";
420 }
421
425 public function renderSingleCustomBlock($a_id): string
426 {
427 $block_tpl = $this->initBlockTemplate();
428
429 if ($this->renderHelperCustomBlock($block_tpl, $a_id, true)) {
430 return $block_tpl->get();
431 }
432 return "";
433 }
434
435
436 //
437 // render (helper)
438 //
439
440 protected function processBlockPositions(): array
441 {
442 // manual order
443 if (is_array($this->block_custom_pos) && count($this->block_custom_pos)) {
444 $tmp = $this->block_pos;
445 $this->block_pos = [];
446 foreach ($this->block_custom_pos as $idx => $block_id) {
447 if ($this->isValidBlock($block_id)) {
448 $this->block_pos[$block_id] = $idx;
449 }
450 }
451
452 // at least some manual are valid
453 if (count($this->block_pos)) {
454 // append missing blocks from default order
455 $last = max($this->block_pos);
456 foreach (array_keys($tmp) as $block_id) {
457 if (!array_key_exists($block_id, $this->block_pos)) {
458 $this->block_pos[$block_id] = ++$last;
459 }
460 }
461 }
462 // all manual invalid, use default
463 else {
464 $this->block_pos = $tmp;
465 }
466 }
467
468 // add missing blocks to order
469 $last = count($this->block_pos)
470 ? max($this->block_pos)
471 : 0;
472 foreach (array_keys($this->custom_blocks) as $block_id) {
473 if (!array_key_exists($block_id, $this->block_pos)) {
474 $this->block_pos[$block_id] = ++$last;
475 }
476 }
477 foreach (array_keys($this->type_blocks) as $block_id) {
478 if (!array_key_exists($block_id, $this->block_pos)) {
479 $this->block_pos[$block_id] = ++$last;
480 }
481 }
482
483 asort($this->block_pos);
484 return array_keys($this->block_pos);
485 }
486
490 protected function renderHelperCustomBlock(
491 ilTemplate $a_block_tpl,
492 $a_block_id,
493 bool $a_is_single = false,
494 bool $is_exhausted = false
495 ): bool {
496 if ($this->hasCustomBlock($a_block_id)) {
497 return $this->renderHelperGeneric($a_block_tpl, $a_block_id, $this->custom_blocks[$a_block_id], $a_is_single, $is_exhausted);
498 }
499 return false;
500 }
501
502 protected function renderHelperTypeBlock(
503 ilTemplate $a_block_tpl,
504 string $a_type,
505 bool $a_is_single = false,
506 bool $is_exhausted = false
507 ): bool {
508 if ($this->hasTypeBlock($a_type)) {
509 $block = $this->type_blocks[$a_type];
510 $block["type"] = $a_type;
511 return $this->renderHelperGeneric($a_block_tpl, $a_type, $block, $a_is_single, $is_exhausted);
512 }
513 return false;
514 }
515
516 protected function getViewModeOfItemGroup(int $ref_id): int
517 {
518 $item_group = new ilObjItemGroup($ref_id);
520 if ($item_group->getListPresentation() !== "") {
521 $view_mode = ($item_group->getListPresentation() === "tile")
524 }
525 return $view_mode;
526 }
527
528 protected function getListPresentationOfItemGroup(int $ref_id): string
529 {
530 $item_group = new ilObjItemGroup($ref_id);
531 return $item_group->getListPresentation();
532 }
533
537 protected function renderHelperGeneric(
538 ilTemplate $a_block_tpl,
539 $a_block_id,
540 array $a_block,
541 bool $a_is_single = false,
542 bool $is_exhausted = false
543 ): bool {
544 $ctrl = $this->ctrl;
545 if (!in_array($a_block_id, $this->rendered_blocks)) {
546 $this->rendered_blocks[] = $a_block_id;
547 $block_types = [];
548 if (isset($this->block_items[$a_block_id]) && is_array($this->block_items[$a_block_id])) {
549 foreach ($this->block_items[$a_block_id] as $item_id) {
550 if (isset($this->items[$item_id]["type"])) {
551 $block_types[] = $this->items[$item_id]["type"];
552 }
553 }
554 }
555
556 // determine view mode and tile size
557 $tile_size = ilContainer::TILE_SMALL;
558 $view_mode = $this->getViewMode();
559 if ($view_mode === ilContainerContentGUI::VIEW_MODE_TILE) {
560 $tile_size = ilContainer::_lookupContainerSetting($this->container_gui->getObject()->getId(), "tile_size");
561 }
562 if (is_numeric($a_block_id)) {
563 $item_group = new ilObjItemGroup($a_block_id);
564 if ($item_group->getListPresentation() !== "") {
565 $view_mode = ($item_group->getListPresentation() === "tile" && !$this->active_block_ordering && !$this->admin_panel)
568 $tile_size = $item_group->getTileSize();
569 }
570 }
571
572
573 // #14610 - manage empty item groups
574 if ((isset($this->block_items[$a_block_id]) && is_array($this->block_items[$a_block_id])) ||
575 is_numeric($a_block_id)) {
576 $cards = [];
577
578 $order_id = (!$a_is_single && $this->active_block_ordering)
579 ? $a_block_id
580 : "";
581 $this->addHeaderRow(
582 $a_block_tpl,
583 $a_block["type"] ?? '',
584 $a_block["caption"] ?? '',
585 array_unique($block_types),
586 $a_block["actions"] ?? '',
587 $order_id,
588 $a_block["data"] ?? []
589 );
590
591 if ($view_mode === ilContainerContentGUI::VIEW_MODE_LIST) {
592 if (isset($a_block["prefix"]) && $a_block["prefix"]) {
593 $this->addStandardRow($a_block_tpl, $a_block["prefix"]);
594 }
595 }
596
597 if (isset($this->block_items[$a_block_id])) {
598 foreach ($this->block_items[$a_block_id] as $item_id) {
599 if ($view_mode === ilContainerContentGUI::VIEW_MODE_LIST) {
600 $this->addStandardRow($a_block_tpl, $this->items[$item_id]["html"], $item_id);
601 } else {
602 $cards[] = $this->items[$item_id]["html"];
603 }
604 }
605 }
606
607 if ($view_mode === ilContainerContentGUI::VIEW_MODE_LIST) {
608 if (isset($a_block["postfix"]) && $a_block["postfix"]) {
609 $this->addStandardRow($a_block_tpl, $a_block["postfix"]);
610 }
611 }
612
613 if ($view_mode === ilContainerContentGUI::VIEW_MODE_TILE) {
614 $f = $this->ui->factory();
615 $renderer = $this->ui->renderer();
616
617 //Create a deck with large cards
618 switch ($tile_size) {
620 $deck = $f->deck($cards)->withSmallCardsSize();
621 break;
622
624 $deck = $f->deck($cards)->withLargeCardsSize();
625 break;
626
628 $deck = $f->deck($cards)->withExtraLargeCardsSize();
629 break;
630
632 $deck = $f->deck($cards)->withFullSizedCardsSize();
633 break;
634
635 default:
636 $deck = $f->deck($cards)->withNormalCardsSize();
637 break;
638 }
639
640 $html = $renderer->render($deck);
641 $a_block_tpl->setCurrentBlock("tile_rows");
642 $a_block_tpl->setVariable("TILE_ROWS", $html);
643 $a_block_tpl->parseCurrentBlock();
644 }
645 // show more
646 if ($is_exhausted) {
647 $a_block_tpl->setCurrentBlock("show_more");
648
649 $ctrl->setParameter($this->container_gui, "type", $a_block_id);
650 $url = $ctrl->getLinkTarget($this->container_gui, "renderBlockAsynch", "", true);
651 $ctrl->setParameter($this->container_gui, "type", "");
652
653 $f = $this->ui->factory();
654 $renderer = $this->ui->renderer();
655 $button = $f->button()->standard($this->lng->txt("cont_show_more"), "")
656 ->withLoadingAnimationOnClick(true)
657 ->withOnLoadCode(function ($id) use ($a_block_id, $url) {
658 return "il.Container.initShowMore('$id', '$a_block_id', '" . $url . "');";
659 });
660 if ($ctrl->isAsynch()) {
661 $a_block_tpl->setVariable("SHOW_MORE_BUTTON", $renderer->renderAsync($button));
662 } else {
663 $a_block_tpl->setVariable("SHOW_MORE_BUTTON", $renderer->render($button));
664 }
665 $a_block_tpl->parseCurrentBlock();
666 $a_block_tpl->setCurrentBlock("show_more");
667 $a_block_tpl->parseCurrentBlock();
668 }
669
670 return true;
671 }
672 }
673
674 return false;
675 }
676
677 protected function initBlockTemplate(): ilTemplate
678 {
679 return new ilTemplate("tpl.container_list_block.html", true, true, "components/ILIAS/Container");
680 }
681
687 protected function addHeaderRow(
688 ilTemplate $a_tpl,
689 string $a_type = "",
690 string $a_text = "",
691 ?array $a_types_in_block = null,
692 string $a_commands_html = "",
693 string $a_order_id = "",
694 array $a_data = []
695 ): void {
696 $lng = $this->lng;
697 $ilSetting = $this->settings;
698 $objDefinition = $this->obj_definition;
699
700 $a_tpl->setVariable("CB_ID", ' id="bl_cntr_' . (++$this->bl_cnt) . '"');
701
702 if ($this->enable_manage_select_all) {
703 $this->renderSelectAllBlock($a_tpl);
704 } elseif ($this->enable_multi_download) {
705 if ($a_type) {
706 $a_types_in_block = [$a_type];
707 }
708 foreach ($a_types_in_block as $type) {
709 if (in_array($type, $this->getDownloadableTypes(), true)) {
710 $this->renderSelectAllBlock($a_tpl);
711 break;
712 }
713 }
714 }
715
716 if ($a_text === "" && $a_type !== "") {
717 if (!$objDefinition->isPlugin($a_type)) {
718 $title = $lng->txt("objs_" . $a_type);
719 } else {
721 $title = $pl->txt("objs_" . $a_type);
722 }
723 } else {
724 $title = $a_text;
725 }
726
727 if (is_array($a_data)) {
728 foreach ($a_data as $k => $v) {
729 $a_tpl->setCurrentBlock("cb_data");
730 $a_tpl->setVariable("DATA_KEY", $k);
731 $a_tpl->setVariable("DATA_VALUE", $v);
732 $a_tpl->parseCurrentBlock();
733
734 if ($k === "behaviour" && $v == ilItemGroupBehaviour::EXPANDABLE_CLOSED) {
735 $a_tpl->touchBlock("container_items_hide");
736 }
737 }
738 }
739
740 if ($a_type !== "" && $ilSetting->get("icon_position_in_lists") !== "item_rows") {
741 $icon = ilUtil::getImagePath("standard/icon_" . $a_type . ".svg");
742
743 $a_tpl->setCurrentBlock("container_header_row_image");
744 $a_tpl->setVariable("HEADER_IMG", $icon);
745 $a_tpl->setVariable("HEADER_ALT", $title);
746 } else {
747 $a_tpl->setCurrentBlock("container_header_row");
748 }
749
750 if ($a_order_id !== "") {
751 /* blocks are ordered in page editor
752 $a_tpl->setVariable("BLOCK_HEADER_ORDER_NAME", "position[blocks][" . $a_order_id . "]");
753 $a_tpl->setVariable("BLOCK_HEADER_ORDER_NUM", (++$this->order_cnt) * 10);
754 */
755 }
756
757 $presentation_title = $title;
758 $sr_only = "";
759 if (trim($title) === "") {
760 $presentation_title = $this->lng->txt("cont_no_title");
761 $sr_only = "sr-only";
762 }
763 $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $presentation_title);
764 $a_tpl->setVariable("SR_ONLY", $sr_only);
765 $a_tpl->setVariable("CHR_COMMANDS", $a_commands_html);
766 $a_tpl->parseCurrentBlock();
767 }
768
769 protected function addStandardRow(
770 ilTemplate $a_tpl,
771 string $a_html,
772 ?string $a_item_id = null
773 ): void {
774 if ($a_item_id) {
775 $a_tpl->setCurrentBlock("row");
776 $a_tpl->setVariable("ROW_ID", 'id="item_row_' . $a_item_id . '"');
777 $a_tpl->parseCurrentBlock();
778 } else {
779 $a_tpl->touchBlock("row");
780 }
781
782 $a_tpl->setCurrentBlock("container_standard_row");
783 $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
784 $a_tpl->parseCurrentBlock();
785
786 $a_tpl->touchBlock("container_row");
787 }
788
792 protected function renderSelectAllBlock(ilTemplate $a_tpl): void
793 {
795
796 $a_tpl->setCurrentBlock("select_all_row");
797 $a_tpl->setVariable("CHECKBOXNAME", "bl_cb_" . $this->bl_cnt);
798 $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_" . $this->bl_cnt);
799 $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_" . $this->bl_cnt);
800 $a_tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
801 $a_tpl->parseCurrentBlock();
802 }
803
804 protected function addSeparatorRow(ilTemplate $a_tpl): void
805 {
806 $a_tpl->setCurrentBlock("container_block");
807 $a_tpl->parseCurrentBlock();
808 }
809
813 protected function getDownloadableTypes(): array
814 {
815 return ["fold", "file"];
816 }
817
818 public function renderDetails(ilTemplate $a_tpl): void
819 {
821
822 if (count($this->details)) {
823 $a_tpl->setCurrentBlock('container_details_row');
824 $a_tpl->setVariable('TXT_DETAILS', $lng->txt('details'));
825 $a_tpl->parseCurrentBlock();
826 }
827 }
828
832
833 public function getItemRenderer(): \ILIAS\Containter\Content\ItemRenderer
834 {
835 return $this->item_renderer;
836 }
837
838 protected function renderContainerPage(): string
839 {
840 return $this->container_gui->getContainerPageHTML();
841 }
842
843 protected function getDetailsLevel(int $a_item_id): int
844 {
845 if ($this->container_gui->isActiveAdministrationPanel()) {
847 }
848 if ($this->item_manager->getExpanded($a_item_id) !== null) {
849 return $this->item_manager->getExpanded($a_item_id);
850 }
851 /*if ($a_item_id === $this->force_details) {
852 return ilContainerContentGUI::DETAILS_ALL;
853 }*/
855 }
856
857 public function renderItemBlockSequence(
858 ItemBlockSequence $sequence
859 ): string {
860 $valid = false;
861
862 $page_html = $this->renderContainerPage();
863 $block_tpl = $this->initBlockTemplate();
864
866 foreach ($this->item_presentation->getAllRefIds() as $ref_id) {
867 $rd = $this->item_presentation->getRawDataByRefId($ref_id);
868 $preloader->addItem($rd["obj_id"], $rd["type"], $ref_id);
869 if ($rd["type"] === "sess") {
870 $ev_items = ilObjectActivation::getItemsByEvent((int) $rd["obj_id"]);
871 foreach ($ev_items as $ev_item) {
872 $preloader->addItem((int) $ev_item["obj_id"], $ev_item["type"], $ev_item["ref_id"]);
873 }
874 }
875 }
876 $preloader->preload();
877
878 $embedded_block_ids = $this->item_presentation->getPageEmbeddedBlockIds();
879 foreach ($sequence->getBlocks() as $block) {
880 $block_id = "";
881 $force_item_even_if_already_rendered = false;
882 if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
883 $block_id = (string) $block->getBlock()->getRefId();
884 $force_item_even_if_already_rendered = true;
885 }
886 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock) {
887 $block_id = $block->getBlock()->getType();
888 if ($block->getPageEmbedded()) {
889 $force_item_even_if_already_rendered = true;
890 }
891 }
892 if ($block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
893 $block_id = "sess";
894 }
895 if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
896 $block_id = "_other";
897 }
898 if ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
899 $block_id = "_lobj";
900 }
901
902 $position = 1;
903 $pos_prefix = "";
904
905 // (1) add block
906 if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
907 $this->addItemGroupBlock($block_id);
908 $pos_prefix = "[itgr][" . \ilObject::_lookupObjId($block->getBlock()->getRefId()) . "]";
909 }
910 if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
911 $title = $this->item_presentation->filteredSubtree()
912 ? $this->lng->txt("cont_found_objects")
913 : $this->lng->txt("content");
914 $this->addCustomBlock($block_id, $title);
915 }
916 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
917 $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
918 $this->addTypeBlock(
919 $block_id,
920 $this->getBlockPrefix($block_id),
921 $this->getBlockPostfix($block_id)
922 );
923 }
924
925 // (2) render and add items
926 foreach ($block->getItemRefIds() as $ref_id) {
927 if ($this->isItemHidden($block_id, $ref_id)) {
928 continue;
929 }
930 if (!$this->access->checkAccess('visible', '', $ref_id)) {
931 continue;
932 }
933
934 $item_data = $this->item_presentation->getRawDataByRefId($ref_id);
935 if ($item_data === null) {
936 continue;
937 }
939 if ($this->container_gui->isActiveAdministrationPanel()) {
941 } elseif ($this->container_gui->isMultiDownloadEnabled()) {
943 }
944 $item_group_list_presentation = "";
945 if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
946 if ($this->getListPresentationOfItemGroup((int) $block_id) === "tile") {
947 if (!$this->admin_panel && !$this->active_block_ordering) {
948 $item_group_list_presentation = "tile";
949 }
950 }
951 if ($this->getListPresentationOfItemGroup((int) $block_id) === "list") {
952 if (!$this->admin_panel && !$this->active_block_ordering) {
953 $item_group_list_presentation = "list";
954 }
955 }
956 }
957 $html = $this->item_renderer->renderItem(
958 $item_data,
959 $position++,
960 false,
961 $pos_prefix,
962 $item_group_list_presentation,
963 $checkbox,
964 $this->item_presentation->isActiveItemOrdering($item_data["type"]),
965 $this->getDetailsLevel($item_data["obj_id"])
966 );
967 if ($html != "") {
968 $this->addItemToBlock(
969 $block_id,
970 $item_data["type"],
971 $item_data["child"],
972 $html,
973 $force_item_even_if_already_rendered
974 );
975 }
976 }
977
978 // (3) render blocks
979 if ($block->getPageEmbedded()) {
980 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
981 $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
982 $page_html = preg_replace(
983 '~\[list-' . $block->getId() . '\]~i',
984 $this->renderSingleTypeBlock($block->getId(), $block->getLimitExhausted()),
985 $page_html
986 );
987 $valid = true;
988 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
989 $page_html = preg_replace(
990 '~\[item-group-' . $block->getId() . '\]~i',
991 $this->renderSingleCustomBlock((int) $block->getId()),
992 $page_html
993 );
994 $valid = true;
995 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
996 $page_html = preg_replace(
997 '~\[list-_other\]~i',
998 $this->renderSingleCustomBlock($block->getId()),
999 $page_html
1000 );
1001 $valid = true;
1002 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
1003 $page_html = preg_replace(
1004 '~\[list-_lobj\]~i',
1005 $this->objective_renderer->renderObjectives(),
1006 $page_html
1007 );
1008 $valid = true;
1009 }
1010 } else {
1011 if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock ||
1012 $block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
1013 if ($this->renderHelperCustomBlock($block_tpl, $block_id, false, $block->getLimitExhausted())) {
1014 $this->addSeparatorRow($block_tpl);
1015 $valid = true;
1016 }
1017 }
1018 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
1019 $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
1020 if ($this->renderHelperTypeBlock($block_tpl, $block_id, false, $block->getLimitExhausted())) {
1021 $this->addSeparatorRow($block_tpl);
1022 $valid = true;
1023 }
1024 }
1025 if ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
1026 $this->objective_renderer->renderObjectives();
1027 $block_tpl->setVariable(
1028 "CONTENT",
1029 $this->objective_renderer->getContent()
1030 );
1031 $this->addSeparatorRow($block_tpl);
1032 $valid = true;
1033 }
1034 }
1035 }
1036
1037 // remove embedded, but unrendered blocks
1038 foreach ($this->item_presentation->getPageEmbeddedBlockIds() as $id) {
1039 if (is_numeric($id)) {
1040 $page_html = preg_replace(
1041 '~\[item-group-' . $id . '\]~i',
1042 "",
1043 $page_html
1044 );
1045 } else {
1046 $page_html = preg_replace(
1047 '~\[list-' . $id . '\]~i',
1048 "",
1049 $page_html
1050 );
1051 }
1052 }
1053
1054 if ($valid) {
1055 $this->renderDetails($block_tpl);
1056 return $page_html . $block_tpl->get();
1057 }
1058 return $page_html;
1059 }
1060
1062 ItemBlockSequence $sequence,
1063 string $block_id,
1064 array $already_rendered_items,
1065 int $block_limit
1066 ): string {
1067
1068 $block = $this->getBlockById($sequence, $block_id);
1069 // get all sub items
1070 //$this->items = $this->getContainerObject()->getSubItems(
1071 // $this->getContainerGUI()->isActiveAdministrationPanel()
1072 //);
1073 $exhausted = false;
1074 $ref_ids = $already_rendered_items;
1075
1076 // iterate all types
1077 if (!is_null($block) && count($block->getItemRefIds()) > 0) {
1078
1079 $this->addTypeBlock($block_id);
1080 //$this->renderer->setBlockPosition($type, ++$pos);
1081
1082 $position = 1;
1083 $counter = 1;
1084 foreach ($block->getItemRefIds() as $item_ref_id) {
1085 $item_data = $this->item_presentation->getRawDataByRefId($item_ref_id);
1086 if (in_array($item_ref_id, $ref_ids)) {
1087 continue;
1088 }
1089
1091 if ($this->container_gui->isActiveAdministrationPanel()) {
1093 } elseif ($this->container_gui->isMultiDownloadEnabled()) {
1095 }
1096 if (!$this->hasItem($item_ref_id)) {
1097 $html = $this->item_renderer->renderItem(
1098 $item_data,
1099 $position++,
1100 false,
1101 "",
1102 "",
1103 $checkbox,
1104 $this->item_presentation->isActiveItemOrdering($item_data["type"]),
1105 );
1106 if ($html != "") {
1107 $this->addItemToBlock($block_id, $item_data["type"], $item_ref_id, $html);
1108 }
1109 }
1110
1111 if ($block_limit > 0 && $html != "" && $block->getLimitExhausted()) {
1112 $this->addShowMoreButton($block_id);
1113 $exhausted = true;
1114 }
1115 }
1116 }
1117
1118 return $this->renderSingleTypeBlock($block_id, $exhausted);
1119 }
1120
1121 public function getBlockById(
1122 ItemBlockSequence $sequence,
1123 string $block_id,
1124 ): ?ItemBlock {
1125 foreach ($sequence->getBlocks() as $block) {
1126 if ($block->getId() === $block_id) {
1127 return $block;
1128 }
1129 }
1130 return null;
1131 }
1132
1136 protected function addItemGroupBlock(string $block_id, int $block_pos = 0): void
1137 {
1138 $item_data = $this->item_presentation->getRawDataByRefId((int) $block_id);
1139 $item_list_gui = $this->item_renderer->getItemGUI($item_data);
1140
1141 $perm_ok = true;
1142 /*
1143 $ilAccess = $this->access;
1144 $ilUser = $this->user;
1145
1146 // #16493
1147 $perm_ok = ($ilAccess->checkAccess("visible", "", $item_data['ref_id']) &&
1148 $ilAccess->checkAccess("read", "", $item_data['ref_id']));
1149
1150 $items = ilObjectActivation::getItemsByItemGroup($item_data['ref_id']);
1151
1152 // get all valid ids (this is filtered)
1153 $all_ids = array_map(static function (array $i) : int {
1154 return (int) $i["child"];
1155 }, $this->items["_all"]);
1156
1157 // remove filtered items
1158 $items = array_filter($items, static function (array $i) use ($all_ids) : bool {
1159 return in_array($i["ref_id"], $all_ids);
1160 });
1161
1162 // if no permission is given, set the items to "rendered" but
1163 // do not display the whole block
1164 if (!$perm_ok) {
1165 foreach ($items as $item) {
1166 $this->renderer->hideItem($item["child"]);
1167 }
1168 return;
1169 }
1170 */
1171
1172 $item_list_gui->enableNotes(false);
1173 $item_list_gui->enableTags(false);
1174 $item_list_gui->enableComments(false);
1175 $item_list_gui->enableTimings(false);
1176 $item_list_gui->initItem(
1177 (int) $item_data["ref_id"],
1178 (int) $item_data["obj_id"],
1179 "itgr",
1180 $item_data["title"],
1181 $item_data["description"]
1182 );
1183 $commands_html = $item_list_gui->getCommandsHTML();
1184
1185 // determine behaviour
1186 $item_group = new ilObjItemGroup($item_data["ref_id"]);
1187 $beh = $item_group->getBehaviour();
1188 $stored_val = $this->block_repo->getProperty(
1189 "itgr_" . $item_data["ref_id"],
1190 $this->user->getId(),
1191 "opened"
1192 );
1193 if ($stored_val !== "" && $beh !== ilItemGroupBehaviour::ALWAYS_OPEN) {
1194 $beh = ($stored_val === "1")
1197 }
1198
1199 $data = [
1200 "behaviour" => $beh,
1201 "store-url" => "./ilias.php?baseClass=ilcontainerblockpropertiesstoragegui&cmd=store" .
1202 "&cont_block_id=itgr_" . $item_data['ref_id']
1203 ];
1204 if (ilObjItemGroup::lookupHideTitle($item_data["obj_id"]) &&
1205 !$this->container_gui->isActiveAdministrationPanel()) {
1206 $this->addCustomBlock($block_id, "", $commands_html, $data);
1207 } else {
1208 $this->addCustomBlock($block_id, $item_data["title"], $commands_html, $data);
1209 }
1210 }
1211
1212 protected function getBlockPrefix($block_id): string
1213 {
1214 if ($this->block_prefix_closure instanceof Closure) {
1215 $c = $this->block_prefix_closure;
1216 return (string) $c($block_id);
1217 }
1218 return "";
1219 }
1220
1221 protected function getBlockPostfix($block_id): string
1222 {
1223 if ($this->block_postfix_closure instanceof Closure) {
1224 $c = $this->block_postfix_closure;
1225 return (string) $c($block_id);
1226 }
1227 return "";
1228 }
1229
1230 protected function isItemHidden(string $block_id, int $ref_id): bool
1231 {
1232 if ($this->item_hidden_closure instanceof Closure) {
1233 $c = $this->item_hidden_closure;
1234 return (bool) $c($block_id, $ref_id);
1235 }
1236 return false;
1237 }
1238
1239}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$renderer
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder,...
Class ilContainerRenderer.
ILIAS Container Content ItemPresentationManager $item_presentation
addDetailsLevel(int $a_level, string $a_url, bool $a_active=false)
renderSingleTypeBlock(string $a_type, bool $exhausted=false)
removeItem($a_id)
Remove item (from any block)
getDownloadableTypes()
Get downloadable repository object types.
addTypeBlock(string $a_type, ?string $a_prefix=null, ?string $a_postfix=null)
getItemRenderer()
Render Item Block Sequence.
ILIAS Containter Content ItemRenderer $item_renderer
renderHelperTypeBlock(ilTemplate $a_block_tpl, string $a_type, bool $a_is_single=false, bool $is_exhausted=false)
addItemGroupBlock(string $block_id, int $block_pos=0)
replaces ilContainerContentGUI::renderItemGroup
renderItemBlockSequence(ItemBlockSequence $sequence)
addCustomBlock( $a_id, string $a_caption, ?string $a_actions=null, array $a_data=[])
Add custom block.
addItemToBlock( $a_block_id, string $a_item_type, $a_item_id, $a_item_html, bool $a_force=false)
Add item to existing block.
hideItem($a_id)
Mark item id as used, but do not render.
setBlockPosition( $a_block_id, int $a_pos)
hasCustomBlock($a_id)
Custom block already exists?
ILIAS Container Content BlockSessionRepository $block_repo
renderSingleTypeBlockAsynch(ItemBlockSequence $sequence, string $block_id, array $already_rendered_items, int $block_limit)
addShowMoreButton($a_block_id)
Add show more button to a block.
addHeaderRow(ilTemplate $a_tpl, string $a_type="", string $a_text="", ?array $a_types_in_block=null, string $a_commands_html="", string $a_order_id="", array $a_data=[])
Render block header.
renderHelperCustomBlock(ilTemplate $a_block_tpl, $a_block_id, bool $a_is_single=false, bool $is_exhausted=false)
ILIAS Container Content ItemManager $item_manager
hasItem($a_id)
Item with id exists?
renderSelectAllBlock(ilTemplate $a_tpl)
Render "select all".
ILIAS Containter Content ObjectiveRenderer $objective_renderer
addSeparatorRow(ilTemplate $a_tpl)
renderDetails(ilTemplate $a_tpl)
isItemHidden(string $block_id, int $ref_id)
addStandardRow(ilTemplate $a_tpl, string $a_html, ?string $a_item_id=null)
getBlockById(ItemBlockSequence $sequence, string $block_id,)
isValidBlock($a_id)
Any block with id exists?
ilObjectDefinition $obj_definition
renderHelperGeneric(ilTemplate $a_block_tpl, $a_block_id, array $a_block, bool $a_is_single=false, bool $is_exhausted=false)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
Class ilCtrl provides processing control methods.
language handling
Class ilObjItemGroup.
static lookupHideTitle(int $a_id)
User class.
static getItemsByEvent(int $event_id)
Get session material / event items.
parses the objects.xml it handles the xml-description of all ilias objects
Preloader for object list GUIs.
static getPluginObjectByType(string $type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin.
static _lookupObjId(int $ref_id)
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$c
Definition: deliver.php:25
$valid
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:70
$counter