ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilStyleCharacteristicGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
32{
33 protected string $requested_char;
36 protected string $super_type;
37 protected string $current_tag;
38 protected string $current_class; // "XXX:hover"
39 protected string $current_base_class; // "XXX"
40 protected string $current_pseudo_class; // "hover"
41 protected string $style_type;
42 protected int $mq_id;
49
50 public function __construct(
53 ilObjStyleSheet $style_sheet,
54 string $super_type,
58 ) {
59 global $DIC;
60 $this->main_tpl = $DIC->ui()->mainTemplate();
61 $this->gui_service = $gui_service;
62 $this->domain_service = $domain_service;
63 $this->access_manager = $access_manager;
64 $this->object = $style_sheet;
65 $this->super_type = $super_type;
66 $this->manager = $manager;
67 $this->image_manager = $image_manager;
68 $this->request = $gui_service->standardRequest();
69
70 $cur = explode(".", $this->request->getTag());
71 $this->current_tag = (string) $cur[0];
72 $this->current_class = (string) ($cur[1] ?? "");
73
74 $t = explode(":", $cur[1] ?? "");
75 $this->current_base_class = (string) $t[0];
76 $this->current_pseudo_class = (string) ($t[1] ?? "");
77
78 $this->style_type = $this->request->getStyleType();
79 $this->requested_char = $this->request->getCharacteristic();
80 $this->mq_id = $this->request->getMediaQueryId();
81
82 $ctrl = $gui_service->ctrl();
83 $ctrl->saveParameter($this, "tag");
84 }
85
86 protected function extractParametersOfTag(
87 bool $a_custom = false
88 ): array {
89 $style = $this->object->getStyle();
90 $parameters = array();
91 foreach ($style as $tag) {
92 foreach ($tag as $par) {
93 if ($par["tag"] == $this->current_tag && $par["class"] == $this->current_class
94 && $par["type"] == $this->style_type && $this->mq_id == (int) $par["mq_id"]
95 && (int) $a_custom == (int) $par["custom"]) {
96 $parameters[$par["parameter"]] = $par["value"];
97 }
98 }
99 }
100 return $parameters;
101 }
102
106 public function executeCommand(): void
107 {
108 $ctrl = $this->gui_service->ctrl();
109
110 $next_class = $ctrl->getNextClass($this);
111 $cmd = $ctrl->getCmd();
112 $this->showMigrationState();
113 switch ($next_class) {
114 default:
115 if (in_array($cmd, [
116 "listCharacteristics", "addCharacteristic", "saveCharacteristic",
117 "deleteCharacteristicConfirmation", "cancelCharacteristicDeletion", "deleteCharacteristic",
118 "copyCharacteristics", "pasteCharacteristicsOverview", "pasteCharacteristics",
119 "pasteCharacteristicsWithinStyle", "pasteCharacteristicsFromOtherStyle",
120 "saveStatus", "setOutdated", "removeOutdated",
121 "editTagStyle", "refreshTagStyle", "updateTagStyle",
122 "editTagTitles", "saveTagTitles", "switchMQuery", "migrateImages"])) {
123 $this->$cmd();
124 }
125 }
126 }
127
128 public function showMigrationState(): void
129 {
130 $mt = $this->gui_service->mainTemplate();
131 $lng = $this->domain_service->lng();
132 $style_id = $this->object->getId();
133 $f = $this->gui_service->ui()->factory();
134 $toolbar = $this->gui_service->toolbar();
135 $ctrl = $this->gui_service->ctrl();
136 if (!$this->domain_service->style($style_id)->isMigrated()) {
137 $mt->setOnScreenMessage('info', $lng->txt('sty_style_not_migrated'));
138 } else {
139 if ($this->domain_service->image(
140 $style_id,
141 $this->access_manager
142 )->hasLegacyDirAndNoImages()) {
143 $mt->setOnScreenMessage('info', $lng->txt('sty_legacy_image_directory_found'));
144 $toolbar->addComponent(
145 $f->button()->standard(
146 $lng->txt('sty_migrate_images'),
147 $ctrl->getLinkTarget($this, "migrateImages")
148 )
149 );
150 }
151 }
152 }
153
154 public function listCharacteristics(): void
155 {
156 $lng = $this->domain_service->lng();
157 $ilTabs = $this->gui_service->tabs();
158 $ilCtrl = $this->gui_service->ctrl();
159 $ilToolbar = $this->gui_service->toolbar();
160 $tpl = $this->gui_service->mainTemplate();
161
162 $this->setListSubTabs();
163
164 // output characteristics
165 $chars = $this->object->getCharacteristics();
166
167 $style_type = ($this->super_type != "")
168 ? $this->super_type
169 : "text_block";
170 $ilCtrl->setParameter($this, "style_type", $style_type);
171 $ilTabs->activateSubTab("sty_" . $style_type . "_char");
172
173 // add new style?
174 $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
175 $subtypes = $all_super_types[$style_type];
176 $expandable = false;
177 foreach ($subtypes as $t) {
179 $expandable = true;
180 }
181 }
182 if ($expandable && $this->access_manager->checkWrite()) {
183 $ilToolbar->addButton(
184 $lng->txt("sty_add_characteristic"),
185 $ilCtrl->getLinkTarget($this, "addCharacteristic")
186 );
187 }
188
189 if ($this->manager->hasCopiedCharacteristics($style_type)) {
190 if ($expandable) {
191 $ilToolbar->addSeparator();
192 }
193 $ilToolbar->addButton(
194 $lng->txt("sty_paste_style_classes"),
195 $ilCtrl->getLinkTarget($this, "pasteCharacteristicsOverview")
196 );
197 }
198
199 $table_gui = $this->gui_service->characteristic()->CharacteristicTableGUI(
200 $this,
201 "edit",
202 $style_type,
203 $this->object,
204 $this->manager,
205 $this->access_manager
206 );
207
208 $tpl->setContent($table_gui->getHTML());
209 }
210
211 public function setListSubTabs(): void
212 {
213 $lng = $this->domain_service->lng();
214 $tabs = $this->gui_service->tabs();
215 $ctrl = $this->gui_service->ctrl();
216
218
219 foreach ($types as $super_type => $t) {
220 // text block characteristics
221 $ctrl->setParameter($this, "style_type", $super_type);
222 $tabs->addSubTab(
223 "sty_" . $super_type . "_char",
224 $lng->txt("sty_" . $super_type . "_char"),
225 $ctrl->getLinkTarget($this, "listCharacteristics")
226 );
227 }
228
229 $ctrl->setParameter($this, "style_type", $this->style_type);
230 }
231
232 public function addCharacteristic(): void
233 {
234 $tpl = $this->gui_service->mainTemplate();
235
236 $form = $this->initCharacteristicForm();
237 $tpl->setContent($form->getHTML());
238 }
239
240 public function saveCharacteristic(): void
241 {
242 $ilCtrl = $this->gui_service->ctrl();
243 $tpl = $this->gui_service->mainTemplate();
244 $lng = $this->domain_service->lng();
245
246 $form = $this->initCharacteristicForm();
247
248 if ($form->checkInput()) {
249 $new_characteristic = $form->getInput("new_characteristic");
250 $type = $form->getInput("type");
251 if ($this->object->characteristicExists($new_characteristic, $this->style_type)) {
252 $char_input = $form->getItemByPostVar("new_characteristic");
253 $char_input->setAlert($lng->txt("sty_characteristic_already_exists"));
254 } else {
255 $this->object->addCharacteristic($type, $new_characteristic);
256 $this->main_tpl->setOnScreenMessage('info', $lng->txt("sty_added_characteristic"), true);
257 $ilCtrl->setParameter(
258 $this,
259 "tag",
260 ilObjStyleSheet::_determineTag($type) . "." . $new_characteristic
261 );
262 $ilCtrl->setParameter($this, "style_type", $type);
263 $ilCtrl->redirectByClass("ilstylecharacteristicgui", "editTagStyle");
264 }
265 }
266 $form->setValuesByPost();
267 $tpl->setContent($form->getHTML());
268 }
269
270 public function deleteCharacteristicConfirmation(): void
271 {
272 $ilCtrl = $this->gui_service->ctrl();
273 $tpl = $this->gui_service->mainTemplate();
274 $lng = $this->domain_service->lng();
275
276 //var_dump($_POST);
277
278 $chars = $this->request->getCharacteristics();
279 if (count($chars) == 0) {
280 $this->main_tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
281 $ilCtrl->redirect($this, "edit");
282 } else {
283 // check whether there are any core style classes included
284 $core_styles = ilObjStyleSheet::_getCoreStyles();
285 foreach ($chars as $char) {
286 if (!empty($core_styles[$char])) {
287 $this->deleteCoreCharMessage();
288 return;
289 }
290 }
291
292 $cgui = new ilConfirmationGUI();
293 $cgui->setFormAction($ilCtrl->getFormAction($this));
294 $cgui->setHeaderText($lng->txt("sty_confirm_char_deletion"));
295 $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
296 $cgui->setConfirm($lng->txt("delete"), "deleteCharacteristic");
297
298 foreach ($chars as $char) {
299 $char_comp = explode(".", $char);
300 $cgui->addItem("char[]", $char, $char_comp[2]);
301 }
302
303 $tpl->setContent($cgui->getHTML());
304 }
305 }
306
307 // Message that appears, when user tries to delete core characteristics
308 public function deleteCoreCharMessage(): void
309 {
310 $ilCtrl = $this->gui_service->ctrl();
311 $tpl = $this->gui_service->mainTemplate();
312 $lng = $this->domain_service->lng();
313
314 $cgui = new ilConfirmationGUI();
315 $cgui->setFormAction($ilCtrl->getFormAction($this));
316
317
318 $core_styles = ilObjStyleSheet::_getCoreStyles();
319 $cnt = 0;
320
321 $chars = $this->request->getCharacteristics();
322 foreach ($chars as $char) {
323 if (!empty($core_styles[$char])) {
324 $cnt++;
325 $char_comp = explode(".", $char);
326 $cgui->addItem("", "", $char_comp[2]);
327 } else {
328 $cgui->addHiddenItem("char[]", $char);
329 }
330 }
331 $all_core_styles = ($cnt == count($chars));
332
333 if ($all_core_styles) {
334 $cgui->setHeaderText($lng->txt("sty_all_styles_obligatory"));
335 $cgui->setCancel($lng->txt("back"), "cancelCharacteristicDeletion");
336 $cgui->setConfirm($lng->txt("ok"), "cancelCharacteristicDeletion");
337 } else {
338 $cgui->setHeaderText($lng->txt("sty_some_styles_obligatory_delete_rest"));
339 $cgui->setCancel($lng->txt("cancel"), "cancelCharacteristicDeletion");
340 $cgui->setConfirm($lng->txt("sty_delete_other_selected"), "deleteCharacteristicConfirmation");
341 }
342
343 $tpl->setContent($cgui->getHTML());
344 }
345
346 public function cancelCharacteristicDeletion(): void
347 {
348 $ilCtrl = $this->gui_service->ctrl();
349 $lng = $this->domain_service->lng();
350
351 $this->main_tpl->setOnScreenMessage('info', $lng->txt("action_aborted"), true);
352 $ilCtrl->redirect($this, "listCharacteristics");
353 }
354
359 public function deleteCharacteristic(): void
360 {
361 $ilCtrl = $this->gui_service->ctrl();
362
363 $chars = $this->request->getCharacteristics();
364 foreach ($chars as $char) {
365 $char_comp = explode(".", $char);
366 $type = $char_comp[0];
367 $tag = $char_comp[1];
368 $class = $char_comp[2];
369
370 $this->manager->deleteCharacteristic(
371 $type,
372 $class
373 );
374 }
375
376 $ilCtrl->redirect($this, "listCharacteristics");
377 }
378
383 {
384 $lng = $this->domain_service->lng();
385 $ilCtrl = $this->gui_service->ctrl();
386
387 $form = new ilPropertyFormGUI();
388
389 // title
390 $txt_input = new ilRegExpInputGUI($lng->txt("title"), "new_characteristic");
391 $txt_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
392 $txt_input->setNoMatchMessage($lng->txt("sty_msg_characteristic_must_only_include") . " A-Z, a-z, 0-9");
393 $txt_input->setRequired(true);
394 $form->addItem($txt_input);
395
396 // type
397 $all_super_types = ilObjStyleSheet::_getStyleSuperTypes();
398 $types = $all_super_types[$this->super_type];
399 $exp_types = array();
400 foreach ($types as $t) {
402 $exp_types[$t] = $lng->txt("sty_type_" . $t);
403 }
404 }
405 if (count($exp_types) > 1) {
406 $type_input = new ilSelectInputGUI($lng->txt("sty_type"), "type");
407 $type_input->setOptions($exp_types);
408 $type_input->setValue(key($exp_types));
409 $form->addItem($type_input);
410 } elseif (count($exp_types) == 1) {
411 $hid_input = new ilHiddenInputGUI("type");
412 $hid_input->setValue(key($exp_types));
413 $form->addItem($hid_input);
414 }
415
416 $form->setTitle($lng->txt("sty_add_characteristic"));
417 $form->addCommandButton("saveCharacteristic", $lng->txt("save"));
418 $form->addCommandButton("listCharacteristics", $lng->txt("cancel"));
419 $form->setFormAction($ilCtrl->getFormAction($this));
420
421 return $form;
422 }
423
424 protected function setTabs(): void
425 {
426 $tabs = $this->gui_service->tabs();
427 $ctrl = $this->gui_service->ctrl();
428 $lng = $this->domain_service->lng();
429
430 $tabs->clearTargets();
431
432 // back to upper context
433 $tabs->setBackTarget(
434 $lng->txt("back"),
435 $ctrl->getLinkTargetByClass("ilobjstylesheetgui", "edit")
436 );
437
438 // parameters
439 $ctrl->setParameter($this, "tag", $this->current_tag . "." . $this->current_base_class);
440 $tabs->addTab(
441 "parameters",
442 $lng->txt("sty_parameters"),
443 $ctrl->getLinkTarget($this, "editTagStyle")
444 );
445
446 // titles
447 $tabs->addTab(
448 "titles",
449 $lng->txt("sty_titles"),
450 $ctrl->getLinkTarget($this, "editTagTitles")
451 );
452 $ctrl->setParameter($this, "tag", $this->request->getTag());
453 }
454
455 protected function setParameterSubTabs(): void
456 {
457 $tabs = $this->gui_service->tabs();
458 $ctrl = $this->gui_service->ctrl();
459 $lng = $this->domain_service->lng();
460
461 $pc = $this->object->_getPseudoClasses($this->current_tag);
462 if (count($pc) > 0) {
463 // style classes
464 $ctrl->setParameter($this, "tag", $this->current_tag . "." . $this->current_base_class);
465 $tabs->addSubTab(
466 "sty_tag_normal",
467 $lng->txt("sty_tag_normal"),
468 $ctrl->getLinkTarget($this, "editTagStyle")
469 );
470 if ($this->current_pseudo_class == "") {
471 $tabs->activateSubTab("sty_tag_normal");
472 }
473
474 foreach ($pc as $p) {
475 // style classes
476 $ctrl->setParameter(
477 $this,
478 "tag",
479 $this->current_tag . "." . $this->current_base_class . ":" . $p
480 );
481 $tabs->addSubTab(
482 "sty_tag_" . $p,
483 ":" . $p,
484 $ctrl->getLinkTarget($this, "editTagStyle")
485 );
486 if ($this->current_pseudo_class == $p) {
487 $tabs->activateSubTab("sty_tag_" . $p);
488 }
489 }
490 $ctrl->setParameter($this, "tag", $this->current_tag . "." . $this->current_base_class);
491 }
492 $ctrl->setParameter($this, "tag", $this->request->getTag());
493 }
494
495 protected function editTagStyle(): void
496 {
497 $ilToolbar = $this->gui_service->toolbar();
498 $lng = $this->domain_service->lng();
499 $ilCtrl = $this->gui_service->ctrl();
500 $tabs = $this->gui_service->tabs();
501
502 $this->setTabs();
503 $this->setParameterSubTabs();
504 $tabs->activateTab("parameters");
505
506 // media query selector
507 $mqs = $this->object->getMediaQueries();
508 if (count($mqs) > 0) {
509 //
510 $options = array(
511 "" => $lng->txt("sty_default"),
512 );
513 foreach ($mqs as $mq) {
514 $options[$mq["id"]] = $mq["mquery"];
515 }
516 $si = new ilSelectInputGUI("@media", "mq_id");
517 $si->setOptions($options);
518 $si->setValue($this->mq_id);
519 $ilToolbar->addInputItem($si, true);
520 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
521 $ilToolbar->addFormButton($lng->txt("sty_switch"), "switchMQuery");
522 }
523
524 $form = $this->initTagStyleForm();
525 $this->getValues($form);
526 $this->outputTagStyleEditScreen($form);
527 }
528
536 {
537 $lng = $this->domain_service->lng();
538 $ilCtrl = $this->gui_service->ctrl();
539
540 $ilCtrl->saveParameter($this, array("mq_id"));
541
542 $form_gui = new ilPropertyFormGUI();
543
544 $avail_pars = $this->object->getAvailableParameters();
545 $groups = $this->object->getStyleParameterGroups();
546
547 // output select lists
548 foreach ($groups as $k => $group) {
549 // filter groups of properties that should only be
550 // displayed with matching tag
551 $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
552 if (isset($filtered_groups[$k]) && !in_array($this->current_tag, $filtered_groups[$k])) {
553 continue;
554 }
555
556 $sh = new ilFormSectionHeaderGUI();
557 $sh->setTitle($lng->txt("sty_" . $k));
558 $form_gui->addItem($sh);
559
560 foreach ($group as $par) {
561 $basepar = explode(".", $par);
562 $basepar = $basepar[0];
563
564 $var = str_replace("-", "_", $basepar);
565
567 case "select":
568 $sel_input = new ilSelectInputGUI($lng->txt("sty_" . $var), $basepar);
569 $options = array("" => "");
570 foreach ($avail_pars[$par] as $p) {
571 $options[$p] = $p;
572 }
573 $sel_input->setOptions($options);
574 $form_gui->addItem($sel_input);
575 break;
576
577 case "text":
578 $text_input = new ilTextInputGUI($lng->txt("sty_" . $var), $basepar);
579 $text_input->setMaxLength(200);
580 $text_input->setSize(20);
581 $form_gui->addItem($text_input);
582 break;
583
584 case "fontsize":
585 $fs_input = new ilFontSizeInputGUI($lng->txt("sty_" . $var), $basepar);
586 $form_gui->addItem($fs_input);
587 break;
588
589 case "numeric_no_perc":
590 case "numeric":
591 $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_" . $var), $basepar);
592 if (ilObjStyleSheet::_getStyleParameterInputType($par) == "numeric_no_perc") {
593 $num_input->setAllowPercentage(false);
594 }
595 $form_gui->addItem($num_input);
596 break;
597
598 case "percentage":
599 $per_input = new ilNumberInputGUI($lng->txt("sty_" . $var), $basepar);
600 $per_input->setMinValue(0);
601 $per_input->setMaxValue(100);
602 $per_input->setMaxLength(3);
603 $per_input->setSize(3);
604 $form_gui->addItem($per_input);
605 break;
606
607 case "color":
608 $col_input = new ilColorPickerInputGUI($lng->txt("sty_" . $var), $basepar);
609 $col_input->setDefaultColor("");
610 $col_input->setAcceptNamedColors(true);
611 $form_gui->addItem($col_input);
612 break;
613
614 case "trbl_numeric":
615 $num_input = new ilTRBLNumericStyleValueInputGUI($lng->txt("sty_" . $var), $basepar);
616 if (ilObjStyleSheet::_getStyleParameterInputType($par) == "trbl_numeric_no_perc") {
617 $num_input->setAllowPercentage(false);
618 }
619 $form_gui->addItem($num_input);
620 break;
621
622 case "border_width":
623 $bw_input = new ilTRBLBorderWidthInputGUI($lng->txt("sty_" . $var), $basepar);
624 $form_gui->addItem($bw_input);
625 break;
626
627 case "border_style":
628 $bw_input = new ilTRBLBorderStyleInputGUI($lng->txt("sty_" . $var), $basepar);
629 $form_gui->addItem($bw_input);
630 break;
631
632 case "trbl_color":
633 $col_input = new ilTRBLColorPickerInputGUI($lng->txt("sty_" . $var), $basepar);
634 $col_input->setAcceptNamedColors(true);
635 $form_gui->addItem($col_input);
636 break;
637
638 case "background_image":
639 $im_input = new ilBackgroundImageInputGUI($lng->txt("sty_" . $var), $basepar);
640 $images = array();
641 foreach ($this->image_manager->getImages() as $entry) {
642 $images[] = $entry->getFilename();
643 }
644 $im_input->setImages($images);
645 $im_input->setInfo($lng->txt("sty_bg_img_info"));
646 $form_gui->addItem($im_input);
647 break;
648
649 case "background_position":
650 $im_input = new ilBackgroundPositionInputGUI($lng->txt("sty_" . $var), $basepar);
651 $form_gui->addItem($im_input);
652 break;
653 }
654 }
655 }
656
657 // custom parameters
658 $sh = new ilFormSectionHeaderGUI();
659 $sh->setTitle($lng->txt("sty_custom"));
660 $form_gui->addItem($sh);
661
662 // custom parameters
663 $ti = new ilTextInputGUI($lng->txt("sty_custom_par"), "custom_par");
664 $ti->setMaxLength(300);
665 $ti->setSize(80);
666 $ti->setMulti(true);
667 $ti->setInfo($lng->txt("sty_custom_par_info"));
668 $form_gui->addItem($ti);
669
670
671 // save and cancel commands
672 $form_gui->addCommandButton("updateTagStyle", $lng->txt("save_return"));
673 $form_gui->addCommandButton("refreshTagStyle", $lng->txt("save_refresh"));
674
675 $form_gui->setFormAction($ilCtrl->getFormAction($this));
676 return $form_gui;
677 }
678
682 protected function getValues(ilPropertyFormGUI $form): void
683 {
684 $cur_parameters = $this->extractParametersOfTag();
686 foreach ($parameters as $p => $v) {
687 $filtered_groups = ilObjStyleSheet::_getFilteredGroups();
688 if (isset($filtered_groups[$v["group"]]) && !in_array($this->current_tag, $filtered_groups[$v["group"]])) {
689 continue;
690 }
691 $p = explode(".", $p);
692 $p = $p[0];
693 $input = $form->getItemByPostVar($p);
694 switch ($v["input"]) {
695 case "":
696 break;
697
698 case "trbl_numeric":
699 case "border_width":
700 case "border_style":
701 case "trbl_color":
702 $input->setAllValue($cur_parameters[$v["subpar"][0]] ?? "");
703 $input->setTopValue($cur_parameters[$v["subpar"][1]] ?? "");
704 $input->setRightValue($cur_parameters[$v["subpar"][2]] ?? "");
705 $input->setBottomValue($cur_parameters[$v["subpar"][3]] ?? "");
706 $input->setLeftValue($cur_parameters[$v["subpar"][4]] ?? "");
707 break;
708
709 default:
710 $input->setValue($cur_parameters[$p] ?? "");
711 break;
712 }
713 }
714
715 $cust_parameters = $this->extractParametersOfTag(true);
716 $vals = array();
717 foreach ($cust_parameters as $k => $c) {
718 $vals[] = $k . ": " . $c;
719 }
720 $input = $form->getItemByPostVar("custom_par");
721 $input->setValue($vals);
722 }
723
724 protected function outputTagStyleEditScreen(ilPropertyFormGUI $form): void
725 {
726 $tpl = $this->gui_service->mainTemplate();
727
728 // set style sheet
729 $tpl->setCurrentBlock("ContentStyle");
730 $tpl->setVariable(
731 "LOCATION_CONTENT_STYLESHEET",
733 );
734
735 $ts_tpl = new ilTemplate("tpl.style_tag_edit.html", true, true, "components/ILIAS/Style/Content");
736
737 $ts_tpl->setVariable(
738 "EXAMPLE",
739 ilObjStyleSheetGUI::getStyleExampleHTML($this->style_type, $this->current_class)
740 );
741
742 $ts_tpl->setVariable(
743 "FORM",
744 $form->getHTML()
745 );
746
747 $this->setTitle();
748
749 $tpl->setContent($ts_tpl->get());
750 }
751
752 protected function setTitle(): void
753 {
754 $tpl = $this->gui_service->mainTemplate();
755 $lng = $this->domain_service->lng();
756 $tpl->setTitle($this->current_class . " (" . $lng->txt("sty_type_" . $this->style_type) . ")");
757 }
758
759 protected function refreshTagStyle(): void
760 {
761 $ilCtrl = $this->gui_service->ctrl();
762
763 $form = $this->initTagStyleForm();
764
765 if ($form->checkInput()) {
766 $this->saveTagStyle($form);
767 $ilCtrl->redirect($this, "editTagStyle");
768 } else {
769 $form->setValuesByPost();
770 $this->outputTagStyleEditScreen($form);
771 }
772 }
773
774 protected function updateTagStyle(): void
775 {
776 $ilCtrl = $this->gui_service->ctrl();
777
778 $form = $this->initTagStyleForm();
779 if ($form->checkInput()) {
780 $this->saveTagStyle($form);
781 $ilCtrl->redirectByClass("ilobjstylesheetgui", "edit");
782 } else {
783 $form->setValuesByPost();
784 $this->outputTagStyleEditScreen($form);
785 }
786 }
787
788 protected function saveTagStyle(ilPropertyFormGUI $form): void
789 {
790 $avail_pars = ilObjStyleSheet::_getStyleParameters($this->current_tag);
791 foreach ($avail_pars as $par => $v) {
792 $var = str_replace("-", "_", $par);
793 $basepar_arr = explode(".", $par);
794 $basepar = $basepar_arr[0];
795 if (($basepar_arr[1] ?? "") != "" && $basepar_arr[1] != $this->current_tag) {
796 continue;
797 }
798
799 switch ($v["input"]) {
800 case "fontsize":
801 case "numeric_no_perc":
802 case "numeric":
803 case "background_image":
804 case "background_position":
805 $in = $form->getItemByPostVar($basepar);
806 $this->writeStylePar($basepar, (string) $in->getValue());
807 break;
808
809 case "color":
810 $color = trim($form->getInput($basepar));
811 if ($color != "" && trim(substr($color, 0, 1)) != "!") {
812 $color = "#" . $color;
813 }
814 $this->writeStylePar($basepar, $color);
815 break;
816
817 case "trbl_numeric":
818 case "border_width":
819 case "border_style":
820 $in = $form->getItemByPostVar($basepar);
821 $this->writeStylePar($v["subpar"][0], (string) $in->getAllValue());
822 $this->writeStylePar($v["subpar"][1], (string) $in->getTopValue());
823 $this->writeStylePar($v["subpar"][2], (string) $in->getRightValue());
824 $this->writeStylePar($v["subpar"][3], (string) $in->getBottomValue());
825 $this->writeStylePar($v["subpar"][4], (string) $in->getLeftValue());
826 break;
827
828 case "trbl_color":
829 $in = $form->getItemByPostVar($basepar);
830 $tblr_p = array(0 => "getAllValue", 1 => "getTopValue", 2 => "getRightValue",
831 3 => "getBottomValue", 4 => "getLeftValue");
832 foreach ($tblr_p as $k => $func) {
833 $val = trim($in->$func());
834 $val = (($in->getAcceptNamedColors() && substr($val, 0, 1) == "!")
835 || $val == "")
836 ? $val
837 : "#" . $val;
838 $this->writeStylePar($v["subpar"][$k], $val);
839 }
840 break;
841
842 default:
843 $this->writeStylePar($basepar, (string) $form->getInput($basepar));
844 break;
845 }
846 }
847
848 // write custom parameter
849 $this->object->deleteCustomStylePars(
850 $this->current_tag,
851 $this->current_class,
852 $this->style_type,
853 $this->mq_id
854 );
855 $custom_par = $form->getInput("custom_par");
856 foreach ($custom_par as $cpar) {
857 $par_arr = explode(":", $cpar);
858 if (count($par_arr) == 2) {
859 $par = trim($par_arr[0]);
860 $val = trim(str_replace(";", "", $par_arr[1]));
861 $this->writeStylePar($par, $val, true);
862 }
863 }
864
865 $this->object->update();
866 }
867
871 protected function writeStylePar(string $par, string $value, bool $a_custom = false): void
872 {
873 if ($this->style_type == "") {
874 return;
875 }
876 $this->manager->replaceParameter(
877 $this->current_tag,
878 $this->current_class,
879 $par,
880 $value,
881 $this->style_type,
882 $this->mq_id,
883 $a_custom
884 );
885 }
886
887 protected function editTagTitles(): void
888 {
889 $this->setTabs();
890 $tpl = $this->gui_service->mainTemplate();
891 $ui = $this->gui_service->ui();
892 $tabs = $this->gui_service->tabs();
893
894 $form = $this->getTagTitlesForm();
895 $this->setTitle();
896 $tabs->activateTab("titles");
897 $tpl->setContent($ui->renderer()->render($form));
898 }
899
903 protected function getTagTitlesForm(): Standard
904 {
905 $ui = $this->gui_service->ui();
906 $f = $ui->factory();
907 $ctrl = $this->gui_service->ctrl();
908 $lng = $this->domain_service->lng();
909 $fields = [];
910
911 $lng->loadLanguageModule("meta");
912
913 $characteristic = $this->manager->getByKey(
914 $this->style_type,
915 $this->current_base_class
916 );
917 $titles = $characteristic->getTitles();
918
919 foreach ($lng->getInstalledLanguages() as $l) {
920 $fields["title_" . $l] = $f->input()->field()->text($lng->txt("title") .
921 " - " . $lng->txt("meta_l_" . $l))
922 ->withRequired(false)
923 ->withValue($titles[$l] ?? "");
924 }
925
926 // section
927 $section1 = $f->input()->field()->section($fields, $lng->txt("sty_titles"));
928
929 $form_action = $ctrl->getLinkTarget($this, "saveTagTitles");
930 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
931 }
932
933 public function saveTagTitles(): void
934 {
935 $request = $this->gui_service->http()->request();
936 $form = $this->getTagTitlesForm();
937 $lng = $this->domain_service->lng();
938 $ctrl = $this->gui_service->ctrl();
939 $manager = $this->manager;
940
941 if ($request->getMethod() == "POST") {
942 $form = $form->withRequest($request);
943 $data = $form->getData();
944 if (isset($data["sec"])) {
945 $d = $data["sec"];
946 $titles = [];
947 foreach ($lng->getInstalledLanguages() as $l) {
948 $titles[$l] = $d["title_" . $l];
949 }
950
951 $manager->saveTitles(
952 $this->style_type,
953 $this->current_base_class,
954 $titles
955 );
956
957 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
958 }
959 }
960 $ctrl->redirect($this, "editTagTitles");
961 }
962
968 public function saveStatus(): void
969 {
970 $ilCtrl = $this->gui_service->ctrl();
971 $lng = $this->domain_service->lng();
972
973 $all_chars = $this->request->getAllCharacteristics();
974 $hidden = $this->request->getHidden();
975 $order = $this->request->getOrder();
976
977 // save hide status
978 foreach ($all_chars as $char) {
979 $ca = explode(".", $char);
980 $this->manager->saveHidden(
981 $ca[0],
982 $ca[2],
983 (in_array($char, $hidden))
984 );
985 }
986
987 // save order
988 if (count($order) > 0) {
989 $order_by_type = [];
990 foreach ($order as $char => $order_nr) {
991 $ca = explode(".", $char);
992 $order_by_type[$ca[0]][$ca[2]] = $order_nr;
993 }
994 foreach ($order_by_type as $type => $order_nrs) {
995 $this->manager->saveOrderNrs(
996 $type,
997 $order_nrs
998 );
999 }
1000 }
1001
1002 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1003 $ilCtrl->redirect($this, "listCharacteristics");
1004 }
1005
1006 protected function setOutdated(): void
1007 {
1008 $lng = $this->domain_service->lng();
1009 $ctrl = $this->gui_service->ctrl();
1010
1011 $chars = $this->request->getCharacteristics();
1012 if (count($chars) > 0) {
1013 foreach ($chars as $c) {
1014 $c_parts = explode(".", $c);
1015 if (!ilObjStyleSheet::isCoreStyle($c_parts[0], $c_parts[2])) {
1016 $this->manager->saveOutdated(
1017 $c_parts[0],
1018 $c_parts[2],
1019 true
1020 );
1021 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1022 }
1023 }
1024 } else {
1025 $this->manager->saveOutdated(
1026 $this->style_type,
1027 $this->requested_char,
1028 true
1029 );
1030 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1031 }
1032
1033 $ctrl->redirect($this, "listCharacteristics");
1034 }
1035
1036 protected function removeOutdated(): void
1037 {
1038 $lng = $this->domain_service->lng();
1039 $ctrl = $this->gui_service->ctrl();
1040 $chars = $this->request->getCharacteristics();
1041
1042 if (count($chars) > 0) {
1043 foreach ($chars as $c) {
1044 $c_parts = explode(".", $c);
1045 if (!ilObjStyleSheet::isCoreStyle($c_parts[0], $c_parts[2])) {
1046 $this->manager->saveOutdated(
1047 $c_parts[0],
1048 $c_parts[2],
1049 false
1050 );
1051 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1052 }
1053 }
1054 } else {
1055 $this->manager->saveOutdated(
1056 $this->style_type,
1057 $this->requested_char,
1058 false
1059 );
1060 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1061 }
1062
1063 $ctrl->redirect($this, "listCharacteristics");
1064 }
1065
1066 public function copyCharacteristics(): void
1067 {
1068 $ilCtrl = $this->gui_service->ctrl();
1069 $lng = $this->domain_service->lng();
1070
1071 $chars = $this->request->getCharacteristics();
1072
1073 // check, if type can be copied (is expanable)
1074 foreach ($chars as $c) {
1075 $type_arr = explode(".", $c);
1076 if (!ilObjStyleSheet::_isExpandable($type_arr[0] ?? "")) {
1077 $this->main_tpl->setOnScreenMessage(
1078 'failure',
1079 $lng->txt("sty_cannot_be_copied") . ": " . $lng->txt("sty_type_" . $type_arr[0] ?? ""),
1080 true
1081 );
1082 $ilCtrl->redirect($this, "listCharacteristics");
1083 }
1084 }
1085
1086 if (count($chars) == 0) {
1087 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
1088 } else {
1089 $this->manager->setCopyCharacteristics(
1090 $this->style_type,
1091 $chars
1092 );
1093 $this->main_tpl->setOnScreenMessage('success', $lng->txt("sty_copied_please_select_target"), true);
1094 }
1095 $ilCtrl->redirect($this, "listCharacteristics");
1096 }
1097
1098 public function pasteCharacteristicsOverview(): void
1099 {
1100 $tpl = $this->gui_service->mainTemplate();
1101 $ilTabs = $this->gui_service->tabs();
1102 $ui = $this->gui_service->ui();
1103
1104 $ilTabs->clearTargets();
1105
1106 if ($this->manager->getCopyCharacteristicStyleId() ==
1107 $this->object->getId()) {
1108 $form = $this->getPasteWithinStyleForm();
1109 } else {
1110 $form = $this->getPasteFromOtherStyleForm();
1111 }
1112 $tpl->setContent($ui->renderer()->render($form));
1113 }
1114
1120 {
1121 $ui = $this->gui_service->ui();
1122 $f = $ui->factory();
1123 $ctrl = $this->gui_service->ctrl();
1124
1125 $sections = [];
1126 foreach ($this->manager->getCopyCharacteristics() as $char) {
1127 // section
1128 $char_text = explode(".", $char);
1129 $sections[$char] = $f->input()->field()->section(
1130 $this->getCharacterTitleFormFields($char),
1131 $char_text[2]
1132 );
1133 }
1134
1135 $form_action = $ctrl->getLinkTarget($this, "pasteCharacteristicsWithinStyle");
1136 return $f->input()->container()->form()->standard($form_action, $sections);
1137 }
1138
1144 {
1145 $ui = $this->gui_service->ui();
1146 $lng = $this->domain_service->lng();
1147 $f = $ui->factory();
1148 $ctrl = $this->gui_service->ctrl();
1149
1150 $sections = [];
1151 $fields = [];
1152 foreach ($this->manager->getCopyCharacteristics() as $char) {
1153 $char_text = explode(".", $char);
1154 $options = [];
1155 foreach ($this->manager->getByType($char_text[0]) as $c) {
1156 $options[$c->getCharacteristic()] = $c->getCharacteristic();
1157 }
1158 $group1 = $f->input()->field()->group(
1159 $this->getCharacterTitleFormFields($char),
1160 $lng->txt("sty_create_new_class")
1161 );
1162 $group2 = $f->input()->field()->group(
1163 [
1164 "overwrite_class" => $f->input()->field()->select(
1165 $lng->txt("sty_class"),
1166 $options
1167 )->withRequired(true)
1168 ],
1169 $lng->txt("sty_overwrite_existing_class")
1170 );
1171 $fields[$char] = $f->input()->field()->switchableGroup(
1172 [
1173 "new_" . $char => $group1,
1174 "overwrite_" . $char => $group2
1175 ],
1176 $char_text[2]
1177 )->withValue("new_" . $char);
1178 }
1179 $sections["sec"] = $f->input()->field()->section(
1180 $fields,
1181 $lng->txt("sty_paste_chars")
1182 );
1183
1184 $form_action = $ctrl->getLinkTarget($this, "pasteCharacteristicsFromOtherStyle");
1185 return $f->input()->container()->form()->standard($form_action, $sections);
1186 }
1187
1191 protected function getCharacterTitleFormFields(string $char): array
1192 {
1193 $ui = $this->gui_service->ui();
1194 $f = $ui->factory();
1195 $refinery = $this->domain_service->refinery();
1196 $lng = $this->domain_service->lng();
1197 $style_type = $this->style_type;
1198 $style_obj = $this->object;
1199
1200
1201 $lng->loadLanguageModule("meta");
1202
1203 $char_regexp_constraint = $refinery->custom()->constraint(function ($v) use ($lng) {
1204 return (bool) preg_match("/^[a-zA-Z]+[a-zA-Z0-9]*$/", $v);
1205 }, $lng->txt("sty_msg_characteristic_must_only_include") . " A-Z, a-z, 0-9");
1206
1207 $char_exists_constraint = $refinery->custom()->constraint(function ($v) use ($style_obj, $style_type) {
1208 return !$style_obj->characteristicExists($v, $style_type);
1209 }, $lng->txt("sty_characteristic_already_exists"));
1210
1211 $fields = [];
1212 $fields["char_" . $char] = $f->input()->field()->text($lng->txt("sty_class_name"))
1213 ->withRequired(true)
1214 ->withAdditionalTransformation($char_regexp_constraint)
1215 ->withAdditionalTransformation($char_exists_constraint);
1216
1217 foreach ($lng->getInstalledLanguages() as $l) {
1218 $fields["title_" . $char . "_" . $l] = $f->input()->field()->text($lng->txt("title") .
1219 " - " . $lng->txt("meta_l_" . $l))
1220 ->withRequired(false)
1221 ->withValue($titles[$l] ?? "");
1222 }
1223
1224 return $fields;
1225 }
1226
1227 public function pasteCharacteristicsWithinStyle(): void
1228 {
1229 $ui = $this->gui_service->ui();
1230 $request = $this->gui_service->http()->request();
1231 $form = $this->getPasteWithinStyleForm();
1232 $tpl = $this->gui_service->mainTemplate();
1233 $ctrl = $this->gui_service->ctrl();
1234 $lng = $this->domain_service->lng();
1235 $manager = $this->manager;
1236
1237 if ($request->getMethod() == "POST") {
1238 $form = $form->withRequest($request);
1239 $data = $form->getData();
1240 if (is_null($data)) {
1241 $tpl->setContent($ui->renderer()->render($form));
1242 return;
1243 }
1244 foreach ($this->manager->getCopyCharacteristics() as $char) {
1245 if (is_array($data[$char])) {
1246 $d = $data[$char];
1247 $titles = [];
1248 foreach ($lng->getInstalledLanguages() as $l) {
1249 $titles[$l] = $d["title_" . $char . "_" . $l];
1250 }
1251 $new_char = $d["char_" . $char];
1252 $char_parts = explode(".", $char);
1253 $manager->copyCharacteristicFromSource(
1254 $this->manager->getCopyCharacteristicStyleId(),
1255 $char_parts[0],
1256 $char_parts[2],
1257 $new_char,
1258 $titles
1259 );
1260 }
1261 }
1262 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1263 }
1264 $ctrl->redirect($this, "listCharacteristics");
1265 }
1266
1272 {
1273 $request = $this->gui_service->http()->request();
1274 $form = $this->getPasteFromOtherStyleForm();
1275 $tpl = $this->gui_service->mainTemplate();
1276 $ctrl = $this->gui_service->ctrl();
1277 $lng = $this->domain_service->lng();
1278 $ui = $this->gui_service->ui();
1279 $manager = $this->manager;
1280
1281 if ($request->getMethod() == "POST") {
1282 $form = $form->withRequest($request);
1283 $data = $form->getData();
1284 if (is_null($data)) {
1285 $tpl->setContent($ui->renderer()->render($form));
1286 return;
1287 }
1288 foreach ($this->manager->getCopyCharacteristics() as $char) {
1289 if (is_array($data["sec"][$char])) {
1290 $d = $data["sec"][$char];
1291 $char_parts = explode(".", $char);
1292
1293 if (isset($d[1])) {
1294 $d = $d[1];
1295 }
1296
1297 // overwrite existing class
1298 if (isset($d["overwrite_class"])) {
1299 $manager->copyCharacteristicFromSource(
1300 $manager->getCopyCharacteristicStyleId(),
1301 $char_parts[0],
1302 $char_parts[2],
1303 $d["overwrite_class"],
1304 []
1305 );
1306 } elseif (isset($d["char_" . $char])) {
1307 $titles = [];
1308 foreach ($lng->getInstalledLanguages() as $l) {
1309 $titles[$l] = $d["title_" . $char . "_" . $l];
1310 }
1311 $new_char = $d["char_" . $char];
1312 $manager->copyCharacteristicFromSource(
1313 $manager->getCopyCharacteristicStyleId(),
1314 $char_parts[0],
1315 $char_parts[2],
1316 $new_char,
1317 $titles
1318 );
1319 }
1320 }
1321 }
1322 $this->main_tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
1323 }
1324 $ctrl->redirect($this, "listCharacteristics");
1325 }
1326
1327 public function pasteCharacteristics(): void
1328 {
1329 $ilCtrl = $this->gui_service->ctrl();
1330 $lng = $this->domain_service->lng();
1331
1332 $titles = $this->request->getTitles();
1333 $conflict_action = $this->request->getConflictAction();
1334 if (count($titles) > 0) {
1335 foreach ($titles as $from_char => $to_title) {
1336 $fc = explode(".", $from_char);
1337
1338 if ($conflict_action[$from_char] == "overwrite" ||
1339 !$this->object->characteristicExists($to_title, $fc[0])) {
1340 // @todo check this
1341 $this->manager->copyCharacteristicFromSource(
1342 $this->request->getFromStyleId(),
1343 $fc[0],
1344 $fc[2],
1345 $fc[2],
1346 ["en" => $to_title]
1347 );
1348 }
1349 }
1350 ilObjStyleSheet::_writeUpToDate($this->object->getId(), false);
1351 $this->manager->clearCopyCharacteristics();
1352 $this->main_tpl->setOnScreenMessage('success', $lng->txt("sty_style_classes_copied"), true);
1353 }
1354
1355 $ilCtrl->redirect($this, "listCharacteristics");
1356 }
1357
1361 public function switchMQuery(): void
1362 {
1363 $ctrl = $this->gui_service->ctrl();
1364 $ctrl->setParameter($this, "mq_id", $this->request->getMediaQueryId());
1365 $ctrl->redirectByClass("ilstylecharacteristicgui", "editTagStyle");
1366 }
1367
1368 protected function migrateImages(): void
1369 {
1370 $this->domain_service->style($this->object->getId())->migrateImages();
1371 $ctrl = $this->gui_service->ctrl();
1372 $ctrl->redirectByClass(self::class, "listCharacteristics");
1373 }
1374
1375}
Manages access to content style editing.
Main business logic for characteristics.
Main business logic for content style images.
Content style internal ui factory.
This class represents a background image property in a property form.
This class represents a background position in a property form.
Color picker form for selecting color hexcodes using yui library.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a fint size property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
This class represents a numeric style property in a property form.
static getStyleExampleHTML(string $a_type, string $a_class)
Get style example HTML.
Class ilObjStyleSheet.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static isCoreStyle(string $a_type, string $a_class)
static _getStyleParameterInputType(string $par)
static _determineTag(string $a_type)
static _writeUpToDate(int $a_id, bool $a_up_to_date)
static _getStyleParameters(string $a_tag="")
static _isExpandable(string $a_type)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a regular expression input property in a property form.
This class represents a selection list property in a property form.
Access StyleAccessManager $access_manager
Content CharacteristicManager $manager
outputTagStyleEditScreen(ilPropertyFormGUI $form)
Content StandardGUIRequest $request
getPasteWithinStyleForm()
Init past within style form.
deleteCharacteristic()
Delete one or multiple style characteristic.
__construct(Content\InternalDomainService $domain_service, Content\InternalGUIService $gui_service, ilObjStyleSheet $style_sheet, string $super_type, Access\StyleAccessManager $access_manager, Content\CharacteristicManager $manager, Content\ImageManager $image_manager)
getCharacterTitleFormFields(string $char)
Get character title form section.
extractParametersOfTag(bool $a_custom=false)
Content InternalDomainService $domain_service
initTagStyleForm()
Init tag style editing form.
saveStatus()
Save hide status for characteristics.
getPasteFromOtherStyleForm()
Init past from other style form.
getValues(ilPropertyFormGUI $form)
FORM: Get current values from persistent object.
writeStylePar(string $par, string $value, bool $a_custom=false)
Write style parameter.
initCharacteristicForm()
Init tag style editing form.
Content InternalGUIService $gui_service
This class represents a border style with all/top/right/bottom/left in a property form.
This class represents a border width with all/top/right/bottom/left in a property form.
Color picker form for selecting color hexcodes using yui library (all/top/right/bottom/left)
This class represents a numeric style property with all/top/right/bottom/left in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
$c
Definition: deliver.php:25
This describes a standard form.
Definition: Standard.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26