ILIAS  release_8 Revision v8.24
MainLayoutCollector.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
21
42use LogicException;
43
50{
55 private array $providers;
56
61 public function __construct(array $providers)
62 {
63 $this->providers = $providers;
64 $this->modification_handler = new ModificationHandler();
65 }
66
67 public function collectStructure(): void
68 {
69 // Client
71 $settings->setHashing(true);
72 $settings->setLogging(false);
73
75 $client->init($this->getMetaContent());
76
77 $called_contexts = $this->getContextStack();
78
79 $final_content_modification = new NullModification();
80 $final_logo_modification = new NullModification();
81 $final_responsive_logo_modification = new NullModification();
82 $final_breadcrumbs_modification = new NullModification();
83 $final_main_bar_modification = new NullModification();
84 $final_meta_bar_modification = new NullModification();
85 $final_page_modification = new NullModification();
86 $final_footer_modification = new NullModification();
87 $final_title_modification = new NullModification();
88 $final_short_title_modification = new NullModification();
89 $final_view_title_modification = new NullModification();
90
91 foreach ($this->providers as $provider) {
92 $context_collection = $provider->isInterestedInContexts();
93 if (!$context_collection->hasMatch($called_contexts)) {
94 continue;
95 }
96
97 // CONTENT
98 $content_modification = $provider->getContentModification($called_contexts);
99 $this->replaceModification($final_content_modification, $content_modification, ContentModification::class);
100 // LOGO
101 $logo_modification = $provider->getLogoModification($called_contexts);
102 $this->replaceModification($final_logo_modification, $logo_modification, LogoModification::class);
103 // RESPONSIVE LOGO
104 $responsive_logo_modification = $provider->getResponsiveLogoModification($called_contexts);
105 $this->replaceModification(
106 $final_responsive_logo_modification,
107 $responsive_logo_modification,
108 LogoModification::class
109 );
110 // BREADCRUMBS
111 $breadcrumbs_modification = $provider->getBreadCrumbsModification($called_contexts);
112 $this->replaceModification(
113 $final_breadcrumbs_modification,
114 $breadcrumbs_modification,
115 BreadCrumbsModification::class
116 );
117 // MAINBAR
118 $main_bar_modification = $provider->getMainBarModification($called_contexts);
119 $this->replaceModification(
120 $final_main_bar_modification,
121 $main_bar_modification,
122 MainBarModification::class
123 );
124 // METABAR
125 $meta_bar_modification = $provider->getMetaBarModification($called_contexts);
126 $this->replaceModification(
127 $final_meta_bar_modification,
128 $meta_bar_modification,
129 MetaBarModification::class
130 );
131 // FOOTER
132 $footer_modification = $provider->getFooterModification($called_contexts);
133 $this->replaceModification($final_footer_modification, $footer_modification, FooterModification::class);
134 // PAGE
135 $page_modification = $provider->getPageBuilderDecorator($called_contexts);
136 $this->replaceModification($final_page_modification, $page_modification, PageBuilderModification::class);
137 // Pagetitle
138 $title_modification = $provider->getTitleModification($called_contexts);
139 $this->replaceModification($final_title_modification, $title_modification, TitleModification::class);
140
141 $short_title_modification = $provider->getShortTitleModification($called_contexts);
142 $this->replaceModification($final_short_title_modification, $short_title_modification, ShortTitleModification::class);
143
144 $view_title_modification = $provider->getViewTitleModification($called_contexts);
145 $this->replaceModification(
146 $final_view_title_modification,
147 $view_title_modification,
148 ViewTitleModification::class
149 );
150 }
151
152 if ($final_content_modification->hasValidModification()) {
153 $this->modification_handler->modifyContentWithClosure($final_content_modification->getModification());
154 }
155 if ($final_logo_modification->hasValidModification()) {
156 $this->modification_handler->modifyLogoWithClosure($final_logo_modification->getModification());
157 }
158 if ($final_responsive_logo_modification->hasValidModification()) {
159 $this->modification_handler->modifyResponsiveLogoWithClosure($final_responsive_logo_modification->getModification());
160 }
161 if ($final_breadcrumbs_modification->hasValidModification()) {
162 $this->modification_handler->modifyBreadCrumbsWithClosure($final_breadcrumbs_modification->getModification());
163 }
164 if ($final_main_bar_modification->hasValidModification()) {
165 $this->modification_handler->modifyMainBarWithClosure($final_main_bar_modification->getModification());
166 }
167 if ($final_meta_bar_modification->hasValidModification()) {
168 $this->modification_handler->modifyMetaBarWithClosure($final_meta_bar_modification->getModification());
169 }
170 if ($final_footer_modification->hasValidModification()) {
171 $this->modification_handler->modifyFooterWithClosure($final_footer_modification->getModification());
172 }
173 if ($final_page_modification->hasValidModification()) {
174 $this->modification_handler->modifyPageBuilderWithClosure($final_page_modification->getModification());
175 }
176 if ($final_title_modification->hasValidModification()) {
177 $this->modification_handler->modifyTitleWithClosure($final_title_modification->getModification());
178 }
179 if ($final_short_title_modification->hasValidModification()) {
180 $this->modification_handler->modifyShortTitleWithClosure($final_short_title_modification->getModification());
181 }
182 if ($final_view_title_modification->hasValidModification()) {
183 $this->modification_handler->modifyViewTitleWithClosure($final_view_title_modification->getModification());
184 }
185 }
186
187 public function filterItemsByVisibilty(bool $skip_async = false): void
188 {
189 // TODO: Implement filterItemsByVisibilty() method.
190 }
191
192 public function prepareItemsForUIRepresentation(): void
193 {
194 // TODO: Implement prepareItemsForUIRepresentation() method.
195 }
196
197 public function cleanupItemsForUIRepresentation(): void
198 {
199 // TODO: Implement cleanupItemsForUIRepresentation() method.
200 }
201
202 public function sortItemsForUIRepresentation(): void
203 {
204 // TODO: Implement sortItemsForUIRepresentation() method.
205 }
206
210 public function getItemsForUIRepresentation(): void
211 {
212 // TODO: Implement getItemsForUIRepresentation() method.
213 }
214
218 public function hasItems(): bool
219 {
220 return true;
221 }
222
228 private function replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type): void
229 {
230 if (is_a($candicate, $type) && $candicate->hasValidModification()) {
231 if ($candicate->getPriority() === $current_modification->getPriority()) {
232 throw new LogicException("There are competing Modifications for $type with the same priority ({$candicate->getPriority()})");
233 } elseif ($candicate->getPriority() > $current_modification->getPriority()) {
234 $current_modification = $candicate;
235 }
236 }
237 }
238
242 public function getFinalPage(): Page
243 {
244 $this->collectOnce();
245
246 return $this->modification_handler->getPageWithPagePartProviders();
247 }
248
252 private function getContextStack(): CalledContexts
253 {
254 global $DIC;
255 $called_contexts = $DIC->globalScreen()->tool()->context()->stack();
256
257 return $called_contexts;
258 }
259
263 private function getMetaContent(): MetaContent
264 {
265 global $DIC;
266
267 return $DIC->globalScreen()->layout()->meta();
268 }
269}
collectOnce()
Runs the Collection of all items from the providers.
replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type)
__construct(array $providers)
MainLayoutCollector constructor.
$client
global $DIC
Definition: feed.php:28
This describes the Page.
Definition: Page.php:31
$provider
Definition: ltitoken.php:83
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$type