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