ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
MainMenuMainCollector.php
Go to the documentation of this file.
2
24
33{
34
42 private $information;
46 protected $providers;
50 private $map;
51
59 {
60 $this->information = $information;
61 $this->providers = $providers;
62 $this->type_information_collection = new TypeInformationCollection();
63 $this->map = new Map($factory);
64 }
65
69 private function getProvidersFromList() : \Generator
70 {
71 yield from $this->providers;
72 }
73
74 public function collectStructure() : void
75 {
76 foreach ($this->getProvidersFromList() as $provider) {
77 $this->type_information_collection->append($provider->provideTypeInformation());
78 $this->map->addMultiple(...$provider->getStaticTopItems());
79 $this->map->addMultiple(...$provider->getStaticSubItems());
80 }
81 }
82
83 public function filterItemsByVisibilty(bool $async_only = false) : void
84 {
85 // apply filter
86 $this->map->filter(function (isItem $item) use ($async_only) : bool {
87 if ($async_only && !$item instanceof supportsAsynchronousLoading) {
88 return false;
89 }
90 if (!$item->isAvailable()) {
91 return false;
92 }
93
94 // make parent available if one child is always available
95 if ($item instanceof isParent) {
96 foreach ($item->getChildren() as $child) {
97 if ($child->isAlwaysAvailable()) {
98 return true;
99 }
100 }
101 }
102
103 // Always avaiable must be delivered when visible
104 if ($item->isAlwaysAvailable()) {
105 return $item->isVisible();
106 }
107 // All other cases
108 return $item->isAvailable() && $item->isVisible() && $this->information->isItemActive($item);
109 });
110 }
111
112 public function prepareItemsForUIRepresentation() : void
113 {
114 $this->map->walk(function (isItem &$item) : isItem {
115 $item->setTypeInformation($this->getTypeInformationForItem($item));
116
117 // Apply the TypeHandler
118 $item = $this->getTypeHandlerForItem($item)->enrichItem($item);
119 // Translate Item
120 if ($item instanceof hasTitle) {
121 $item = $this->getItemInformation()->customTranslationForUser($item);
122 }
123 // Custom Symbol
124 if ($item instanceof hasSymbol) {
125 $item = $this->getItemInformation()->customSymbol($item);
126 }
127 // Custom Position
128 $item = $this->getItemInformation()->customPosition($item);
129
130 return $item;
131 });
132
133 // Override parent from configuration
134 $this->map->walk(function (isItem &$item) {
135 if ($item instanceof isChild) {
136 $parent = $this->map->getSingleItemFromFilter($this->information->getParent($item));
137 if ($parent instanceof isParent) {
138 $parent->appendChild($item);
139 if ($parent instanceof Lost && $parent->getProviderIdentification()->serialize() === '') {
140 $item->overrideParent($parent->getProviderIdentification());
141 }
142 }
143 }
144
145 return $item;
146 });
147 }
148
149 public function cleanupItemsForUIRepresentation() : void
150 {
151 // Remove not visible children
152 $this->map->walk(function (isItem &$item) : isItem {
153 if ($item instanceof isParent) {
154 foreach ($item->getChildren() as $child) {
155 if (!$this->map->existsInFilter($child->getProviderIdentification())) {
156 $item->removeChild($child);
157 }
158 }
159 }
160 return $item;
161 });
162
163 $this->map->walk(static function (isItem &$i) : void {
164 if ($i instanceof isParent && count($i->getChildren()) === 0) {
165 $i = $i->withAvailableCallable(static function () {
166 return false;
167 })->withVisibilityCallable(static function () {
168 return false;
169 });
170 }
171 });
172
173 // filter empty slates
174 $this->map->filter(static function (isItem $i) : bool {
175 if ($i instanceof isParent) {
176 return count($i->getChildren()) > 0;
177 }
178
179 return true;
180 });
181
182 }
183
184 public function sortItemsForUIRepresentation() : void
185 {
186 $this->map->sort();
187 }
188
195 public function getItemsForUIRepresentation() : \Generator
196 {
197 foreach ($this->map->getAllFromFilter() as $item) {
198 if ($item->isTop()) {
199 yield $item;
200 }
201 }
202 }
203
207 public function getRawItems() : \Generator
208 {
209 yield from $this->map->getAllFromFilter();
210 }
211
215 public function hasItems() : bool
216 {
217 return $this->map->has();
218 }
219
225 public function getSingleItemFromFilter(IdentificationInterface $identification) : isItem
226 {
227 return $this->map->getSingleItemFromFilter($identification);
228 }
229
235 public function getSingleItemFromRaw(IdentificationInterface $identification) : isItem
236 {
237 return $this->map->getSingleItemFromRaw($identification);
238 }
239
244 public function getTypeHandlerForItem(isItem $item) : TypeHandler
245 {
246 $type_information = $this->getTypeInformationForItem($item);
247 if ($type_information === null) {
248 return new BaseTypeHandler();
249 }
250
251 return $type_information->getTypeHandler();
252 }
253
259 {
260 return $this->information;
261 }
262
268 {
269 return $this->getTypeInformationCollection()->get(get_class($item));
270 }
271
276 {
277 return $this->type_information_collection;
278 }
279}
An exception for terminatinating execution or to throw for unit testing.
Class MainMenuMainCollector This Collector will collect and then provide all available slates from th...
getItemsForUIRepresentation()
This will return all available isTopItem (and moved isInterchangeableItem), stacked based on the conf...
__construct(array $providers, MainMenuItemFactory $factory, ItemInformation $information=null)
MainMenuMainCollector constructor.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:12
setTypeInformation(TypeInformation $information)
$factory
Definition: metadata.php:58
$i
Definition: metadata.php:24