ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSystemStyleOverviewGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
28 {
29  protected ilCtrl $ctrl;
31  protected ilLanguage $lng;
37  protected Factory $ui_factory;
38  protected Renderer $renderer;
40  protected Refinery $refinery;
42  protected ilTabsGUI $tabs;
43  protected ilHelpGUI $help;
44  protected FileUpload $upload;
45  protected string $ref_id;
46  protected bool $read_only = true;
47  protected bool $management_enabled = false;
48 
49  protected string $style_id;
50 
51  public function __construct(
52  ilCtrl $ctrl,
53  ilLanguage $lng,
55  Factory $ui_factory,
56  Renderer $renderer,
57  WrapperFactory $request_wrapper,
58  ilToolbarGUI $toolbar,
59  Refinery $refinery,
60  ilSkinFactory $skin_factory,
61  FileUpload $upload,
62  ilTabsGUI $tabs,
63  ilHelpGUI $help,
64  string $skin_id,
65  string $style_id,
66  string $ref_id,
67  bool $read_only,
68  bool $management_enabled
69  ) {
70  $this->ctrl = $ctrl;
71  $this->lng = $lng;
72  $this->tpl = $tpl;
73  $this->ui_factory = $ui_factory;
74  $this->renderer = $renderer;
75  $this->request_wrapper = $request_wrapper;
76  $this->toolbar = $toolbar;
77  $this->refinery = $refinery;
78  $this->tabs = $tabs;
79  $this->style_id = $style_id;
80  $this->message_stack = new ilSystemStyleMessageStack($this->tpl);
81  $this->skin_factory = $skin_factory;
82  $this->style_container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
83  $this->help = $help;
84  $this->ref_id = $ref_id;
85  $this->file_system = new ilFileSystemHelper($this->lng, $this->message_stack);
86  $this->upload = $upload;
87  $this->config = new ilSystemStyleConfig();
88  $this->setReadOnly($read_only);
89  $this->setManagementEnabled($management_enabled);
90  }
91 
92  public function executeCommand(): void
93  {
94  $cmd = $this->ctrl->getCmd();
95 
96  if ($cmd == '') {
97  $cmd = $this->isReadOnly() ? 'view' : 'edit';
98  }
99 
100  switch ($cmd) {
101  case 'addSystemStyle':
102  case 'addSubStyle':
103  case 'saveNewSystemStyle':
104  case 'saveNewSubStyle':
105  case 'copyStyle':
106  case 'importStyle':
107  case 'deleteStyles':
108  case 'deleteStyle':
109  case 'confirmDelete':
110  if (!$this->isManagementEnabled()) {
111  throw new ilObjectException($this->lng->txt('permission_denied'));
112  }
113  $this->$cmd();
114  break;
115  case 'cancel':
116  case 'edit':
117  case 'export':
118  case 'moveUserStyles':
119  case 'saveStyleSettings':
120  if ($this->isReadOnly()) {
121  throw new ilObjectException($this->lng->txt('permission_denied'));
122  }
123  $this->$cmd();
124  break;
125  case 'view':
126  $this->$cmd();
127  break;
128 
129  }
130  $this->message_stack->sendMessages();
131  }
132 
133  protected function view(): void
134  {
135  $table = new ilSystemStylesTableGUI($this, 'edit');
136  $this->tpl->setContent($table->getHTML());
137  }
138 
139  protected function cancel(): void
140  {
141  $this->edit();
142  }
143 
144  public function edit(): void
145  {
146  if ($this->isManagementEnabled()) {
147  // Add Button for adding skins
148  $this->toolbar->addComponent($this->ui_factory->button()->standard(
149  $this->lng->txt('add_system_style'),
150  $this->ctrl->getLinkTarget($this, 'addSystemStyle')
151  ));
152 
153  // Add Button for adding sub styles
154  $add_sub = $this->ui_factory->button()->standard(
155  $this->lng->txt('add_substyle'),
156  $this->ctrl->getLinkTarget($this, 'addSubStyle')
157  );
158  if (count(ilStyleDefinition::getAllSkins()) == 1) {
159  $add_sub = $add_sub->withUnavailableAction();
160  }
161  $this->toolbar->addComponent($add_sub);
162  $this->toolbar->addSeparator();
163  }
164 
165  // from styles selector
166  $si = new ilSelectInputGUI(
167  $this->lng->txt('sty_move_user_styles') . ': ' . $this->lng->txt('sty_from'),
168  'from_style'
169  );
170 
171  $options = [];
172  foreach (ilStyleDefinition::getAllSkinStyles() as $id => $skin_style) {
173  if (!$skin_style['substyle_of']) {
174  $options[$id] = $skin_style['title'];
175  }
176  }
177  $si->setOptions($options + ['other' => $this->lng->txt('other')]);
178 
179  $this->toolbar->addInputItem($si, true);
180 
181  $si = new ilSelectInputGUI($this->lng->txt('sty_to'), 'to_style');
182  $si->setOptions($options);
183  $this->toolbar->addInputItem($si, true);
184  $this->toolbar->addComponent($this->ui_factory->button()->standard($this->lng->txt('sty_move_style'), ''));
185 
186  $this->toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'moveUserStyles'));
187 
188  $table = new ilSystemStylesTableGUI($this, 'edit');
189  $table->addActions($this->isManagementEnabled());
190  $this->tpl->setContent($table->getHTML());
191  }
192 
193  public function moveUserStyles(): void
194  {
195  $to = $this->request_wrapper->post()->retrieve('to_style', $this->refinery->string()->splitString(':'));
196 
197  $from_style = $this->request_wrapper->post()->retrieve('from_style', $this->refinery->kindlyTo()->string());
198 
199  if ($from_style == 'other') {
200  // get all user assigned styles
201  $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
202 
203  // move users that are not assigned to
204  // currently existing style
205  foreach ($all_user_styles as $style) {
206  if (!ilStyleDefinition::styleExists($style)) {
207  $style_arr = explode(':', $style);
208  ilObjUser::_moveUsersToStyle($style_arr[0], $style_arr[1], $to[0], $to[1]);
209  }
210  }
211  } else {
212  $from = explode(':', $from_style);
213  ilObjUser::_moveUsersToStyle($from[0], $from[1], $to[0], $to[1]);
214  }
215 
216  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_obj_modified')));
217  $this->edit();
218  }
219 
220  public function saveStyleSettings(): void
221  {
222  $active_styles = $this->request_wrapper->post()->retrieve('st_act', $this->refinery->identity());
223 
224  if ($this->checkStyleSettings($this->message_stack, $active_styles)) {
225  $all_styles = ilStyleDefinition::getAllSkinStyles();
226  foreach ($all_styles as $style) {
227  if (!isset($active_styles[$style['id']])) {
228  ilSystemStyleSettings::_deactivateStyle($style['template_id'], $style['style_id']);
229  } else {
230  ilSystemStyleSettings::_activateStyle($style['template_id'], $style['style_id']);
231  }
232  }
233 
234  //set default skin and style
235  if ($this->request_wrapper->post()->has('default_skin_style')) {
236  $sknst = $this->request_wrapper->post()->retrieve(
237  'default_skin_style',
238  $this->refinery->string()->splitString(':')
239  );
240  ilSystemStyleSettings::setCurrentDefaultStyle($sknst[0], $sknst[1]);
241  }
242  $this->message_stack->addMessage(new ilSystemStyleMessage(
243  $this->lng->txt('msg_obj_modified'),
245  ));
246  }
247  $this->message_stack->sendMessages();
248  $this->ctrl->redirect($this, 'edit');
249  }
250 
251  protected function checkStyleSettings(ilSystemStyleMessageStack $message_stack, array $active_styles): bool
252  {
253  $passed = true;
254 
255  if (count($active_styles) < 1) {
256  $passed = false;
257  $message_stack->addMessage(new ilSystemStyleMessage(
258  $this->lng->txt('at_least_one_style'),
260  ));
261  }
262 
263  $default_style = $this->request_wrapper->post()->retrieve(
264  'default_skin_style',
265  $this->refinery->kindlyTo()->string()
266  );
267 
268  if (!isset($active_styles[$default_style])) {
269  $passed = false;
270  $message_stack->addMessage(new ilSystemStyleMessage(
271  $this->lng->txt('cant_deactivate_default_style'),
273  ));
274  }
275 
276  // check if a style should be deactivated, that still has
277  // a user assigned to
278  $all_styles = ilStyleDefinition::getAllSkinStyles();
279 
280  foreach ($all_styles as $style) {
281  if (!isset($active_styles[$style['id']])) {
282  if (ilObjUser::_getNumberOfUsersForStyle($style['template_id'], $style['style_id']) > 0) {
283  $passed = false;
284  $message_stack->addMessage(new ilSystemStyleMessage(
285  $style['style_name'] . ': ' . $this->lng->txt('cant_deactivate_if_users_assigned'),
287  ));
288  }
289  }
290  }
291  return $passed;
292  }
293 
294  protected function addSystemStyle(): void
295  {
296  $this->addSystemStyleForms();
297  }
298 
299  protected function saveNewSystemStyle(): void
300  {
301  $form = $this->createSystemStyleForm();
302 
303  if ($form->checkInput()) {
304  $skin_id = $this->request_wrapper->post()->retrieve('skin_id', $this->refinery->kindlyTo()->string());
305  $style_id = $this->request_wrapper->post()->retrieve('style_id', $this->refinery->kindlyTo()->string());
306 
307  $skin_name = $this->request_wrapper->post()->retrieve('skin_name', $this->refinery->kindlyTo()->string());
308  $style_name = $this->request_wrapper->post()->retrieve('style_name', $this->refinery->kindlyTo()->string());
309 
310  if (ilStyleDefinition::skinExists($skin_id)) {
311  $this->message_stack->addMessage(new ilSystemStyleMessage(
312  $this->lng->txt('skin_id_exists'),
314  ));
315  } else {
316  try {
317  $skin = new ilSkin($skin_id, $skin_name);
318  $style = new ilSkinStyle($style_id, $style_name);
319  $skin->addStyle($style);
320  $container = new ilSkinStyleContainer($this->lng, $skin, $this->message_stack);
321  $container->create($this->message_stack);
322  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $skin->getId());
323  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $style->getId());
324  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_sys_style_created')));
325  $this->message_stack->sendMessages();
326  $this->ctrl->redirectByClass('ilSystemStyleSettingsGUI');
327  } catch (ilSystemStyleException $e) {
328  $this->message_stack->addMessage(new ilSystemStyleMessage(
329  $e->getMessage(),
331  ));
332  }
333  }
334  }
335 
336  // display only this form to correct input
337  $form->setValuesByPost();
338  $this->tpl->setContent($form->getHTML());
339  }
340 
341  protected function addSystemStyleForms(): void
342  {
343  $this->tabs->clearTargets();
347  $this->help->setScreenIdComponent('sty');
348  $this->help->setScreenId('system_styles');
349  $this->help->setSubScreenId('create');
350 
351  $forms = [];
352 
353  $forms[] = $this->createSystemStyleForm();
354  $forms[] = $this->importSystemStyleForm();
355  $forms[] = $this->cloneSystemStyleForm();
356 
357  $this->tpl->setContent($this->getCreationFormsHTML($forms));
358  }
359 
361  {
362  $form = new ilPropertyFormGUI();
363  $form->setFormAction($this->ctrl->getFormAction($this));
364  $form->setTitle($this->lng->txt('sty_create_new_system_style'));
365 
366  $ti = new ilTextInputGUI($this->lng->txt('skin_id'), 'skin_id');
367  $ti->setInfo($this->lng->txt('skin_id_description'));
368  $ti->setMaxLength(128);
369  $ti->setSize(40);
370  $ti->setRequired(true);
371  $form->addItem($ti);
372 
373  $ti = new ilTextInputGUI($this->lng->txt('skin_name'), 'skin_name');
374  $ti->setInfo($this->lng->txt('skin_name_description'));
375  $ti->setMaxLength(128);
376  $ti->setSize(40);
377  $ti->setRequired(true);
378  $form->addItem($ti);
379 
380  $ti = new ilTextInputGUI($this->lng->txt('style_id'), 'style_id');
381  $ti->setInfo($this->lng->txt('style_id_description'));
382  $ti->setMaxLength(128);
383  $ti->setSize(40);
384  $ti->setRequired(true);
385  $form->addItem($ti);
386 
387  $ti = new ilTextInputGUI($this->lng->txt('style_name'), 'style_name');
388  $ti->setInfo($this->lng->txt('style_name_description'));
389  $ti->setMaxLength(128);
390  $ti->setSize(40);
391  $ti->setRequired(true);
392  $form->addItem($ti);
393 
394  $form->addCommandButton('saveNewSystemStyle', $this->lng->txt('save'));
395  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
396 
397  return $form;
398  }
399 
401  {
402  $form = new ilPropertyFormGUI();
403  $form->setFormAction($this->ctrl->getFormAction($this, 'importStyle'));
404  $form->setTitle($this->lng->txt('sty_import_system_style'));
405 
406  // title
407  $file_input = new ilFileInputGUI($this->lng->txt('import_file'), 'importfile');
408  $file_input->setRequired(true);
409  $file_input->setSuffixes(['zip']);
410  $form->addItem($file_input);
411 
412  $form->addCommandButton('importStyle', $this->lng->txt('import'));
413  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
414 
415  return $form;
416  }
417 
419  {
420  $form = new ilPropertyFormGUI();
421  $form->setFormAction($this->ctrl->getFormAction($this));
422  $form->setTitle($this->lng->txt('sty_copy_other_system_style'));
423 
424  // source
425  $ti = new ilSelectInputGUI($this->lng->txt('sty_source'), 'source_style');
426  $ti->setRequired(true);
428  $options = [];
429  foreach ($styles as $id => $style) {
430  $system_style_conf = new ilSystemStyleConfig();
431  if ($style['skin_id'] != $system_style_conf->getDefaultSkinId()) {
432  $options[$id] = $style['title'];
433  }
434  }
435  $ti->setOptions($options);
436 
437  $form->addItem($ti);
438 
439  $form->addCommandButton('copyStyle', $this->lng->txt('copy'));
440  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
441 
442  return $form;
443  }
444 
445  protected function getCreationFormsHTML(array $a_forms): string
446  {
447  include_once('./Services/Accordion/classes/class.ilAccordionGUI.php');
448 
449  $acc = new ilAccordionGUI();
450  $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
451  $cnt = 1;
452  foreach ($a_forms as $form_type => $cf) {
456  $htpl = new ilTemplate('tpl.creation_acc_head.html', true, true, 'Services/Object');
457 
458  // using custom form titles (used for repository plugins)
459  $form_title = '';
460  if (method_exists($this, 'getCreationFormTitle')) {
461  $form_title = $this->getCreationFormTitle($form_type);
462  }
463  if (!$form_title) {
464  $form_title = $cf->getTitle();
465  }
466 
467  // move title from form to accordion
468  $htpl->setVariable('TITLE', $this->lng->txt('option') . ' ' . $cnt . ': ' .
469  $form_title);
470  $cf->setTitle('');
471  $cf->setTitleIcon('');
472  $cf->setTableWidth('100%');
473 
474  $acc->addItem($htpl->get(), $cf->getHTML());
475 
476  $cnt++;
477  }
478 
479  return "<div class='ilCreationFormSection'>" . $acc->getHTML() . '</div>';
480  }
481 
482  protected function copyStyle(): void
483  {
484  $imploded_skin_style_id = $this->request_wrapper->post()->retrieve(
485  'source_style',
486  $this->refinery->string()->splitString(':')
487  );
488  $skin_id = $imploded_skin_style_id[0];
489  $style_id = $imploded_skin_style_id[1];
490 
491  try {
492  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
493  $new_container = $this->skin_factory->copyFromSkinStyleContainer(
494  $container,
495  $this->file_system,
496  $this->message_stack,
497  $this->lng->txt('sty_acopy')
498  );
499  $this->message_stack->prependMessage(new ilSystemStyleMessage(
500  $this->lng->txt('style_copied'),
502  ));
503  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $new_container->getSkin()->getId());
504  $this->ctrl->setParameterByClass(
505  'ilSystemStyleSettingsGUI',
506  'style_id',
507  $new_container->getSkin()->getStyle($style_id)->getId()
508  );
509  $this->message_stack->addMessage(new ilSystemStyleMessage(
510  $this->lng->txt('directory_created') . ' ' . $new_container->getSkinDirectory(),
512  ));
513  } catch (Exception $e) {
514  $this->message_stack->addMessage(new ilSystemStyleMessage(
515  $e->getMessage(),
517  ));
518  }
519  $this->message_stack->sendMessages();
520  $this->ctrl->redirectByClass('ilSystemStyleSettingsGUI');
521  }
522 
523  protected function deleteStyle(): void
524  {
525  $skin_id = $this->style_container->getSkin()->getId();
526  $style_id = $this->style_id;
527 
528  if ($this->checkDeletable($skin_id, $style_id, $this->message_stack)) {
529  $delete_form_table = new ilSystemStyleDeleteGUI($this->lng, $this->ctrl);
530  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
531  $delete_form_table->addStyle(
532  $container->getSkin(),
533  $container->getSkin()->getStyle($style_id),
534  $container->getImagesSkinPath($style_id) . '/icon_stys.svg'
535  );
536  $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
537  } else {
538  $this->message_stack->prependMessage(new ilSystemStyleMessage(
539  $this->lng->txt('style_not_deleted'),
541  ));
542  $this->edit();
543  }
544  }
545 
546  protected function deleteStyles(): void
547  {
548  $delete_form_table = new ilSystemStyleDeleteGUI($this->lng, $this->ctrl);
549 
550  $all_deletable = true;
551 
552  $skin_ids = $this->request_wrapper->post()->retrieve('id', $this->refinery->identity());
553  foreach ($skin_ids as $skin_style_id) {
554  $imploded_skin_style_id = explode(':', $skin_style_id);
555  $skin_id = $imploded_skin_style_id[0];
556  $style_id = $imploded_skin_style_id[1];
557  if (!$this->checkDeletable($skin_id, $style_id, $this->message_stack)) {
558  $all_deletable = false;
559  }
560  }
561  if ($all_deletable) {
562  foreach ($skin_ids as $skin_style_id) {
563  $imploded_skin_style_id = explode(':', $skin_style_id);
564  $skin_id = $imploded_skin_style_id[0];
565  $style_id = $imploded_skin_style_id[1];
566  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
567  $delete_form_table->addStyle(
568  $container->getSkin(),
569  $container->getSkin()->getStyle($style_id),
570  $container->getImagesSkinPath($style_id) . '/icon_stys.svg'
571  );
572  }
573  $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
574  } else {
575  $this->message_stack->prependMessage(new ilSystemStyleMessage(
576  $this->lng->txt('styles_not_deleted'),
578  ));
579  $this->edit();
580  }
581  }
582 
583  protected function checkDeletable(
584  string $skin_id,
585  string $style_id,
586  ilSystemStyleMessageStack $message_stack
587  ): bool {
588  $passed = true;
589  if (ilObjUser::_getNumberOfUsersForStyle($skin_id, $style_id) > 0) {
590  $message_stack->addMessage(new ilSystemStyleMessage(
591  $style_id . ': ' . $this->lng->txt('cant_delete_if_users_assigned'),
593  ));
594  $passed = false;
595  }
596  if (ilSystemStyleSettings::_lookupActivatedStyle($skin_id, $style_id) > 0) {
597  $message_stack->addMessage(new ilSystemStyleMessage(
598  $style_id . ': ' . $this->lng->txt('cant_delete_activated_style'),
600  ));
601  $passed = false;
602  }
604  $message_stack->addMessage(new ilSystemStyleMessage(
605  $style_id . ': ' . $this->lng->txt('cant_delete_default_style'),
607  ));
608  $passed = false;
609  }
610 
611  if ($this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack)->getSkin()->getSubstylesOfStyle($style_id)) {
612  $message_stack->addMessage(new ilSystemStyleMessage(
613  $style_id . ': ' . $this->lng->txt('cant_delete_style_with_substyles'),
615  ));
616  $passed = false;
617  }
618  return $passed;
619  }
620 
621  protected function confirmDelete(): void
622  {
623  $i = 0;
624  while ($this->request_wrapper->post()->has('style_' . $i)) {
625  try {
626  $skin_style_id = $this->request_wrapper->post()->retrieve(
627  'style_' . $i,
628  $this->refinery->string()->splitString(':')
629  );
630  $container = $this->skin_factory->skinStyleContainerFromId($skin_style_id[0], $this->message_stack);
631  $syle = $container->getSkin()->getStyle($skin_style_id[1]);
632  $container->deleteStyle($syle);
633  if (!$container->getSkin()->hasStyles()) {
634  $container->delete();
635  }
636  } catch (Exception $e) {
637  $this->message_stack->addMessage(new ilSystemStyleMessage(
638  $e->getMessage(),
640  ));
641  }
642  $i++;
643  }
644  $this->message_stack->sendMessages();
645  $this->ctrl->redirect($this);
646  }
647 
648  protected function importStyle(): void
649  {
650  $form = $this->importSystemStyleForm();
651 
652  if ($form->checkInput() && $this->upload->hasUploads()) {
654  $result = array_values($this->upload->getResults())[0];
655 
656  $this->upload->moveOneFileTo(
657  $result,
658  'global/skin',
659  ILIAS\FileUpload\Location::CUSTOMIZING,
660  $result->getName(),
661  true
662  );
663  $imported_container = $this->skin_factory->skinStyleContainerFromZip(
664  $this->config->getCustomizingSkinPath() . $result->getName(),
665  $result->getName(),
667  );
668  $this->ctrl->setParameterByClass(
669  'ilSystemStyleSettingsGUI',
670  'skin_id',
671  $imported_container->getSkin()->getId()
672  );
673  $this->ctrl->setParameterByClass(
674  'ilSystemStyleSettingsGUI',
675  'style_id',
676  $imported_container->getSkin()->getDefaultStyle()->getId()
677  );
678  $this->message_stack->addMessage(new ilSystemStyleMessage(
679  $this->lng->txt('style_imported') . ' ' . $imported_container->getSkinDirectory(),
681  ));
682  $this->message_stack->sendMessages();
683  $this->ctrl->redirectByClass('ilSystemStyleSettingsGUI');
684  }
685  // display only this form to correct input
686  $form->setValuesByPost();
687  $this->tpl->setContent($form->getHTML());
688  }
689 
690  protected function export(): void
691  {
692  $container = $this->skin_factory->skinStyleContainerFromId($this->style_container->getSkin()->getId(), $this->message_stack);
693  try {
694  $container->export();
695  } catch (Exception $e) {
696  $this->message_stack->addMessage(new ilSystemStyleMessage(
697  $this->lng->txt('zip_export_failed') . ' ' . $e->getMessage(),
699  ));
700  }
701  }
702 
706  protected function addSubStyle(): void
707  {
708  $this->tabs->clearTargets();
712  $this->help->setScreenIdComponent('sty');
713  $this->help->setScreenId('system_styles');
714  $this->help->setSubScreenId('create_sub');
715 
716  $form = $this->addSubStyleForms();
717 
718  $this->tpl->setContent($form->getHTML());
719  }
720 
721  protected function addSubStyleForms(): ilPropertyFormGUI
722  {
723  $form = new ilPropertyFormGUI();
724  $form->setFormAction($this->ctrl->getFormAction($this));
725  $form->setTitle($this->lng->txt('sty_create_new_system_sub_style'));
726 
727  $ti = new ilTextInputGUI($this->lng->txt('sub_style_id'), 'sub_style_id');
728  $ti->setInfo($this->lng->txt('sub_style_id_description'));
729  $ti->setMaxLength(128);
730  $ti->setSize(40);
731  $ti->setRequired(true);
732  $form->addItem($ti);
733 
734  $ti = new ilTextInputGUI($this->lng->txt('sub_style_name'), 'sub_style_name');
735  $ti->setInfo($this->lng->txt('sub_style_name_description'));
736  $ti->setMaxLength(128);
737  $ti->setSize(40);
738  $ti->setRequired(true);
739  $form->addItem($ti);
740 
741  // source
742  $ti = new ilSelectInputGUI($this->lng->txt('parent'), 'parent_style');
743  $ti->setRequired(true);
744  $ti->setInfo($this->lng->txt('sub_style_parent_style_description'));
746  $options = [];
747  foreach ($styles as $id => $style) {
748  $system_style_conf = new ilSystemStyleConfig();
749  if ($style['skin_id'] != $system_style_conf->getDefaultSkinId() && !$style['substyle_of']) {
750  $options[$id] = $style['title'];
751  }
752  }
753  $ti->setOptions($options);
754 
755  $form->addItem($ti);
756  $form->addCommandButton('saveNewSubStyle', $this->lng->txt('save'));
757  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
758 
759  return $form;
760  }
761 
762  protected function saveNewSubStyle(): void
763  {
764  $form = $this->addSubStyleForms();
765 
766  if ($form->checkInput()) {
767  try {
768  $skin_style_ids = $this->request_wrapper->post()->retrieve(
769  'parent_style',
770  $this->refinery->string()->splitString(':')
771  );
772 
773  $parent_skin_id = $skin_style_ids[0];
774  $parent_style_id = $skin_style_ids[1];
775 
776  $container = $this->skin_factory->skinStyleContainerFromId($parent_skin_id, $this->message_stack);
777 
778  $sub_style_id = $this->request_wrapper->post()->retrieve(
779  'sub_style_id',
780  $this->refinery->kindlyTo()->string()
781  );
782 
783  if (array_key_exists(
784  $sub_style_id,
785  $container->getSkin()->getSubstylesOfStyle($parent_style_id)
786  )) {
787  throw new ilSystemStyleException(
789  $sub_style_id
790  );
791  }
792 
793  $sub_style_name = $this->request_wrapper->post()->retrieve(
794  'sub_style_name',
795  $this->refinery->kindlyTo()->string()
796  );
797 
798  $style = new ilSkinStyle($sub_style_id, $sub_style_name);
799  $style->setSubstyleOf($parent_style_id);
800  $container->addStyle($style);
801 
802  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $parent_skin_id);
803  $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $sub_style_id);
804  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_sub_style_created')));
805  $this->message_stack->sendMessages();
806  $this->ctrl->redirectByClass('ilSystemStyleSettingsGUI');
807  } catch (ilSystemStyleException $e) {
808  $this->message_stack->addMessage(new ilSystemStyleMessage(
809  $e->getMessage(),
811  ));
812  }
813  }
814 
815  // display only this form to correct input
816  $form->setValuesByPost();
817  $this->tpl->setContent($form->getHTML());
818  }
819 
820  public function isReadOnly(): bool
821  {
822  return $this->read_only;
823  }
824 
825  public function setReadOnly(bool $read_only): void
826  {
827  $this->read_only = $read_only;
828  }
829 
830  public function isManagementEnabled(): bool
831  {
833  }
834 
835  public function setManagementEnabled(bool $management_enabled): void
836  {
837  $this->management_enabled = $management_enabled;
838  }
839 }
An entity that renders components to a string output.
Definition: Renderer.php:30
static _lookupActivatedStyle(string $a_skin, string $a_style)
lookup if a style is activated
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static styleExists(string $style_id)
static getCurrentDefaultSkin()
Gets default Skin of the System.
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
This class represents a file property in a property form.
Class ChatMainBarProvider .
static _moveUsersToStyle(string $a_from_skin, string $a_from_style, string $a_to_skin, string $a_to_style)
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
File System Helper, to reduce deps.
setOptions(array $a_options)
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
static _deactivateStyle(string $a_skin, string $a_style)
deactivate system style
$container
Definition: wac.php:14
static _getNumberOfUsersForStyle(string $a_skin, string $a_style)
static _activateStyle(string $a_skin, string $a_style)
activate system style
This class is responsible for all file system related actions related actions of a skin such as copyi...
static getAllSkinStyles()
Get all skins/styles as array (convenient for tables) Attention: tempalte_name/template_id in this ar...
skinStyleContainerFromId(string $skin_id, ilSystemStyleMessageStack $message_stack)
Get container class is responsible for all file system related actions related actions of a skin such...
static setCurrentDefaultStyle(string $skin_id, string $style_id)
Sets the default style of the system.
Class FileUpload.
Definition: FileUpload.php:34
setRequired(bool $a_required)
checkStyleSettings(ilSystemStyleMessageStack $message_stack, array $active_styles)
ilSystemStyleConfig wraps all &#39;constants&#39; to ensure the testability of all classes using those &#39;const...
__construct(ilCtrl $ctrl, ilLanguage $lng, ilGlobalTemplateInterface $tpl, Factory $ui_factory, Renderer $renderer, WrapperFactory $request_wrapper, ilToolbarGUI $toolbar, Refinery $refinery, ilSkinFactory $skin_factory, FileUpload $upload, ilTabsGUI $tabs, ilHelpGUI $help, string $skin_id, string $style_id, string $ref_id, bool $read_only, bool $management_enabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static skinExists(string $skin_id, ?ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
ilSystemStyleMessageStack $message_stack
Used to stack messages to be shown to the user.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
TableGUI class for system styles.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setManagementEnabled(bool $management_enabled)
static _getAllUserAssignedStyles()
checkDeletable(string $skin_id, string $style_id, ilSystemStyleMessageStack $message_stack)
$i
Definition: metadata.php:41
ilSkin holds an manages the basic data of a skin as provide by the template of the skin...