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