ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MainLayoutCollector.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
42use LogicException;
43
50{
52
57 public function __construct(private array $providers)
58 {
59 $this->modification_handler = new ModificationHandler();
60 }
61
62 public function collectStructure(): void
63 {
64 // Client
65 $settings = new ClientSettings();
66 $settings->setHashing(true);
67 $settings->setLogging(false);
68
69 $client = new Client($settings);
70 $client->init($this->getMetaContent());
71
72 $called_contexts = $this->getContextStack();
73
74 $final_content_modification = new NullModification();
75 $final_logo_modification = new NullModification();
76 $final_responsive_logo_modification = new NullModification();
77 $final_breadcrumbs_modification = new NullModification();
78 $final_main_bar_modification = new NullModification();
79 $final_meta_bar_modification = new NullModification();
80 $final_page_modification = new NullModification();
81 $final_footer_modification = new NullModification();
82 $final_title_modification = new NullModification();
83 $final_short_title_modification = new NullModification();
84 $final_view_title_modification = new NullModification();
85
86 foreach ($this->providers as $provider) {
87 $context_collection = $provider->isInterestedInContexts();
88 if (!$context_collection->hasMatch($called_contexts)) {
89 continue;
90 }
91
92 // CONTENT
93 $content_modification = $provider->getContentModification($called_contexts);
94 $this->replaceModification($final_content_modification, $content_modification, ContentModification::class);
95 // LOGO
96 $logo_modification = $provider->getLogoModification($called_contexts);
97 $this->replaceModification($final_logo_modification, $logo_modification, LogoModification::class);
98 // RESPONSIVE LOGO
99 $responsive_logo_modification = $provider->getResponsiveLogoModification($called_contexts);
100 $this->replaceModification(
101 $final_responsive_logo_modification,
102 $responsive_logo_modification,
103 LogoModification::class
104 );
105 // BREADCRUMBS
106 $breadcrumbs_modification = $provider->getBreadCrumbsModification($called_contexts);
107 $this->replaceModification(
108 $final_breadcrumbs_modification,
109 $breadcrumbs_modification,
110 BreadCrumbsModification::class
111 );
112 // MAINBAR
113 $main_bar_modification = $provider->getMainBarModification($called_contexts);
114 $this->replaceModification(
115 $final_main_bar_modification,
116 $main_bar_modification,
117 MainBarModification::class
118 );
119 // METABAR
120 $meta_bar_modification = $provider->getMetaBarModification($called_contexts);
121 $this->replaceModification(
122 $final_meta_bar_modification,
123 $meta_bar_modification,
124 MetaBarModification::class
125 );
126 // FOOTER
127 $footer_modification = $provider->getFooterModification($called_contexts);
128 $this->replaceModification($final_footer_modification, $footer_modification, FooterModification::class);
129 // PAGE
130 $page_modification = $provider->getPageBuilderDecorator($called_contexts);
131 $this->replaceModification($final_page_modification, $page_modification, PageBuilderModification::class);
132 // Pagetitle
133 $title_modification = $provider->getTitleModification($called_contexts);
134 $this->replaceModification($final_title_modification, $title_modification, TitleModification::class);
135
136 $short_title_modification = $provider->getShortTitleModification($called_contexts);
137 $this->replaceModification($final_short_title_modification, $short_title_modification, ShortTitleModification::class);
138
139 $view_title_modification = $provider->getViewTitleModification($called_contexts);
140 $this->replaceModification(
141 $final_view_title_modification,
142 $view_title_modification,
143 ViewTitleModification::class
144 );
145 }
146
147 if ($final_content_modification->hasValidModification()) {
148 $this->modification_handler->modifyContentWithClosure($final_content_modification->getModification());
149 }
150 if ($final_logo_modification->hasValidModification()) {
151 $this->modification_handler->modifyLogoWithClosure($final_logo_modification->getModification());
152 }
153 if ($final_responsive_logo_modification->hasValidModification()) {
154 $this->modification_handler->modifyResponsiveLogoWithClosure($final_responsive_logo_modification->getModification());
155 }
156 if ($final_breadcrumbs_modification->hasValidModification()) {
157 $this->modification_handler->modifyBreadCrumbsWithClosure($final_breadcrumbs_modification->getModification());
158 }
159 if ($final_main_bar_modification->hasValidModification()) {
160 $this->modification_handler->modifyMainBarWithClosure($final_main_bar_modification->getModification());
161 }
162 if ($final_meta_bar_modification->hasValidModification()) {
163 $this->modification_handler->modifyMetaBarWithClosure($final_meta_bar_modification->getModification());
164 }
165 if ($final_footer_modification->hasValidModification()) {
166 $this->modification_handler->modifyFooterWithClosure($final_footer_modification->getModification());
167 }
168 if ($final_page_modification->hasValidModification()) {
169 $this->modification_handler->modifyPageBuilderWithClosure($final_page_modification->getModification());
170 }
171 if ($final_title_modification->hasValidModification()) {
172 $this->modification_handler->modifyTitleWithClosure($final_title_modification->getModification());
173 }
174 if ($final_short_title_modification->hasValidModification()) {
175 $this->modification_handler->modifyShortTitleWithClosure($final_short_title_modification->getModification());
176 }
177 if ($final_view_title_modification->hasValidModification()) {
178 $this->modification_handler->modifyViewTitleWithClosure($final_view_title_modification->getModification());
179 }
180 }
181
182 public function filterItemsByVisibilty(bool $skip_async = false): void
183 {
184 // TODO: Implement filterItemsByVisibilty() method.
185 }
186
187 public function prepareItemsForUIRepresentation(): void
188 {
189 // TODO: Implement prepareItemsForUIRepresentation() method.
190 }
191
192 public function cleanupItemsForUIRepresentation(): void
193 {
194 // TODO: Implement cleanupItemsForUIRepresentation() method.
195 }
196
197 public function sortItemsForUIRepresentation(): void
198 {
199 // TODO: Implement sortItemsForUIRepresentation() method.
200 }
201
205 public function getItemsForUIRepresentation(): void
206 {
207 // TODO: Implement getItemsForUIRepresentation() method.
208 }
209
213 public function hasItems(): bool
214 {
215 return true;
216 }
217
223 private function replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type): void
224 {
225 if (is_a($candicate, $type) && $candicate->hasValidModification()) {
226 if ($candicate->getPriority() === $current_modification->getPriority()) {
227 throw new LogicException("There are competing Modifications for $type with the same priority ({$candicate->getPriority()})");
228 }
229 if ($candicate->getPriority() > $current_modification->getPriority()) {
230 $current_modification = $candicate;
231 }
232 }
233 }
234
238 public function getFinalPage(): Page
239 {
240 $this->collectOnce();
241
242 return $this->modification_handler->getPageWithPagePartProviders();
243 }
244
248 private function getContextStack(): CalledContexts
249 {
250 global $DIC;
251 $called_contexts = $DIC->globalScreen()->tool()->context()->stack();
252
253 return $called_contexts;
254 }
255
259 private function getMetaContent(): MetaContent
260 {
261 global $DIC;
262
263 return $DIC->globalScreen()->layout()->meta();
264 }
265}
collectOnce()
Runs the Collection of all items from the providers.
replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type)
__construct(private array $providers)
MainLayoutCollector constructor.
$client
This describes the Page.
Definition: Page.php:31
$provider
Definition: ltitoken.php:80
global $DIC
Definition: shib_login.php:26