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