ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
StandardPagePartProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 use ilUserUtil;
35 use ilUtil;
38 use ilLanguage;
40 
47 {
48  use isSupportedTrait;
50 
54  protected $content;
58  protected $gs;
62  protected $ui;
66  protected $lang;
67 
71  public function __construct()
72  {
73  global $DIC;
74  $this->ui = $DIC->ui();
75  $this->gs = $DIC->globalScreen();
76  $this->lang = $DIC->language();
77  }
78 
82  public function getContent() : ?Legacy
83  {
84  return $this->content ?? $this->ui->factory()->legacy("");
85  }
86 
90  public function getMetaBar() : ?MetaBar
91  {
92  $this->gs->collector()->metaBar()->collectOnce();
93  if (!$this->gs->collector()->metaBar()->hasItems()) {
94  return null;
95  }
96  $f = $this->ui->factory();
97  $meta_bar = $f->mainControls()->metaBar();
98 
99  foreach ($this->gs->collector()->metaBar()->getItemsForUIRepresentation() as $item) {
101  $component = $item->getRenderer()->getComponentForItem($item);
102  if ($this->isComponentSupportedForCombinedSlate($component)) {
103  $meta_bar = $meta_bar->withAdditionalEntry($item->getProviderIdentification()->getInternalIdentifier(), $component);
104  }
105  }
106 
107  return $meta_bar;
108  }
109 
113  public function getMainBar() : ?MainBar
114  {
115  // Collect all items which could be displayed in the main bar
116  $this->gs->collector()->mainmenu()->collectOnce();
117  $this->gs->collector()->tool()->collectOnce();
118 
119  // If there are no items to display, return null. By definition, no MainBar is added to the Page in this case.
120  if (!$this->gs->collector()->mainmenu()->hasVisibleItems()
121  && !$this->gs->collector()->tool()->hasVisibleItems()) {
122  return null;
123  }
124 
125  $f = $this->ui->factory();
126  $main_bar = $f->mainControls()->mainBar();
127 
128  foreach ($this->gs->collector()->mainmenu()->getItemsForUIRepresentation() as $item) {
132  $component = $item->getTypeInformation()->getRenderer()->getComponentForItem($item, false);
133  $identifier = $this->hash($item->getProviderIdentification()->serialize());
134 
135  if ($this->isComponentSupportedForCombinedSlate($component)) {
136  $main_bar = $main_bar->withAdditionalEntry($identifier, $component);
137  }
138  }
139 
140  // Tools
141  $grid_icon = $f->symbol()->icon()->custom(ilUtil::getImagePath("outlined/icon_tool.svg"), $this->lang->txt('more'));
142  if ($this->gs->collector()->tool()->hasItems()) {
143  $tools_button = $f->button()->bulky($grid_icon, $this->lang->txt('tools'), "#")->withEngagedState(true);
144  $main_bar = $main_bar->withToolsButton($tools_button);
148  foreach ($this->gs->collector()->tool()->getItemsForUIRepresentation() as $tool) {
150  if (!$tool instanceof isToolItem) {
151  continue;
152  }
153  $component = $tool->getTypeInformation()->getRenderer()->getComponentForItem($tool, false);
154 
155  $identifier = $this->hash($tool->getProviderIdentification()->serialize());
156  $close_button = null;
157  if ($tool->hasCloseCallback()) {
158  $close_button = $this->ui->factory()->button()->close()->withOnLoadCode(static function (string $id) use ($identifier) {
159  $key_item = CallbackHandler::KEY_ITEM;
160  return "$('#$id').on('click', function(){
161  $.ajax({
162  url: 'src/GlobalScreen/Client/callback_handler.php?$key_item=$identifier'
163  }).done(function() {
164  console.log('done closing');
165  });
166  });";
167  });
168  }
169  $main_bar = $main_bar->withAdditionalToolEntry($identifier, $component, $tool->isInitiallyHidden(), $close_button);
170  }
171  }
172 
173  return $main_bar;
174  }
175 
179  public function getBreadCrumbs() : ?Breadcrumbs
180  {
181  // TODO this currently gets the items from ilLocatorGUI, should that serve be removed with
182  // something like GlobalScreen\Scope\Locator\Item
183  global $DIC;
184 
185  $f = $this->ui->factory();
186  $crumbs = [];
187  foreach ($DIC['ilLocator']->getItems() as $item) {
188  if (empty($item['title']) || empty($item['link'])) {
189  continue;
190  }
191  $crumbs[] = $f->link()->standard($item['title'], $item["link"]);
192  }
193 
194  return $f->breadcrumbs($crumbs);
195  }
196 
200  public function getLogo() : ?Image
201  {
202  $std_logo = ilUtil::getImagePath("HeaderIcon.svg");
203 
204  return $this->ui->factory()->image()
205  ->standard($std_logo, $this->lang->txt('rep_main_page'))
206  ->withAction($this->getStartingPointAsUrl());
207  }
208 
212  public function getResponsiveLogo() : ?Image
213  {
214  $responsive_logo = ilUtil::getImagePath("HeaderIconResponsive.svg");
215 
216  return $this->ui->factory()->image()
217  ->standard($responsive_logo, $this->lang->txt('rep_main_page'))
218  ->withAction($this->getStartingPointAsUrl());
219  }
220 
221  protected function getStartingPointAsUrl() : string
222  {
223  $std_logo_link = ilUserUtil::getStartingPointAsUrl();
224  if (!$std_logo_link) {
225  $std_logo_link = "./goto.php?target=root_1";
226  }
227  return $std_logo_link;
228  }
229 
233  public function getSystemInfos() : array
234  {
235  $system_infos = [];
236 
237  foreach ($this->gs->collector()->notifications()->getAdministrativeNotifications() as $adn) {
238  $system_infos[] = $adn->getRenderer($this->ui->factory())->getNotificationComponentForItem($adn);
239  }
240 
241  return $system_infos;
242  }
243 
247  public function getFooter() : ?Footer
248  {
249  return $this->ui->factory()->mainControls()->footer([]);
250  }
251 
255  public function getTitle() : string
256  {
257  return 'title';
258  }
259 
263  public function getShortTitle() : string
264  {
265  return 'short';
266  }
267 
271  public function getViewTitle() : string
272  {
273  return 'view';
274  }
275 }
This describes the MainBar.
Definition: MainBar.php:16
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5
This describes the MetaBar.
Definition: MetaBar.php:14
This describes the Footer.
Definition: Footer.php:15