ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
StandardPagePartProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 use ilUserUtil;
36 use ilUtil;
39 use ilLanguage;
44 
51 {
52  use isSupportedTrait;
54 
55  protected Legacy $content;
56  protected Services $gs;
57  protected UIServices $ui;
58  protected ilLanguage $lang;
59 
60 
61  public function __construct()
62  {
63  global $DIC;
64  $this->ui = $DIC->ui();
65  $this->gs = $DIC->globalScreen();
66  $this->lang = $DIC->language();
67  }
68 
69 
70  public function getContent(): ?Legacy
71  {
72  return $this->content ?? $this->ui->factory()->legacy("");
73  }
74 
75 
76  public function getMetaBar(): ?MetaBar
77  {
78  $this->gs->collector()->metaBar()->collectOnce();
79  if (!$this->gs->collector()->metaBar()->hasItems()) {
80  return null;
81  }
82  $f = $this->ui->factory();
83  $meta_bar = $f->mainControls()->metaBar();
84 
85  foreach ($this->gs->collector()->metaBar()->getItemsForUIRepresentation() as $item) {
87  $component = $item->getRenderer()->getComponentForItem($item);
88  if ($this->isComponentSupportedForCombinedSlate($component)) {
89  $meta_bar = $meta_bar->withAdditionalEntry($item->getProviderIdentification()->getInternalIdentifier(), $component);
90  }
91  }
92 
93  return $meta_bar;
94  }
95 
96 
97  public function getMainBar(): ?MainBar
98  {
99  // Collect all items which could be displayed in the main bar
100  $this->gs->collector()->mainmenu()->collectOnce();
101  $this->gs->collector()->tool()->collectOnce();
102 
103  // If there are no items to display, return null. By definition, no MainBar is added to the Page in this case.
104  if (!$this->gs->collector()->mainmenu()->hasVisibleItems()
105  && !$this->gs->collector()->tool()->hasVisibleItems()) {
106  return null;
107  }
108 
109  $f = $this->ui->factory();
110  $main_bar = $f->mainControls()->mainBar();
111 
112  foreach ($this->gs->collector()->mainmenu()->getItemsForUIRepresentation() as $item) {
116  $component = $item->getTypeInformation()->getRenderer()->getComponentForItem($item, false);
117  $identifier = $this->hash($item->getProviderIdentification()->serialize());
118 
119  if ($this->isComponentSupportedForCombinedSlate($component)) {
120  $main_bar = $main_bar->withAdditionalEntry($identifier, $component);
121  }
122  }
123 
124  // Tools
125  $grid_icon = $f->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_tool.svg"), $this->lang->txt('more'));
126 
127  if ($this->gs->collector()->tool()->hasItems()) {
128  $tools_button = $f->button()->bulky($grid_icon, $this->lang->txt('tools'), "#")->withEngagedState(true);
129  $main_bar = $main_bar->withToolsButton($tools_button);
133  foreach ($this->gs->collector()->tool()->getItemsForUIRepresentation() as $tool) {
135  if (!$tool instanceof isToolItem) {
136  continue;
137  }
138  $component = $tool->getTypeInformation()->getRenderer()->getComponentForItem($tool, false);
139 
140  $identifier = $this->hash($tool->getProviderIdentification()->serialize());
141  $close_button = null;
142  if ($tool->hasCloseCallback()) {
143  $close_button = $this->ui->factory()->button()->close()->withOnLoadCode(static function (string $id) use ($identifier): string {
144  $key_item = CallbackHandler::KEY_ITEM;
145  return "$('#$id').on('click', function(){
146  $.ajax({
147  url: 'callback_handler.php?$key_item=$identifier'
148  }).done(function() {
149  console.log('done closing');
150  });
151  });";
152  });
153  }
154  $main_bar = $main_bar->withAdditionalToolEntry($identifier, $component, $tool->isInitiallyHidden(), $close_button);
155  }
156  }
157 
158  return $main_bar;
159  }
160 
161 
162  public function getBreadCrumbs(): ?Breadcrumbs
163  {
164  // TODO this currently gets the items from ilLocatorGUI, should that serve be removed with
165  // something like GlobalScreen\Scope\Locator\Item
166  global $DIC;
167 
168  $f = $this->ui->factory();
169  $crumbs = [];
170  foreach ($DIC['ilLocator']->getItems() as $item) {
171  if (empty($item['title'])) {
172  continue;
173  }
174  if (empty($item['link'])) {
175  continue;
176  }
177  $crumbs[] = $f->link()->standard($item['title'], $item["link"]);
178  }
179 
180  return $f->breadcrumbs($crumbs);
181  }
182 
183 
184  public function getLogo(): ?Image
185  {
186  $std_logo = ilUtil::getImagePath("logo/HeaderIcon.svg");
187 
188  return $this->ui->factory()->image()
189  ->standard($std_logo, $this->lang->txt('rep_main_page'))
190  ->withAction($this->getStartingPointAsUrl());
191  }
192 
193 
194  public function getResponsiveLogo(): ?Image
195  {
196  $responsive_logo = ilUtil::getImagePath("logo/HeaderIconResponsive.svg");
197 
198  return $this->ui->factory()->image()
199  ->standard($responsive_logo, $this->lang->txt('rep_main_page'))
200  ->withAction($this->getStartingPointAsUrl());
201  }
202 
203 
204  public function getFaviconPath(): string
205  {
206  return ilUtil::getImagePath("logo/favicon.ico");
207  }
208 
209  protected function getStartingPointAsUrl(): string
210  {
211  $std_logo_link = ilUserUtil::getStartingPointAsUrl();
212  if ($std_logo_link === '' || $std_logo_link === '0') {
213  return "./goto.php?target=root_1";
214  }
215  return $std_logo_link;
216  }
217 
218 
219  public function getSystemInfos(): array
220  {
221  $system_infos = [];
222 
223  foreach ($this->gs->collector()->notifications()->getAdministrativeNotifications() as $adn) {
224  $system_infos[] = $adn->getRenderer($this->ui->factory())->getNotificationComponentForItem($adn);
225  }
226 
227  return $system_infos;
228  }
229 
230 
231  public function getFooter(): ?Footer
232  {
233  $footer = $this->ui->factory()->mainControls()->footer();
234  $renderer_factory = new FooterRendererFactory($this->ui);
235  $collector = $this->gs->collector()->footer();
236 
237  $collector->collectOnce();
238 
239  foreach ($collector->getItemsForUIRepresentation() as $item) {
240  $footer = $renderer_factory->addToFooter($item, $footer);
241  }
242 
243  return $footer;
244  }
245 
246 
247  public function getTitle(): string
248  {
249  return 'title';
250  }
251 
252 
253  public function getShortTitle(): string
254  {
255  return 'short';
256  }
257 
258 
259  public function getViewTitle(): string
260  {
261  return 'view';
262  }
263 
264 
265  public function getToastContainer(): TContainer
266  {
267  $toast_container = $this->ui->factory()->toast()->container();
268 
269  foreach ($this->gs->collector()->toasts()->getToasts() as $toast) {
270  $renderer = $toast->getRenderer();
271  $toast_container = $toast_container->withAdditionalToast($renderer->getToastComponentForItem($toast));
272  }
273 
274  return $toast_container;
275  }
276 }
$renderer
This describes the MainBar.
Definition: MainBar.php:33
withAction(URI|Signal|string $action)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
global $DIC
Definition: shib_login.php:25
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This describes the MetaBar.
Definition: MetaBar.php:32
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...