ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  $this->message_stack->sendMessages();
130  }
131 
132  protected function view(): void
133  {
134  $table = new ilSystemStylesTableGUI($this, 'edit');
135  $this->tpl->setContent($table->getHTML().$table->getModalsHtml());
136  }
137 
138  public function getAssignmentCreationModal(string $style_name = ""): ?\ILIAS\UI\Component\Modal\RoundTrip
139  {
140  $options = [];
141  foreach (ilStyleDefinition::getAllSkinStyles() as $id => $skin_style) {
142  if (!$skin_style['substyle_of'] && $style_name != $skin_style['style_name']) {
143  $options[$id] = $skin_style['title'];
144  }
145  }
146 
147  $default = "default:delos";
148  if($style_name == "Delos") {
149  $default = key($options);
150  }
151 
152  if(count($options) == 0) {
153  return null;
154  }
155 
156  $txt = $this->lng->txt('sty_move_user_styles').' '.$this->lng->txt('sty_to');
157 
158  $byline = $this->lng->txt('sty_move_user_styles') . ' ' .
159  $this->lng->txt('sty_from') . ' ' . $style_name;
160 
161  $select = $this->ui_factory->input()->field()
162  ->select($txt, $options, $byline)
163  ->withValue($default)
164  ->withAdditionalTransformation($this->refinery->string()->splitString(':'))
165  ->withRequired(true);
166 
167  return $this->ui_factory->modal()->roundtrip(
168  $this->lng->txt('change_assignment'),
169  [],
170  ["new_style" => $select],
171  $this->ctrl->getLinkTargetByClass(ilSystemStyleOverviewGUI::class, 'moveUserStyles')
172  );
173  }
174 
175  protected function cancel(): void
176  {
177  $this->edit();
178  }
179 
180  public function edit(): void
181  {
182  if ($this->isManagementEnabled()) {
183  // Add Button for adding skins
184  $this->toolbar->addComponent($this->ui_factory->button()->standard(
185  $this->lng->txt('add_system_style'),
186  $this->ctrl->getLinkTarget($this, 'addSystemStyle')
187  ));
188 
189  // Add Button for adding sub styles
190  $add_sub = $this->ui_factory->button()->standard(
191  $this->lng->txt('add_substyle'),
192  $this->ctrl->getLinkTarget($this, 'addSubStyle')
193  );
194  if (count(ilStyleDefinition::getAllSkins()) == 1) {
195  $add_sub = $add_sub->withUnavailableAction();
196  }
197  $this->toolbar->addComponent($add_sub);
198  }
199 
200  $table = new ilSystemStylesTableGUI($this, 'edit');
201  $table->addActions($this->isManagementEnabled());
202  $this->tpl->setContent($table->getHTML().$table->getModalsHtml());
203  }
204 
205  public function moveUserStyles(): void
206  {
207  global $DIC;
208 
209  $request = $DIC->http()->request();
210 
211  $modal = $this->getAssignmentCreationModal()->withRequest($request);
212  [$new_skin, $new_style] = $modal->getData()["new_style"];
213 
214  $old_skin = $this->request_wrapper->query()->retrieve('old_skin_id', $this->refinery->kindlyTo()->string());
215  $old_style = $this->request_wrapper->query()->retrieve('old_style_id', $this->refinery->kindlyTo()->string());
216 
217  if ($old_style == 'other') {
218  // get all user assigned styles
219  $all_user_styles = ilObjUser::_getAllUserAssignedStyles();
220 
221  // move users that are not assigned to
222  // currently existing style
223  foreach ($all_user_styles as $style) {
224  if (!ilStyleDefinition::styleExists($style)) {
225  [$old_skin, $old_style] = explode(':', $style);
226  ilObjUser::_moveUsersToStyle($old_skin, $old_style, $new_skin, $new_style);
227  }
228  }
229  } else {
230  ilObjUser::_moveUsersToStyle($old_skin, $old_style, $new_skin, $new_style);
231  }
232 
233  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_obj_modified')));
234  $this->ctrl->redirect($this, 'edit');
235  }
236 
237  public function saveStyleSettings(): void
238  {
239  $active_styles = $this->request_wrapper->post()->retrieve('st_act', $this->refinery->identity());
240 
241  if ($this->checkStyleSettings($this->message_stack, $active_styles)) {
242  $all_styles = ilStyleDefinition::getAllSkinStyles();
243  foreach ($all_styles as $style) {
244  if (!isset($active_styles[$style['id']])) {
245  ilSystemStyleSettings::_deactivateStyle($style['template_id'], $style['style_id']);
246  } else {
247  ilSystemStyleSettings::_activateStyle($style['template_id'], $style['style_id']);
248  }
249  }
250 
251  //set default skin and style
252  if ($this->request_wrapper->post()->has('default_skin_style')) {
253  $sknst = $this->request_wrapper->post()->retrieve(
254  'default_skin_style',
255  $this->refinery->string()->splitString(':')
256  );
257  ilSystemStyleSettings::setCurrentDefaultStyle($sknst[0], $sknst[1]);
258  }
259  $this->message_stack->addMessage(new ilSystemStyleMessage(
260  $this->lng->txt('msg_obj_modified'),
262  ));
263  }
264  $this->message_stack->sendMessages();
265  $this->ctrl->redirect($this, 'edit');
266  }
267 
268  protected function checkStyleSettings(ilSystemStyleMessageStack $message_stack, array $active_styles): bool
269  {
270  $passed = true;
271 
272  if (count($active_styles) < 1) {
273  $passed = false;
274  $message_stack->addMessage(new ilSystemStyleMessage(
275  $this->lng->txt('at_least_one_style'),
277  ));
278  }
279 
280  $default_style = $this->request_wrapper->post()->retrieve(
281  'default_skin_style',
282  $this->refinery->kindlyTo()->string()
283  );
284 
285  if (!isset($active_styles[$default_style])) {
286  $passed = false;
287  $message_stack->addMessage(new ilSystemStyleMessage(
288  $this->lng->txt('cant_deactivate_default_style'),
290  ));
291  }
292 
293  // check if a style should be deactivated, that still has
294  // a user assigned to
295  $all_styles = ilStyleDefinition::getAllSkinStyles();
296 
297  foreach ($all_styles as $style) {
298  if (!isset($active_styles[$style['id']])) {
299  if (ilObjUser::_getNumberOfUsersForStyle($style['template_id'], $style['style_id']) > 0) {
300  $passed = false;
301  $message_stack->addMessage(new ilSystemStyleMessage(
302  $style['style_name'] . ': ' . $this->lng->txt('cant_deactivate_if_users_assigned'),
304  ));
305  }
306  }
307  }
308  return $passed;
309  }
310 
311  protected function addSystemStyle(): void
312  {
313  $this->addSystemStyleForms();
314  }
315 
316  protected function saveNewSystemStyle(): void
317  {
318  $form = $this->createSystemStyleForm();
319 
320  if ($form->checkInput()) {
321  $skin_id = $this->request_wrapper->post()->retrieve('skin_id', $this->refinery->kindlyTo()->string());
322  $style_id = $this->request_wrapper->post()->retrieve('style_id', $this->refinery->kindlyTo()->string());
323 
324  $skin_name = $this->request_wrapper->post()->retrieve('skin_name', $this->refinery->kindlyTo()->string());
325  $style_name = $this->request_wrapper->post()->retrieve('style_name', $this->refinery->kindlyTo()->string());
326 
327  if (ilStyleDefinition::skinExists($skin_id)) {
328  $this->message_stack->addMessage(new ilSystemStyleMessage(
329  $this->lng->txt('skin_id_exists'),
331  ));
332  } else {
333  try {
334  $skin = new ilSkin($skin_id, $skin_name);
335  $style = new ilSkinStyle($style_id, $style_name);
336  $skin->addStyle($style);
337  $container = new ilSkinStyleContainer($this->lng, $skin, $this->message_stack);
338  $container->create($this->message_stack);
339  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'skin_id', $skin->getId());
340  $this->ctrl->setParameterByClass(ilSystemStyleConfigGUI::class, 'style_id', $style->getId());
341  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_sys_style_created')));
342  $this->message_stack->sendMessages();
343  $this->ctrl->redirectByClass(ilSystemStyleConfigGUI::class);
344  } catch (ilSystemStyleException $e) {
345  $this->message_stack->addMessage(new ilSystemStyleMessage(
346  $e->getMessage(),
348  ));
349  }
350  }
351  }
352 
353  // display only this form to correct input
354  $form->setValuesByPost();
355  $this->tpl->setContent($form->getHTML());
356  }
357 
358  protected function addSystemStyleForms(): void
359  {
360  $this->tabs->clearTargets();
364  $this->help->setScreenIdComponent('sty');
365  $this->help->setScreenId('system_styles');
366  $this->help->setSubScreenId('create');
367 
368  $forms = [];
369 
370  $forms[] = $this->createSystemStyleForm();
371  $forms[] = $this->importSystemStyleForm();
372  $forms[] = $this->cloneSystemStyleForm();
373 
374  $this->tpl->setContent($this->getCreationFormsHTML($forms));
375  }
376 
378  {
379  $form = new ilPropertyFormGUI();
380  $form->setFormAction($this->ctrl->getFormAction($this));
381  $form->setTitle($this->lng->txt('sty_create_new_system_style'));
382 
383  $ti = new ilTextInputGUI($this->lng->txt('skin_id'), 'skin_id');
384  $ti->setInfo($this->lng->txt('skin_id_description'));
385  $ti->setMaxLength(128);
386  $ti->setSize(40);
387  $ti->setRequired(true);
388  $form->addItem($ti);
389 
390  $ti = new ilTextInputGUI($this->lng->txt('skin_name'), 'skin_name');
391  $ti->setInfo($this->lng->txt('skin_name_description'));
392  $ti->setMaxLength(128);
393  $ti->setSize(40);
394  $ti->setRequired(true);
395  $form->addItem($ti);
396 
397  $ti = new ilTextInputGUI($this->lng->txt('style_id'), 'style_id');
398  $ti->setInfo($this->lng->txt('style_id_description'));
399  $ti->setMaxLength(128);
400  $ti->setSize(40);
401  $ti->setRequired(true);
402  $form->addItem($ti);
403 
404  $ti = new ilTextInputGUI($this->lng->txt('style_name'), 'style_name');
405  $ti->setInfo($this->lng->txt('style_name_description'));
406  $ti->setMaxLength(128);
407  $ti->setSize(40);
408  $ti->setRequired(true);
409  $form->addItem($ti);
410 
411  $form->addCommandButton('saveNewSystemStyle', $this->lng->txt('save'));
412  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
413 
414  return $form;
415  }
416 
418  {
419  $form = new ilPropertyFormGUI();
420  $form->setFormAction($this->ctrl->getFormAction($this, 'importStyle'));
421  $form->setTitle($this->lng->txt('sty_import_system_style'));
422 
423  // title
424  $file_input = new ilFileInputGUI($this->lng->txt('import_file'), 'importfile');
425  $file_input->setRequired(true);
426  $file_input->setSuffixes(['zip']);
427  $form->addItem($file_input);
428 
429  $form->addCommandButton('importStyle', $this->lng->txt('import'));
430  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
431 
432  return $form;
433  }
434 
436  {
437  $form = new ilPropertyFormGUI();
438  $form->setFormAction($this->ctrl->getFormAction($this));
439  $form->setTitle($this->lng->txt('sty_copy_other_system_style'));
440 
441  // source
442  $ti = new ilSelectInputGUI($this->lng->txt('sty_source'), 'source_style');
443  $ti->setRequired(true);
445  $options = [];
446  foreach ($styles as $id => $style) {
447  $system_style_conf = new ilSystemStyleConfig();
448  if ($style['skin_id'] != $system_style_conf->getDefaultSkinId()) {
449  $options[$id] = $style['title'];
450  }
451  }
452  $ti->setOptions($options);
453 
454  $form->addItem($ti);
455 
456  $form->addCommandButton('copyStyle', $this->lng->txt('copy'));
457  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
458 
459  return $form;
460  }
461 
462  protected function getCreationFormsHTML(array $a_forms): string
463  {
464  include_once('./Services/Accordion/classes/class.ilAccordionGUI.php');
465 
466  $acc = new ilAccordionGUI();
467  $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
468  $cnt = 1;
469  foreach ($a_forms as $form_type => $cf) {
473  $htpl = new ilTemplate('tpl.creation_acc_head.html', true, true, 'Services/Object');
474 
475  // using custom form titles (used for repository plugins)
476  $form_title = '';
477  if (method_exists($this, 'getCreationFormTitle')) {
478  $form_title = $this->getCreationFormTitle($form_type);
479  }
480  if (!$form_title) {
481  $form_title = $cf->getTitle();
482  }
483 
484  // move title from form to accordion
485  $htpl->setVariable('TITLE', $this->lng->txt('option') . ' ' . $cnt . ': ' .
486  $form_title);
487  $cf->setTitle('');
488  $cf->setTitleIcon('');
489  $cf->setTableWidth('100%');
490 
491  $acc->addItem($htpl->get(), $cf->getHTML());
492 
493  $cnt++;
494  }
495 
496  return "<div class='ilCreationFormSection'>" . $acc->getHTML() . '</div>';
497  }
498 
499  protected function copyStyle(): void
500  {
501  $imploded_skin_style_id = $this->request_wrapper->post()->retrieve(
502  'source_style',
503  $this->refinery->string()->splitString(':')
504  );
505  $skin_id = $imploded_skin_style_id[0];
506  $style_id = $imploded_skin_style_id[1];
507 
508  try {
509  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
510  $new_container = $this->skin_factory->copyFromSkinStyleContainer(
511  $container,
512  $this->file_system,
513  $this->message_stack,
514  $this->lng->txt('sty_acopy')
515  );
516  $this->message_stack->prependMessage(new ilSystemStyleMessage(
517  $this->lng->txt('style_copied'),
519  ));
520  $this->ctrl->setParameterByClass('ilsystemstyleconfiggui', 'skin_id', $new_container->getSkin()->getId());
521  $this->ctrl->setParameterByClass(
522  'ilsystemstyleconfiggui',
523  'style_id',
524  $new_container->getSkin()->getStyle($style_id)->getId()
525  );
526  $this->message_stack->addMessage(new ilSystemStyleMessage(
527  $this->lng->txt('directory_created') . ' ' . $new_container->getSkinDirectory(),
529  ));
530  } catch (Exception $e) {
531  $this->message_stack->addMessage(new ilSystemStyleMessage(
532  $e->getMessage(),
534  ));
535  }
536  $this->message_stack->sendMessages();
537  $this->ctrl->redirectByClass('ilsystemstyleconfiggui');
538  }
539 
540  protected function deleteStyle(): void
541  {
542  $skin_id = $this->style_container->getSkin()->getId();
543  $style_id = $this->style_id;
544 
545  if ($this->checkDeletable($skin_id, $style_id, $this->message_stack)) {
546  $delete_form_table = new ilSystemStyleDeleteGUI($this->lng, $this->ctrl);
547  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
548  $delete_form_table->addStyle(
549  $container->getSkin(),
550  $container->getSkin()->getStyle($style_id),
551  $container->getImagesStylePath($style_id) . '/standard/icon_stys.svg'
552  );
553  $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
554  } else {
555  $this->message_stack->prependMessage(new ilSystemStyleMessage(
556  $this->lng->txt('style_not_deleted'),
558  ));
559  $this->edit();
560  }
561  }
562 
563  protected function deleteStyles(): void
564  {
565  $delete_form_table = new ilSystemStyleDeleteGUI($this->lng, $this->ctrl);
566 
567  $all_deletable = true;
568 
569  $skin_ids = $this->request_wrapper->post()->retrieve('id', $this->refinery->identity());
570  foreach ($skin_ids as $skin_style_id) {
571  $imploded_skin_style_id = explode(':', $skin_style_id);
572  $skin_id = $imploded_skin_style_id[0];
573  $style_id = $imploded_skin_style_id[1];
574  if (!$this->checkDeletable($skin_id, $style_id, $this->message_stack)) {
575  $all_deletable = false;
576  }
577  }
578  if ($all_deletable) {
579  foreach ($skin_ids as $skin_style_id) {
580  $imploded_skin_style_id = explode(':', $skin_style_id);
581  $skin_id = $imploded_skin_style_id[0];
582  $style_id = $imploded_skin_style_id[1];
583  $container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
584  $delete_form_table->addStyle(
585  $container->getSkin(),
586  $container->getSkin()->getStyle($style_id),
587  $container->getImagesStylePath($style_id) . '/standard/icon_stys.svg'
588  );
589  }
590  $this->tpl->setContent($delete_form_table->getDeleteStyleFormHTML());
591  } else {
592  $this->message_stack->prependMessage(new ilSystemStyleMessage(
593  $this->lng->txt('styles_not_deleted'),
595  ));
596  $this->edit();
597  }
598  }
599 
600  protected function checkDeletable(
601  string $skin_id,
602  string $style_id,
603  ilSystemStyleMessageStack $message_stack
604  ): bool {
605  $passed = true;
606  if (ilObjUser::_getNumberOfUsersForStyle($skin_id, $style_id) > 0) {
607  $message_stack->addMessage(new ilSystemStyleMessage(
608  $style_id . ': ' . $this->lng->txt('cant_delete_if_users_assigned'),
610  ));
611  $passed = false;
612  }
613  if (ilSystemStyleSettings::_lookupActivatedStyle($skin_id, $style_id) > 0) {
614  $message_stack->addMessage(new ilSystemStyleMessage(
615  $style_id . ': ' . $this->lng->txt('cant_delete_activated_style'),
617  ));
618  $passed = false;
619  }
621  $message_stack->addMessage(new ilSystemStyleMessage(
622  $style_id . ': ' . $this->lng->txt('cant_delete_default_style'),
624  ));
625  $passed = false;
626  }
627 
628  if ($this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack)->getSkin()->getSubstylesOfStyle($style_id)) {
629  $message_stack->addMessage(new ilSystemStyleMessage(
630  $style_id . ': ' . $this->lng->txt('cant_delete_style_with_substyles'),
632  ));
633  $passed = false;
634  }
635  return $passed;
636  }
637 
638  protected function confirmDelete(): void
639  {
640  $i = 0;
641  while ($this->request_wrapper->post()->has('style_' . $i)) {
642  try {
643  $skin_style_id = $this->request_wrapper->post()->retrieve(
644  'style_' . $i,
645  $this->refinery->string()->splitString(':')
646  );
647  $container = $this->skin_factory->skinStyleContainerFromId($skin_style_id[0], $this->message_stack);
648  $syle = $container->getSkin()->getStyle($skin_style_id[1]);
649  $container->deleteStyle($syle);
650  if (!$container->getSkin()->hasStyles()) {
651  $container->delete();
652  }
653  } catch (Exception $e) {
654  $this->message_stack->addMessage(new ilSystemStyleMessage(
655  $e->getMessage(),
657  ));
658  }
659  $i++;
660  }
661  $this->message_stack->sendMessages();
662  $this->ctrl->redirect($this);
663  }
664 
665  protected function importStyle(): void
666  {
667  $form = $this->importSystemStyleForm();
668 
669  if ($form->checkInput() && $this->upload->hasUploads()) {
671  $result = array_values($this->upload->getResults())[0];
672 
673  $this->upload->moveOneFileTo(
674  $result,
675  'global/skin',
676  ILIAS\FileUpload\Location::CUSTOMIZING,
677  $result->getName(),
678  true
679  );
680  $imported_container = $this->skin_factory->skinStyleContainerFromZip(
681  $this->config->getCustomizingSkinPath() . $result->getName(),
682  $result->getName(),
684  );
685  $this->ctrl->setParameterByClass(
686  'ilsystemstyleconfiggui',
687  'skin_id',
688  $imported_container->getSkin()->getId()
689  );
690  $this->ctrl->setParameterByClass(
691  'ilsystemstyleconfiggui',
692  'style_id',
693  $imported_container->getSkin()->getDefaultStyle()->getId()
694  );
695  $this->message_stack->addMessage(new ilSystemStyleMessage(
696  $this->lng->txt('style_imported') . ' ' . $imported_container->getSkinDirectory(),
698  ));
699  $this->message_stack->sendMessages();
700  $this->ctrl->redirectByClass('ilsystemstyleconfiggui');
701  }
702  // display only this form to correct input
703  $form->setValuesByPost();
704  $this->tpl->setContent($form->getHTML());
705  }
706 
707  protected function export(): void
708  {
709  try {
710  $this->style_container->export();
711  } catch (Exception $e) {
712  $this->message_stack->addMessage(new ilSystemStyleMessage(
713  $this->lng->txt('zip_export_failed') . ' ' . $e->getMessage(),
715  ));
716  }
717  }
718 
722  protected function addSubStyle(): void
723  {
724  $this->tabs->clearTargets();
728  $this->help->setScreenIdComponent('sty');
729  $this->help->setScreenId('system_styles');
730  $this->help->setSubScreenId('create_sub');
731 
732  $form = $this->addSubStyleForms();
733 
734  $this->tpl->setContent($form->getHTML());
735  }
736 
737  protected function addSubStyleForms(): ilPropertyFormGUI
738  {
739  $form = new ilPropertyFormGUI();
740  $form->setFormAction($this->ctrl->getFormAction($this));
741  $form->setTitle($this->lng->txt('sty_create_new_system_sub_style'));
742 
743  $ti = new ilTextInputGUI($this->lng->txt('sub_style_id'), 'sub_style_id');
744  $ti->setInfo($this->lng->txt('sub_style_id_description'));
745  $ti->setMaxLength(128);
746  $ti->setSize(40);
747  $ti->setRequired(true);
748  $form->addItem($ti);
749 
750  $ti = new ilTextInputGUI($this->lng->txt('sub_style_name'), 'sub_style_name');
751  $ti->setInfo($this->lng->txt('sub_style_name_description'));
752  $ti->setMaxLength(128);
753  $ti->setSize(40);
754  $ti->setRequired(true);
755  $form->addItem($ti);
756 
757  // source
758  $ti = new ilSelectInputGUI($this->lng->txt('parent'), 'parent_style');
759  $ti->setRequired(true);
760  $ti->setInfo($this->lng->txt('sub_style_parent_style_description'));
762  $options = [];
763  foreach ($styles as $id => $style) {
764  $system_style_conf = new ilSystemStyleConfig();
765  if ($style['skin_id'] != $system_style_conf->getDefaultSkinId() && !$style['substyle_of']) {
766  $options[$id] = $style['title'];
767  }
768  }
769  $ti->setOptions($options);
770 
771  $form->addItem($ti);
772  $form->addCommandButton('saveNewSubStyle', $this->lng->txt('save'));
773  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
774 
775  return $form;
776  }
777 
778  protected function saveNewSubStyle(): void
779  {
780  $form = $this->addSubStyleForms();
781 
782  if ($form->checkInput()) {
783  try {
784  $skin_style_ids = $this->request_wrapper->post()->retrieve(
785  'parent_style',
786  $this->refinery->string()->splitString(':')
787  );
788 
789  $parent_skin_id = $skin_style_ids[0];
790  $parent_style_id = $skin_style_ids[1];
791 
792  $container = $this->skin_factory->skinStyleContainerFromId($parent_skin_id, $this->message_stack);
793 
794  $sub_style_id = $this->request_wrapper->post()->retrieve(
795  'sub_style_id',
796  $this->refinery->kindlyTo()->string()
797  );
798 
799  if (array_key_exists(
800  $sub_style_id,
801  $container->getSkin()->getSubstylesOfStyle($parent_style_id)
802  )) {
803  throw new ilSystemStyleException(
805  $sub_style_id
806  );
807  }
808 
809  $sub_style_name = $this->request_wrapper->post()->retrieve(
810  'sub_style_name',
811  $this->refinery->kindlyTo()->string()
812  );
813 
814  $style = new ilSkinStyle($sub_style_id, $sub_style_name);
815  $style->setSubstyleOf($parent_style_id);
816  $container->addStyle($style);
817  $this->ctrl->setParameterByClass('ilsystemstyleconfiggui', 'skin_id', $parent_skin_id);
818  $this->ctrl->setParameterByClass('ilsystemstyleconfiggui', 'style_id', $sub_style_id);
819  $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('msg_sub_style_created')));
820  $this->message_stack->sendMessages();
821  $this->ctrl->redirectByClass('ilsystemstyleconfiggui');
822  } catch (ilSystemStyleException $e) {
823  $this->message_stack->addMessage(new ilSystemStyleMessage(
824  $e->getMessage(),
826  ));
827  }
828  }
829 
830  // display only this form to correct input
831  $form->setValuesByPost();
832  $this->tpl->setContent($form->getHTML());
833  }
834 
835  public function isReadOnly(): bool
836  {
837  return $this->read_only;
838  }
839 
840  public function setReadOnly(bool $read_only): void
841  {
842  $this->read_only = $read_only;
843  }
844 
845  public function isManagementEnabled(): bool
846  {
848  }
849 
850  public function setManagementEnabled(bool $management_enabled): void
851  {
852  $this->management_enabled = $management_enabled;
853  }
854 }
An entity that renders components to a string output.
Definition: Renderer.php:30
This class represents a selection list property in a property form.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
File System Helper, to reduce deps.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
getAssignmentCreationModal(string $style_name="")
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...
global $DIC
Definition: feed.php:28
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
$txt
Definition: error.php:14
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)
ilSkin holds an manages the basic data of a skin as provide by the template of the skin...