ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
MainLayoutCollector.php
Go to the documentation of this file.
2 
25 use LogicException;
26 
35 {
36 
44  private $providers = [];
45 
46 
52  public function __construct(array $providers)
53  {
54  $this->providers = $providers;
55  $this->modification_handler = new ModificationHandler();
56  }
57 
58 
59  public function collectStructure() : void
60  {
61  // Client
62  $settings = new ClientSettings();
63  $settings->setHashing(true);
64  $settings->setLogging(false);
65 
66  $client = new Client($settings);
67  $client->init($this->getMetaContent());
68 
69  $called_contexts = $this->getContextStack();
70 
71  $final_content_modification = new NullModification();
72  $final_logo_modification = new NullModification();
73  $final_responsive_logo_modification = new NullModification();
74  $final_breadcrumbs_modification = new NullModification();
75  $final_main_bar_modification = new NullModification();
76  $final_meta_bar_modification = new NullModification();
77  $final_page_modification = new NullModification();
78  $final_footer_modification = new NullModification();
79  $final_title_modification = new NullModification();
80  $final_short_title_modification = new NullModification();
81  $final_view_title_modification = new NullModification();
82 
83  foreach ($this->providers as $provider) {
84  $context_collection = $provider->isInterestedInContexts();
85  if (!$context_collection->hasMatch($called_contexts)) {
86  continue;
87  }
88 
89  // CONTENT
90  $content_modification = $provider->getContentModification($called_contexts);
91  $this->replaceModification($final_content_modification, $content_modification, ContentModification::class);
92  // LOGO
93  $logo_modification = $provider->getLogoModification($called_contexts);
94  $this->replaceModification($final_logo_modification, $logo_modification, LogoModification::class);
95  // RESPONSIVE LOGO
96  $responsive_logo_modification = $provider->getResponsiveLogoModification($called_contexts);
97  $this->replaceModification($final_responsive_logo_modification, $responsive_logo_modification,
98  LogoModification::class);
99  // BREADCRUMBS
100  $breadcrumbs_modification = $provider->getBreadCrumbsModification($called_contexts);
101  $this->replaceModification($final_breadcrumbs_modification, $breadcrumbs_modification,
102  BreadCrumbsModification::class);
103  // MAINBAR
104  $main_bar_modification = $provider->getMainBarModification($called_contexts);
105  $this->replaceModification($final_main_bar_modification, $main_bar_modification,
106  MainBarModification::class);
107  // METABAR
108  $meta_bar_modification = $provider->getMetaBarModification($called_contexts);
109  $this->replaceModification($final_meta_bar_modification, $meta_bar_modification,
110  MetaBarModification::class);
111  // FOOTER
112  $footer_modification = $provider->getFooterModification($called_contexts);
113  $this->replaceModification($final_footer_modification, $footer_modification, FooterModification::class);
114  // PAGE
115  $page_modification = $provider->getPageBuilderDecorator($called_contexts);
116  $this->replaceModification($final_page_modification, $page_modification, PageBuilderModification::class);
117  // Pagetitle
118  $title_modification = $provider->getTitleModification($called_contexts);
119  $this->replaceModification($final_title_modification, $title_modification, TitleModification::class);
120 
121  $short_title_modification = $provider->getShortTitleModification($called_contexts);
122  $this->replaceModification($final_short_title_modification, $short_title_modification,
123  ShortTitleModification::class);
124 
125  $view_title_modification = $provider->getViewTitleModification($called_contexts);
126  $this->replaceModification($final_view_title_modification, $view_title_modification,
127  ViewTitleModification::class);
128  }
129 
130  if ($final_content_modification->hasValidModification()) {
131  $this->modification_handler->modifyContentWithClosure($final_content_modification->getModification());
132  }
133  if ($final_logo_modification->hasValidModification()) {
134  $this->modification_handler->modifyLogoWithClosure($final_logo_modification->getModification());
135  }
136  if ($final_responsive_logo_modification->hasValidModification()) {
137  $this->modification_handler->modifyResponsiveLogoWithClosure($final_responsive_logo_modification->getModification());
138  }
139  if ($final_breadcrumbs_modification->hasValidModification()) {
140  $this->modification_handler->modifyBreadCrumbsWithClosure($final_breadcrumbs_modification->getModification());
141  }
142  if ($final_main_bar_modification->hasValidModification()) {
143  $this->modification_handler->modifyMainBarWithClosure($final_main_bar_modification->getModification());
144  }
145  if ($final_meta_bar_modification->hasValidModification()) {
146  $this->modification_handler->modifyMetaBarWithClosure($final_meta_bar_modification->getModification());
147  }
148  if ($final_footer_modification->hasValidModification()) {
149  $this->modification_handler->modifyFooterWithClosure($final_footer_modification->getModification());
150  }
151  if ($final_page_modification->hasValidModification()) {
152  $this->modification_handler->modifyPageBuilderWithClosure($final_page_modification->getModification());
153  }
154  if ($final_title_modification->hasValidModification()) {
155  $this->modification_handler->modifyTitleWithClosure($final_title_modification->getModification());
156  }
157  if ($final_short_title_modification->hasValidModification()) {
158  $this->modification_handler->modifyShortTitleWithClosure($final_short_title_modification->getModification());
159  }
160  if ($final_view_title_modification->hasValidModification()) {
161  $this->modification_handler->modifyViewTitleWithClosure($final_view_title_modification->getModification());
162  }
163  }
164 
165 
166  public function filterItemsByVisibilty(bool $skip_async = false) : void
167  {
168  // TODO: Implement filterItemsByVisibilty() method.
169  }
170 
171 
172  public function prepareItemsForUIRepresentation() : void
173  {
174  // TODO: Implement prepareItemsForUIRepresentation() method.
175  }
176 
177  public function cleanupItemsForUIRepresentation() : void
178  {
179  // TODO: Implement cleanupItemsForUIRepresentation() method.
180  }
181 
182  public function sortItemsForUIRepresentation() : void
183  {
184  // TODO: Implement sortItemsForUIRepresentation() method.
185  }
186 
187 
192  {
193  // TODO: Implement getItemsForUIRepresentation() method.
194  }
195 
196 
200  public function hasItems() : bool
201  {
202  return true;
203  }
204 
205 
211  private function replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type)
212  {
213  if (is_a($candicate, $type) && $candicate->hasValidModification()) {
214  if ($candicate->getPriority() === $current_modification->getPriority()) {
215  throw new LogicException("There are competing Modifications for $type with the same priority ({$candicate->getPriority()})");
216  } elseif ($candicate->getPriority() > $current_modification->getPriority()) {
217  $current_modification = $candicate;
218  }
219  }
220  }
221 
222 
226  public function getFinalPage() : Page
227  {
228  $this->collectOnce();
229 
230  return $this->modification_handler->getPageWithPagePartProviders();
231  }
232 
233 
237  private function getContextStack() : CalledContexts
238  {
239  global $DIC;
240  $called_contexts = $DIC->globalScreen()->tool()->context()->stack();
241 
242  return $called_contexts;
243  }
244 
245 
249  private function getMetaContent() : MetaContent
250  {
251  global $DIC;
252 
253  return $DIC->globalScreen()->layout()->meta();
254  }
255 }
replaceModification(LayoutModification &$current_modification, ?LayoutModification $candicate, string $type)
__construct(array $providers)
MainLayoutCollector constructor.
$type
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
collectOnce()
Runs the Collection of all items from the providers.
This describes the Page.
Definition: Page.php:13
$DIC
Definition: xapitoken.php:46