ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSystemStyleMainGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
37 {
38  protected ilCtrl $ctrl;
39  protected ilLanguage $lng;
40  protected ilTabsGUI $tabs;
42  protected string $ref_id;
44  protected ilHelpGUI $help;
45  protected Factory $ui_factory;
46  protected Renderer $renderer;
47  protected ilIniFile $ilIniFile;
52  protected ServerRequestInterface $request;
55  protected FileUpload $upload;
56  protected ilTree $tree;
57  protected ilObjUser $user;
59 
60  public function __construct()
61  {
65  global $DIC;
66 
67  $this->ctrl = $DIC->ctrl();
68  $this->lng = $DIC->language();
69  $this->tabs = $DIC->tabs();
70  $this->rbacsystem = $DIC->rbac()->system();
71  $this->tpl = $DIC->ui()->mainTemplate();
72  $this->help = $DIC->help();
73  $this->ui_factory = $DIC->ui()->factory();
74  $this->renderer = $DIC->ui()->renderer();
75  $this->locator = $DIC['ilLocator'];
76  $this->ilIniFile = $DIC->iliasIni();
77  $this->global_screen = $DIC->globalScreen();
78  $this->request_wrapper = $DIC->http()->wrapper();
79  $this->refinery = $DIC->refinery();
80  $this->request = $DIC->http()->request();
81  $this->toolbar = $DIC->toolbar();
82  $this->upload = $DIC->upload();
83  $this->tree = $DIC->repositoryTree();
84  $this->skin_factory = new ilSkinFactory($this->lng);
85  $this->user = $DIC->user();
86 
87  $this->message_stack = new ilSystemStyleMessageStack($this->tpl);
88  $this->ref_id = $this->request_wrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->string());
89  }
90 
95  public function executeCommand(): void
96  {
97  $next_class = $this->ctrl->getNextClass($this);
98 
99  $this->help->setScreenIdComponent('sty');
100  $this->help->setScreenId('system_styles');
101 
102  $config = new ilSystemStyleConfig();
103  $skin_factory = new ilSkinFactory($this->lng);
104 
105  if ($this->request_wrapper->query()->has('skin_id') && $this->request_wrapper->query()->has('style_id')) {
106  $skin_id = $this->request_wrapper->query()->retrieve('skin_id', $this->refinery->kindlyTo()->string());
107  $style_id = $this->request_wrapper->query()->retrieve('style_id', $this->refinery->kindlyTo()->string());
108  } else {
109  $skin_id = $config->getDefaultSkinId();
110  $style_id = $config->getDefaultStyleId();
111  }
112 
113  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'skin_id', $skin_id);
114  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'style_id', $style_id);
115  $this->ctrl->setParameterByClass(ilSystemStyleScssGUI::class, 'skin_id', $skin_id);
116  $this->ctrl->setParameterByClass(ilSystemStyleScssGUI::class, 'style_id', $style_id);
117  $this->ctrl->setParameterByClass(ilSystemStyleIconsGUI::class, 'skin_id', $skin_id);
118  $this->ctrl->setParameterByClass(ilSystemStyleIconsGUI::class, 'style_id', $style_id);
119  $this->ctrl->setParameterByClass(ilSystemStyleDocumentationGUI::class, 'skin_id', $skin_id);
120  $this->ctrl->setParameterByClass(ilSystemStyleDocumentationGUI::class, 'style_id', $style_id);
121 
122  try {
123  switch ($next_class) {
124  case strtolower(ilSystemStyleConfigGUI::class):
125  $this->help->setSubScreenId('settings');
126  $this->checkPermission('sty_management');
127  $this->setUnderworldTabs($skin_id, 'settings');
128  $this->setUnderworldTitle($skin_id, $style_id);
129  $system_styles_settings = new ilSystemStyleConfigGUI(
130  $this->ctrl,
131  $this->lng,
132  $this->tpl,
133  $this->tabs,
134  $this->ui_factory,
135  $this->renderer,
136  $skin_factory,
137  $this->request_wrapper,
138  $this->refinery,
139  $this->toolbar,
140  $this->user,
141  $this->request,
142  $this->tree,
143  $skin_id,
144  $style_id
145  );
146  $this->ctrl->forwardCommand($system_styles_settings);
147  break;
148  case strtolower(ilSystemStyleScssGUI::class):
149  $this->help->setSubScreenId('scss');
150  $this->checkPermission('sty_management');
151  $this->setUnderworldTabs($skin_id, 'scss');
152  $this->setUnderworldTitle($skin_id, $style_id);
153  $system_styles_scss = new ilSystemStyleScssGUI(
154  $this->ctrl,
155  $this->lng,
156  $this->tpl,
157  $this->ui_factory,
158  $this->renderer,
159  $this->request,
160  $this->toolbar,
161  $this->refinery,
162  $skin_factory,
163  $skin_id,
164  $style_id
165  );
166  $this->ctrl->forwardCommand($system_styles_scss);
167  break;
168  case strtolower(ilSystemStyleIconsGUI::class):
169  $this->help->setSubScreenId('icons');
170  $this->checkPermission('sty_management');
171  $this->setUnderworldTabs($skin_id, 'icons');
172  $this->setUnderworldTitle($skin_id, $style_id);
173  $system_styles_icons = new ilSystemStyleIconsGUI(
174  $this->ctrl,
175  $this->lng,
176  $this->tpl,
177  $this->ui_factory,
178  $this->renderer,
179  $this->request_wrapper,
180  $this->toolbar,
181  $this->refinery,
182  $skin_factory,
183  $this->tabs,
184  $this->upload,
185  $skin_id,
186  $style_id
187  );
188  $this->ctrl->forwardCommand($system_styles_icons);
189  break;
190  case strtolower(ilSystemStyleDocumentationGUI::class):
191  $this->help->setSubScreenId('documentation');
192  $read_only = !$this->checkPermission('sty_management', false);
193  $this->setUnderworldTabs($skin_id, 'documentation', $read_only);
194  $this->setUnderworldTitle($skin_id, $style_id, $read_only);
195  $node_id = '';
196  if ($this->request_wrapper->query()->has('node_id')) {
197  $node_id = $this->request_wrapper->query()->retrieve(
198  'node_id',
199  $this->refinery->kindlyTo()->string()
200  );
201  }
202  $goto_link = (new ilKSDocumentationGotoLink())->generateGotoLink($node_id, $skin_id, $style_id);
203  $this->global_screen->tool()->context()->current()->addAdditionalData(
205  true
206  );
207  $this->tpl->setPermanentLink('stys', (int) $this->ref_id, $goto_link);
208  $entries = new Entries();
209  $entries->addEntriesFromArray(include ilSystemStyleDocumentationGUI::DATA_PATH);
210  $documentation_gui = new ilSystemStyleDocumentationGUI(
211  $this->tpl,
212  $this->ctrl,
213  $this->ui_factory,
214  $this->renderer
215  );
216  $documentation_gui->show($entries, $node_id);
217  break;
218  case strtolower(ilSystemStyleOverviewGUI::class):
219  default:
220  $this->executeDefaultCommand($skin_factory, $skin_id, $style_id);
221  break;
222  }
223  } catch (ilObjectException $e) {
224  $this->message_stack->addMessage(new ilSystemStyleMessage(
225  $e->getMessage(),
227  ));
228  $this->message_stack->sendMessages();
229  $this->executeDefaultCommand($skin_factory, $skin_id, $style_id);
230  }
231  }
232 
233  protected function executeDefaultCommand(ilSkinFactory $skin_factory, string $skin_id, string $style_id): void
234  {
235  $this->help->setSubScreenId('overview');
236  $this->checkPermission('visible,read');
237  $read_only = !$this->checkPermission('sty_write_system', false);
238  $management_enabled = $this->checkPermission('sty_management', false);
239  $system_styles_overview = new ilSystemStyleOverviewGUI(
240  $this->ctrl,
241  $this->lng,
242  $this->tpl,
243  $this->ui_factory,
244  $this->renderer,
245  $this->request_wrapper,
246  $this->toolbar,
247  $this->refinery,
248  $skin_factory,
249  $this->upload,
250  $this->tabs,
251  $this->help,
252  $skin_id,
253  $style_id,
254  $this->ref_id,
255  $read_only,
256  $management_enabled
257  );
258 
259  $this->ctrl->forwardCommand($system_styles_overview);
260  }
261 
267  public function checkPermission(string $a_perm, bool $a_throw_exc = true): bool
268  {
269  $has_perm = true;
270 
271  $config = new ilSystemStyleConfig();
272  if ($a_perm == 'sty_management') {
273  $has_perm = $this->ilIniFile->readVariable('tools', 'enable_system_styles_management') == '1';
274  $a_perm = 'sty_write_system';
275  if ($has_perm && !is_writable($config->getCustomizingSkinPath())) {
276  $this->message_stack->addMessage(new ilSystemStyleMessage(
277  $this->lng->txt('enable_system_styles_management_no_write_perm'),
279  ));
280  $this->message_stack->sendMessages();
281  $has_perm = false;
282  }
283  }
284 
285  if ($has_perm) {
286  $has_perm = $this->rbacsystem->checkAccess($a_perm, (int) $this->ref_id);
287  }
288 
289  if (!$has_perm) {
290  if ($a_throw_exc) {
291  throw new ilObjectException($this->lng->txt('sty_permission_denied'));
292  }
293  return false;
294  }
295  return true;
296  }
297 
302  protected function setUnderworldTabs(string $sking_id, string $active = '', bool $read_only = false): void
303  {
304  $this->tabs->clearTargets();
305 
306  if ($read_only) {
307  $this->locator->clearItems();
308  $this->tpl->setLocator();
309  return;
310  }
311 
315  $this->help->setScreenIdComponent('sty');
316  $this->help->setScreenId('system_styles');
317  $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this));
318  $config = new ilSystemStyleConfig();
319  if ($sking_id != $config->getDefaultSkinId()) {
320  $this->tabs->addTab(
321  'settings',
322  $this->lng->txt('settings'),
323  $this->ctrl->getLinkTargetByClass('ilsystemstyleconfiggui')
324  );
325  $this->tabs->addTab(
326  'scss',
327  $this->lng->txt('scss'),
328  $this->ctrl->getLinkTargetByClass('ilsystemstylescssgui')
329  );
330  $this->tabs->addTab(
331  'icons',
332  $this->lng->txt('icons'),
333  $this->ctrl->getLinkTargetByClass('ilsystemstyleiconsgui')
334  );
335  }
336 
337  $this->tabs->addTab(
338  'documentation',
339  $this->lng->txt('documentation'),
340  $this->ctrl->getLinkTargetByClass(ilSystemStyleDocumentationGUI::class)
341  );
342 
343  $this->tabs->activateTab($active);
344  }
345 
350  protected function setUnderworldTitle(string $skin_id, string $style_id, bool $read_only = false): void
351  {
352  $skin = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack)->getSkin();
353  $style = $skin->getStyle($style_id);
354 
355  if ($read_only) {
356  $this->tpl->setTitle($this->lng->txt('documentation'));
357 
358  if ($style->isSubstyle()) {
359  $this->tpl->setDescription(
360  $this->lng->txt('ks_documentation_of_substyle')
361  . " '"
362  . $style->getName() . "' " .
363  $this->lng->txt('of_parent') . " '" . $skin->getStyle($style->getSubstyleOf())->getName() . "' " .
364  $this->lng->txt('from_skin') . ' ' . $skin->getName()
365  );
366  } else {
367  $this->tpl->setDescription(
368  $this->lng->txt('ks_documentation_of_style') . " '" . $style->getName() . "' " .
369  $this->lng->txt('from_skin') . " '" . $skin->getName() . "'"
370  );
371  }
372  } else {
373  $this->tpl->setTitle($style->getName());
374  if ($style->isSubstyle()) {
375  $this->tpl->setDescription(
376  $this->lng->txt('settings_of_substyle') . " '" . $style->getName() . "' " .
377  $this->lng->txt('of_parent') . " '" . $skin->getStyle($style->getSubstyleOf())->getName() . "' " .
378  $this->lng->txt('from_skin') . ' ' . $skin->getName()
379  );
380  } else {
381  $this->tpl->setDescription(
382  $this->lng->txt('settings_of_style') . " '" . $style->getName() . "' " .
383  $this->lng->txt('from_skin') . " '" . $skin->getName() . "'"
384  );
385  }
386  }
387  }
388 }
An entity that renders components to a string output.
Definition: Renderer.php:30
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
ilSystemStyleMessageStack $message_stack
Help GUI class.
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setUnderworldTitle(string $skin_id, string $style_id, bool $read_only=false)
Sets title correctly if one system style is opened.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setUnderworldTabs(string $sking_id, string $active='', bool $read_only=false)
Sets the tab correctly if one system style is open (navigational underworld opened) ...
__construct(VocabulariesInterface $vocabularies)
checkPermission(string $a_perm, bool $a_throw_exc=true)
Checks permission for system styles.
Class FileUpload.
Definition: FileUpload.php:34
Renders the Overview of the Examples in the Administration.
Settings UI class for system styles.
executeCommand()
Main routing of the system styles.
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Used to stack messages to be shown to the user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readVariable(string $a_group, string $a_var_name)
reads a single variable from a group
executeDefaultCommand(ilSkinFactory $skin_factory, string $skin_id, string $style_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ServerRequestInterface $request