ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FooterMainCollector.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Generator;
34
39{
40 private readonly Map $map;
41
42 public function __construct(
43 private readonly array $providers,
44 private readonly ItemInformation $item_information
45 ) {
46 $this->map = new Map();
47 }
48
52 private function getProvidersFromList(): Generator
53 {
54 yield from $this->providers;
55 }
56
57 public function collectStructure(): void
58 {
59 foreach ($this->getProvidersFromList() as $provider) {
60 $this->map->addMultiple(...$provider->getGroups());
61 $this->map->addMultiple(...$provider->getEntries());
62 $this->map->addMultiple(...$provider->getAdditionalTexts());
63 if (($permanent = $provider->getPermanentURI()) !== null) {
64 $this->map->add($permanent);
65 }
66 }
67 }
68
69 public function filterItemsByVisibilty(bool $async_only = false): void
70 {
71 // apply filter
72 $this->map->filter(fn(isItem $item): bool => $item->isAvailable() && $item->isVisible());
73 }
74
75 public function prepareItemsForUIRepresentation(): void
76 {
77 $this->map->filter(fn(isItem $item): bool => $item->isAvailable());
78 $this->map->filter(fn(isItem $item): bool => $item->isVisible());
79 $this->map->filter(fn(isItem $item): bool => $this->item_information->isItemActive($item));
80
81 $this->map->walk(function (isItem &$item): isItem {
82 if ($item instanceof hasTitle) {
83 $item = $this->item_information->customTranslationForUser($item);
84 }
85
86 $item = $this->item_information->customPosition($item);
87
88 return $item;
89 });
90
91 // Override parent from configuration
92 $this->map->walk(function (isItem $item): isItem {
93 if ($item instanceof canHaveParent && $item->hasParent()) {
94 $parent_id = $this->item_information->getParent($item);
95
96 $parent = $this->map->getSingleItemFromFilter($parent_id); // $item->getParentIdentification()
97
98 if ($parent instanceof isGroup) {
99 $parent->addEntry($item);
100 $this->map->add($parent);
101 }
102 }
103
104 return $item;
105 });
106 }
107
108 public function sortItemsForUIRepresentation(): void
109 {
110 $this->map->sort();
111 }
112
113 public function cleanupItemsForUIRepresentation(): void
114 {
115 // remove empty groups
116 $this->map->filter(function (isItem $item): bool {
117 if (!$item instanceof isGroup) {
118 return true;
119 }
120
121 return $item->getEntries() !== [];
122 });
123 }
124
125 public function getItemsForUIRepresentation(): Generator
126 {
127 foreach ($this->map->getAllFromFilter() as $item) {
128 yield $item;
129 }
130 }
131
132 public function getRawItems(): Generator
133 {
134 yield from $this->map->getAllFromFilter();
135 }
136
137 public function getRawUnfilteredItems(): Generator
138 {
139 yield from $this->map->getAllFromRaw();
140 }
141
142 public function hasItems(): bool
143 {
144 return $this->map->has();
145 }
146
147 public function hasVisibleItems(): bool
148 {
149 if (!$this->hasItems()) {
150 return false;
151 }
152 foreach ($this->getItemsForUIRepresentation() as $item) {
153 return $item instanceof isItem;
154 }
155 return false;
156 }
157
162 {
163 return $this->map->getSingleItemFromFilter($identification);
164 }
165
169 public function getSingleItemFromRaw(IdentificationInterface $identification): isItem
170 {
171 return $this->map->getSingleItemFromRaw($identification);
172 }
173
174}
getSingleItemFromFilter(IdentificationInterface $identification)
getSingleItemFromRaw(IdentificationInterface $identification)
__construct(private readonly array $providers, private readonly ItemInformation $item_information)
$provider
Definition: ltitoken.php:80