ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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;
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  $html = $renderer->render($deck);
638  $a_block_tpl->setCurrentBlock("tile_rows");
639  $a_block_tpl->setVariable("TILE_ROWS", $html);
640  $a_block_tpl->parseCurrentBlock();
641  }
642  // show more
643  if ($is_exhausted) {
644  $a_block_tpl->setCurrentBlock("show_more");
645 
646  $ctrl->setParameter($this->container_gui, "type", $a_block_id);
647  $url = $ctrl->getLinkTarget($this->container_gui, "renderBlockAsynch", "", true);
648  $ctrl->setParameter($this->container_gui, "type", "");
649 
650  $f = $this->ui->factory();
651  $renderer = $this->ui->renderer();
652  $button = $f->button()->standard($this->lng->txt("cont_show_more"), "")
654  ->withOnLoadCode(function ($id) use ($a_block_id, $url) {
655  return "il.Container.initShowMore('$id', '$a_block_id', '" . $url . "');";
656  });
657  if ($ctrl->isAsynch()) {
658  $a_block_tpl->setVariable("SHOW_MORE_BUTTON", $renderer->renderAsync($button));
659  } else {
660  $a_block_tpl->setVariable("SHOW_MORE_BUTTON", $renderer->render($button));
661  }
662  $a_block_tpl->parseCurrentBlock();
663  $a_block_tpl->setCurrentBlock("show_more");
664  $a_block_tpl->parseCurrentBlock();
665  }
666 
667  return true;
668  }
669  }
670 
671  return false;
672  }
673 
674  protected function initBlockTemplate(): ilTemplate
675  {
676  return new ilTemplate("tpl.container_list_block.html", true, true, "components/ILIAS/Container");
677  }
678 
684  protected function addHeaderRow(
685  ilTemplate $a_tpl,
686  string $a_type = "",
687  string $a_text = "",
688  ?array $a_types_in_block = null,
689  string $a_commands_html = "",
690  string $a_order_id = "",
691  array $a_data = []
692  ): void {
693  $lng = $this->lng;
695  $objDefinition = $this->obj_definition;
696 
697  $a_tpl->setVariable("CB_ID", ' id="bl_cntr_' . (++$this->bl_cnt) . '"');
698 
699  if ($this->enable_manage_select_all) {
700  $this->renderSelectAllBlock($a_tpl);
701  } elseif ($this->enable_multi_download) {
702  if ($a_type) {
703  $a_types_in_block = [$a_type];
704  }
705  foreach ($a_types_in_block as $type) {
706  if (in_array($type, $this->getDownloadableTypes(), true)) {
707  $this->renderSelectAllBlock($a_tpl);
708  break;
709  }
710  }
711  }
712 
713  if ($a_text === "" && $a_type !== "") {
714  if (!$objDefinition->isPlugin($a_type)) {
715  $title = $lng->txt("objs_" . $a_type);
716  } else {
718  $title = $pl->txt("objs_" . $a_type);
719  }
720  } else {
721  $title = $a_text;
722  }
723 
724  if (is_array($a_data)) {
725  foreach ($a_data as $k => $v) {
726  $a_tpl->setCurrentBlock("cb_data");
727  $a_tpl->setVariable("DATA_KEY", $k);
728  $a_tpl->setVariable("DATA_VALUE", $v);
729  $a_tpl->parseCurrentBlock();
730 
731  if ($k === "behaviour" && $v == ilItemGroupBehaviour::EXPANDABLE_CLOSED) {
732  $a_tpl->touchBlock("container_items_hide");
733  }
734  }
735  }
736 
737  if ($a_type !== "" && $ilSetting->get("icon_position_in_lists") !== "item_rows") {
738  $icon = ilUtil::getImagePath("standard/icon_" . $a_type . ".svg");
739 
740  $a_tpl->setCurrentBlock("container_header_row_image");
741  $a_tpl->setVariable("HEADER_IMG", $icon);
742  $a_tpl->setVariable("HEADER_ALT", $title);
743  } else {
744  $a_tpl->setCurrentBlock("container_header_row");
745  }
746 
747  if ($a_order_id !== "") {
748  /* blocks are ordered in page editor
749  $a_tpl->setVariable("BLOCK_HEADER_ORDER_NAME", "position[blocks][" . $a_order_id . "]");
750  $a_tpl->setVariable("BLOCK_HEADER_ORDER_NUM", (++$this->order_cnt) * 10);
751  */
752  }
753 
754  $presentation_title = $title;
755  $sr_only = "";
756  if (trim($title) === "") {
757  $presentation_title = $this->lng->txt("cont_no_title");
758  $sr_only = "sr-only";
759  }
760  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $presentation_title);
761  $a_tpl->setVariable("SR_ONLY", $sr_only);
762  $a_tpl->setVariable("CHR_COMMANDS", $a_commands_html);
763  $a_tpl->parseCurrentBlock();
764  }
765 
766  protected function addStandardRow(
767  ilTemplate $a_tpl,
768  string $a_html,
769  string $a_item_id = null
770  ): void {
771  if ($a_item_id) {
772  $a_tpl->setCurrentBlock("row");
773  $a_tpl->setVariable("ROW_ID", 'id="item_row_' . $a_item_id . '"');
774  $a_tpl->parseCurrentBlock();
775  } else {
776  $a_tpl->touchBlock("row");
777  }
778 
779  $a_tpl->setCurrentBlock("container_standard_row");
780  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
781  $a_tpl->parseCurrentBlock();
782 
783  $a_tpl->touchBlock("container_row");
784  }
785 
789  protected function renderSelectAllBlock(ilTemplate $a_tpl): void
790  {
791  $lng = $this->lng;
792 
793  $a_tpl->setCurrentBlock("select_all_row");
794  $a_tpl->setVariable("CHECKBOXNAME", "bl_cb_" . $this->bl_cnt);
795  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_" . $this->bl_cnt);
796  $a_tpl->setVariable("SEL_ALL_PARENT", "bl_cntr_" . $this->bl_cnt);
797  $a_tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
798  $a_tpl->parseCurrentBlock();
799  }
800 
801  protected function addSeparatorRow(ilTemplate $a_tpl): void
802  {
803  $a_tpl->setCurrentBlock("container_block");
804  $a_tpl->parseCurrentBlock();
805  }
806 
810  protected function getDownloadableTypes(): array
811  {
812  return ["fold", "file"];
813  }
814 
815  public function renderDetails(ilTemplate $a_tpl): void
816  {
817  $lng = $this->lng;
818 
819  if (count($this->details)) {
820  $a_tpl->setCurrentBlock('container_details_row');
821  $a_tpl->setVariable('TXT_DETAILS', $lng->txt('details'));
822  $a_tpl->parseCurrentBlock();
823  }
824  }
825 
829 
830  public function getItemRenderer(): \ILIAS\Containter\Content\ItemRenderer
831  {
832  return $this->item_renderer;
833  }
834 
835  protected function renderContainerPage(): string
836  {
837  return $this->container_gui->getContainerPageHTML();
838  }
839 
840  protected function getDetailsLevel(int $a_item_id): int
841  {
842  if ($this->container_gui->isActiveAdministrationPanel()) {
844  }
845  if ($this->item_manager->getExpanded($a_item_id) !== null) {
846  return $this->item_manager->getExpanded($a_item_id);
847  }
848  /*if ($a_item_id === $this->force_details) {
849  return ilContainerContentGUI::DETAILS_ALL;
850  }*/
852  }
853 
854  public function renderItemBlockSequence(
855  \ILIAS\Container\Content\ItemBlock\ItemBlockSequence $sequence
856  ): string {
857  $valid = false;
858 
859  $page_html = $this->renderContainerPage();
860  $block_tpl = $this->initBlockTemplate();
861 
863  foreach ($this->item_presentation->getAllRefIds() as $ref_id) {
864  $rd = $this->item_presentation->getRawDataByRefId($ref_id);
865  $preloader->addItem($rd["obj_id"], $rd["type"], $ref_id);
866  if ($rd["type"] === "sess") {
867  $ev_items = ilObjectActivation::getItemsByEvent((int) $rd["obj_id"]);
868  foreach ($ev_items as $ev_item) {
869  $preloader->addItem((int) $ev_item["obj_id"], $ev_item["type"], $ev_item["ref_id"]);
870  }
871  }
872  }
873  $preloader->preload();
874 
875  $embedded_block_ids = $this->item_presentation->getPageEmbeddedBlockIds();
876  foreach ($sequence->getBlocks() as $block) {
877  $block_id = "";
878  $force_item_even_if_already_rendered = false;
879  if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
880  $block_id = (string) $block->getBlock()->getRefId();
881  $force_item_even_if_already_rendered = true;
882  }
883  if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock) {
884  $block_id = $block->getBlock()->getType();
885  if ($block->getPageEmbedded()) {
886  $force_item_even_if_already_rendered = true;
887  }
888  }
889  if ($block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
890  $block_id = "sess";
891  }
892  if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
893  $block_id = "_other";
894  }
895  if ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
896  $block_id = "_lobj";
897  }
898 
899  $position = 1;
900  $pos_prefix = "";
901 
902  // (1) add block
903  if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
904  $this->addItemGroupBlock($block_id);
905  $pos_prefix = "[itgr][" . \ilObject::_lookupObjId($block->getBlock()->getRefId()) . "]";
906  }
907  if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
908  $title = $this->item_presentation->filteredSubtree()
909  ? $this->lng->txt("cont_found_objects")
910  : $this->lng->txt("content");
911  $this->addCustomBlock($block_id, $title);
912  }
913  if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
914  $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
915  $this->addTypeBlock(
916  $block_id,
917  $this->getBlockPrefix($block_id),
918  $this->getBlockPostfix($block_id)
919  );
920  }
921 
922  // (2) render and add items
923  foreach ($block->getItemRefIds() as $ref_id) {
924  if ($this->isItemHidden($block_id, $ref_id)) {
925  continue;
926  }
927  if (!$this->access->checkAccess('visible', '', $ref_id)) {
928  continue;
929  }
930 
931  $item_data = $this->item_presentation->getRawDataByRefId($ref_id);
933  if ($this->container_gui->isActiveAdministrationPanel()) {
935  } elseif ($this->container_gui->isMultiDownloadEnabled()) {
937  }
938  $item_group_list_presentation = "";
939  if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
940  if ($this->getListPresentationOfItemGroup((int) $block_id) === "tile") {
941  if (!$this->admin_panel && !$this->active_block_ordering) {
942  $item_group_list_presentation = "tile";
943  }
944  }
945  if ($this->getListPresentationOfItemGroup((int) $block_id) === "list") {
946  if (!$this->admin_panel && !$this->active_block_ordering) {
947  $item_group_list_presentation = "list";
948  }
949  }
950  }
951  $html = $this->item_renderer->renderItem(
952  $item_data,
953  $position++,
954  false,
955  $pos_prefix,
956  $item_group_list_presentation,
957  $checkbox,
958  $this->item_presentation->isActiveItemOrdering($item_data["type"]),
959  $this->getDetailsLevel($item_data["obj_id"])
960  );
961  if ($html != "") {
962  $this->addItemToBlock(
963  $block_id,
964  $item_data["type"],
965  $item_data["child"],
966  $html,
967  $force_item_even_if_already_rendered
968  );
969  }
970  }
971 
972  // (3) render blocks
973  if ($block->getPageEmbedded()) {
974  if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
975  $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
976  $page_html = preg_replace(
977  '~\[list-' . $block->getId() . '\]~i',
978  $this->renderSingleTypeBlock($block->getId(), $block->getLimitExhausted()),
979  $page_html
980  );
981  $valid = true;
982  } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
983  $page_html = preg_replace(
984  '~\[item-group-' . $block->getId() . '\]~i',
985  $this->renderSingleCustomBlock((int) $block->getId()),
986  $page_html
987  );
988  $valid = true;
989  } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
990  $page_html = preg_replace(
991  '~\[list-_other\]~i',
992  $this->renderSingleCustomBlock($block->getId()),
993  $page_html
994  );
995  $valid = true;
996  } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
997  $page_html = preg_replace(
998  '~\[list-_lobj\]~i',
999  $this->objective_renderer->renderObjectives(),
1000  $page_html
1001  );
1002  $valid = true;
1003  }
1004  } else {
1005  if ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock ||
1006  $block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
1007  if ($this->renderHelperCustomBlock($block_tpl, $block_id, false, $block->getLimitExhausted())) {
1008  $this->addSeparatorRow($block_tpl);
1009  $valid = true;
1010  }
1011  }
1012  if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock ||
1013  $block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
1014  if ($this->renderHelperTypeBlock($block_tpl, $block_id, false, $block->getLimitExhausted())) {
1015  $this->addSeparatorRow($block_tpl);
1016  $valid = true;
1017  }
1018  }
1019  if ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
1020  $this->objective_renderer->renderObjectives();
1021  $block_tpl->setVariable(
1022  "CONTENT",
1023  $this->objective_renderer->getContent()
1024  );
1025  $this->addSeparatorRow($block_tpl);
1026  $valid = true;
1027  }
1028  }
1029  }
1030 
1031  // remove embedded, but unrendered blocks
1032  foreach ($this->item_presentation->getPageEmbeddedBlockIds() as $id) {
1033  if (is_numeric($id)) {
1034  $page_html = preg_replace(
1035  '~\[item-group-' . $id . '\]~i',
1036  "",
1037  $page_html
1038  );
1039  } else {
1040  $page_html = preg_replace(
1041  '~\[list-' . $id . '\]~i',
1042  "",
1043  $page_html
1044  );
1045  }
1046  }
1047 
1048  if ($valid) {
1049  $this->renderDetails($block_tpl);
1050  return $page_html . $block_tpl->get();
1051  }
1052  return $page_html;
1053  }
1054 
1058  protected function addItemGroupBlock(string $block_id, int $block_pos = 0): void
1059  {
1060  $item_data = $this->item_presentation->getRawDataByRefId((int) $block_id);
1061  $item_list_gui = $this->item_renderer->getItemGUI($item_data);
1062 
1063  $perm_ok = true;
1064  /*
1065  $ilAccess = $this->access;
1066  $ilUser = $this->user;
1067 
1068  // #16493
1069  $perm_ok = ($ilAccess->checkAccess("visible", "", $item_data['ref_id']) &&
1070  $ilAccess->checkAccess("read", "", $item_data['ref_id']));
1071 
1072  $items = ilObjectActivation::getItemsByItemGroup($item_data['ref_id']);
1073 
1074  // get all valid ids (this is filtered)
1075  $all_ids = array_map(static function (array $i) : int {
1076  return (int) $i["child"];
1077  }, $this->items["_all"]);
1078 
1079  // remove filtered items
1080  $items = array_filter($items, static function (array $i) use ($all_ids) : bool {
1081  return in_array($i["ref_id"], $all_ids);
1082  });
1083 
1084  // if no permission is given, set the items to "rendered" but
1085  // do not display the whole block
1086  if (!$perm_ok) {
1087  foreach ($items as $item) {
1088  $this->renderer->hideItem($item["child"]);
1089  }
1090  return;
1091  }
1092  */
1093 
1094  $item_list_gui->enableNotes(false);
1095  $item_list_gui->enableTags(false);
1096  $item_list_gui->enableComments(false);
1097  $item_list_gui->enableTimings(false);
1098  $item_list_gui->initItem(
1099  (int) $item_data["ref_id"],
1100  (int) $item_data["obj_id"],
1101  "itgr",
1102  $item_data["title"],
1103  $item_data["description"]
1104  );
1105  $commands_html = $item_list_gui->getCommandsHTML();
1106 
1107  // determine behaviour
1108  $item_group = new ilObjItemGroup($item_data["ref_id"]);
1109  $beh = $item_group->getBehaviour();
1110  $stored_val = $this->block_repo->getProperty(
1111  "itgr_" . $item_data["ref_id"],
1112  $this->user->getId(),
1113  "opened"
1114  );
1115  if ($stored_val !== "" && $beh !== ilItemGroupBehaviour::ALWAYS_OPEN) {
1116  $beh = ($stored_val === "1")
1119  }
1120 
1121  $data = [
1122  "behaviour" => $beh,
1123  "store-url" => "./ilias.php?baseClass=ilcontainerblockpropertiesstoragegui&cmd=store" .
1124  "&cont_block_id=itgr_" . $item_data['ref_id']
1125  ];
1126  if (ilObjItemGroup::lookupHideTitle($item_data["obj_id"]) &&
1127  !$this->container_gui->isActiveAdministrationPanel()) {
1128  $this->addCustomBlock($block_id, "", $commands_html, $data);
1129  } else {
1130  $this->addCustomBlock($block_id, $item_data["title"], $commands_html, $data);
1131  }
1132  }
1133 
1134  protected function getBlockPrefix($block_id): string
1135  {
1136  if ($this->block_prefix_closure instanceof Closure) {
1138  return (string) $c($block_id);
1139  }
1140  return "";
1141  }
1142 
1143  protected function getBlockPostfix($block_id): string
1144  {
1145  if ($this->block_postfix_closure instanceof Closure) {
1147  return (string) $c($block_id);
1148  }
1149  return "";
1150  }
1151 
1152  protected function isItemHidden(string $block_id, int $ref_id): bool
1153  {
1154  if ($this->item_hidden_closure instanceof Closure) {
1156  return (bool) $c($block_id, $ref_id);
1157  }
1158  return false;
1159  }
1160 
1161 }
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
ILIAS Containter Content ItemRenderer $item_renderer
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
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:68
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:25
withLoadingAnimationOnClick(bool $loading_animation_on_click=true)
addTypeBlock(string $a_type, ?string $a_prefix=null, ?string $a_postfix=null)
ILIAS Container Content ItemPresentationManager $item_presentation
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
hasItem($a_id)
Item with id exists?
touchBlock(string $block)
renderDetails(ilTemplate $a_tpl)
ILIAS Container Content ItemManager $item_manager
$ref_id
Definition: ltiauth.php:65
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
addShowMoreButton($a_block_id)
Add show more button to a block.
isItemHidden(string $block_id, int $ref_id)
global $DIC
Definition: shib_login.php:26
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?
Class ilObjItemGroup.
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.
global $ilSetting
Definition: privfeed.php:31
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
removeItem($a_id)
Remove item (from any block)
addCustomBlock( $a_id, string $a_caption, ?string $a_actions=null, array $a_data=[])
Add custom block.
setBlockPosition( $a_block_id, int $a_pos)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
addItemGroupBlock(string $block_id, int $block_pos=0)
replaces ilContainerContentGUI::renderItemGroup
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
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".
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.
renderHelperTypeBlock(ilTemplate $a_block_tpl, string $a_type, bool $a_is_single=false, bool $is_exhausted=false)