ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjStyleSheetGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
31{
37 protected ilHelpGUI $help;
39 public string $cmd_update;
40 public string $cmd_new_par;
41 public string $cmd_delete;
42 protected bool $enable_write = false;
43 protected string $super_type;
49
50
51 public function __construct(
52 $a_data,
53 int $a_id,
54 bool $a_call_by_reference
55 ) {
56 global $DIC;
57
58 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
59
60 $this->service = $DIC->contentStyle()
61 ->internal();
62 $this->gui_service = $this->service->gui();
63 $this->help = $this->gui_service->help();
64 $this->lng->loadLanguageModule("style");
65 $this->ctrl->saveParameter($this, array("tag", "style_type", "temp_type"));
66 $this->style_request = $DIC->contentStyle()
67 ->internal()
68 ->gui()
69 ->standardRequest();
70
71 $this->super_type = "";
72 if ($this->style_request->getStyleType() != "") {
74 $this->style_request->getStyleType()
75 );
76 }
77 $this->type = "sty";
78
79 $ref_id = (is_object($this->object))
80 ? $this->object->getRefId()
81 : 0;
82 $style_id = (is_object($this->object))
83 ? $this->object->getId()
84 : 0;
85
86 $this->access_manager = $this->service->domain()->access(
87 $ref_id,
88 $this->user->getId()
89 );
90 $this->characteristic_manager = $this->service->domain()->characteristic(
91 $style_id,
92 $this->access_manager
93 );
94 $this->color_manager = $this->service->domain()->color(
95 $style_id,
96 $this->access_manager
97 );
98 $this->image_manager = $this->service->domain()->image(
99 $style_id,
100 $this->access_manager
101 );
102 $this->domain = $this->service->domain();
103 }
104
108 public function enableWrite(bool $a_write): void
109 {
110 $this->access_manager->enableWrite($a_write);
111 }
112
113 public function executeCommand(): void
114 {
115 $tabs = $this->gui_service->tabs();
116 $ctrl = $this->gui_service->ctrl();
117
118 $next_class = $ctrl->getNextClass($this);
119 $cmd = $ctrl->getCmd("edit");
120
121 // #9440/#9489: prepareOutput will fail if not set properly
122 if (!$this->object || $cmd == "create") {
123 $this->setCreationMode();
124 }
125
126 switch ($next_class) {
127 case "ilexportgui":
128 $this->prepareOutput();
129 $exp_gui = new ilExportGUI($this);
130 $exp_gui->addFormat("xml");
131 $ctrl->forwardCommand($exp_gui);
132 break;
133
134 case "ilstylecharacteristicgui":
135 $this->prepareOutput();
136 $this->includeCSS();
137 $tabs->activateTab("sty_style_chars");
138 $gui = $this->gui_service->characteristic()->ilStyleCharacteristicGUI(
139 $this->getStyleSheet(),
140 $this->super_type,
141 $this->access_manager,
142 $this->characteristic_manager,
143 $this->image_manager
144 );
145 $ctrl->forwardCommand($gui);
146 break;
147
148 case "ilcontentstyleimagegui":
149 $this->prepareOutput();
150 $this->includeCSS();
151 $tabs->activateTab("sty_images");
152 $gui = $this->gui_service->image()->ilContentStyleImageGUI(
153 $this->access_manager,
154 $this->image_manager
155 );
156 $ctrl->forwardCommand($gui);
157 break;
158
159 default:
160 $this->prepareOutput();
161 $cmd .= "Object";
162 $this->$cmd();
163 break;
164 }
165 }
166
167 protected function getStyleSheet(): ilObjStyleSheet
168 {
170 $obj = $this->object;
171 return $obj;
172 }
173
174 public function viewObject(): void
175 {
176 $this->editObject();
177 }
178
179 public function createObject(): void
180 {
181 $tpl = $this->gui_service->ui()->mainTemplate();
182
183 $ilHelp = $this->help;
184
185 $forms = array();
186
187
188 $ilHelp->setScreenIdComponent("sty");
189 $ilHelp->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, "create");
190
191 $forms[] = $this->getCreateForm();
192 $forms[] = $this->getImportForm();
193 $forms[] = $this->getCloneForm();
194
196 }
197
198 protected function getRenderedCreationFormsHTML(array $forms): string
199 {
200 // #13168- sanity check
201 foreach ($forms as $id => $form) {
202 if (!$form instanceof ilPropertyFormGUI) {
203 unset($forms[$id]);
204 }
205 }
206
207 $acc = new ilAccordionGUI();
208 $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
209 $cnt = 1;
210 foreach ($forms as $form_type => $cf) {
211 $htpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "components/ILIAS/ILIASObject");
212
213 // using custom form titles (used for repository plugins)
214 $form_title = "";
215 if (method_exists($this, "getCreationFormTitle")) {
216 //$form_title = $this->getCreationFormTitle($form_type);
217 }
218 if (!$form_title) {
219 $form_title = $cf->getTitle();
220 }
221
222 // move title from form to accordion
223 $htpl->setVariable("TITLE", $this->lng->txt("option") . " " . $cnt . ": " . $form_title);
224 $cf->setTitle('');
225 $cf->setTitleIcon('');
226 $cf->setTableWidth("100%");
227
228 $acc->addItem($htpl->get(), $cf->getHTML());
229
230 $cnt++;
231 }
232
233 return "<div class='ilCreationFormSection'>" . $acc->getHTML() . "</div>";
234 }
235
236
237 protected function getCreationFormTitle(): string
238 {
239 return $this->lng->txt("sty_create_new_stylesheet");
240 }
241
242
243 protected function getCreateForm(): ilPropertyFormGUI
244 {
246 $form = new ilPropertyFormGUI();
248 $form->setTitle($this->lng->txt("sty_create_new_stylesheet"));
249
250 // title
251 $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
252 $ti->setMaxLength(128);
253 $ti->setSize(40);
254 $ti->setRequired(true);
255 $form->addItem($ti);
256
257 // description
258 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
259 $ta->setCols(40);
260 $ta->setRows(2);
261 $form->addItem($ta);
262
263 $form->addCommandButton("save", $this->lng->txt("save"));
264 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
265 return $form;
266 }
267
268 protected function getImportForm(): ilPropertyFormGUI
269 {
271 $form = new ilPropertyFormGUI();
273 $form->setTitle($this->lng->txt("sty_import_stylesheet"));
274
275 // title
276 $ti = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
277 $ti->setRequired(true);
278 $form->addItem($ti);
279
280 $form->addCommandButton("importStyle", $this->lng->txt("import"));
281 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
282 return $form;
283 }
284
285 protected function getCloneForm(): ilPropertyFormGUI
286 {
288 $form = new ilPropertyFormGUI();
290 $form->setTitle($this->lng->txt("sty_copy_other_stylesheet"));
291
292 // source
293 $ti = new ilSelectInputGUI($this->lng->txt("sty_source"), "source_style");
294 $ti->setRequired(true);
296 $form->addItem($ti);
297
298 $form->addCommandButton("copyStyle", $this->lng->txt("copy"));
299 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
300 return $form;
301 }
302
303 public function includeCSS(): void
304 {
305 $tpl = $this->gui_service->ui()->mainTemplate();
307 }
308
309
313 public function editObject(): void
314 {
315 $ctrl = $this->gui_service->ctrl();
316 $ctrl->redirectByClass("ilStyleCharacteristicGUI", "listCharacteristics");
317 }
318
319 public function propertiesObject(): void
320 {
321 $tpl = $this->gui_service->ui()->mainTemplate();
323
324 $this->initPropertiesForm();
325 $this->getPropertiesValues();
326 $tpl->setContent($this->form->getHTML());
327 }
328
332 public function getPropertiesValues(): void
333 {
334 $values = array();
335
336 $values["style_title"] = $this->object->getTitle();
337 $values["style_description"] = $this->object->getDescription();
338 $values["disable_auto_margins"] = (int) $this->object->lookupStyleSetting("disable_auto_margins");
339
340 $this->form->setValuesByArray($values);
341 }
342
346 public function initPropertiesForm(
347 string $a_mode = "edit"
348 ): void {
349 $ctrl = $this->gui_service->ctrl();
351
352 $this->form = new ilPropertyFormGUI();
353
354 // title
355 $ti = new ilTextInputGUI($this->lng->txt("title"), "style_title");
356 $ti->setMaxLength(128);
357 $ti->setSize(40);
358 $ti->setRequired(true);
359 $this->form->addItem($ti);
360
361 // description
362 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "style_description");
363 //$ta->setCols();
364 //$ta->setRows();
365 $this->form->addItem($ta);
366
367 // disable automatic margins for left/right alignment
368 $cb = new ilCheckboxInputGUI($this->lng->txt("sty_disable_auto_margins"), "disable_auto_margins");
369 $cb->setInfo($this->lng->txt("sty_disable_auto_margins_info"));
370 $this->form->addItem($cb);
371
372 // save and cancel commands
373
374 if ($a_mode == "create") {
375 $this->form->addCommandButton("save", $lng->txt("save"));
376 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
377 } else {
378 if ($this->access_manager->checkWrite()) {
379 $this->form->addCommandButton("update", $lng->txt("save"));
380 }
381 }
382
383 $this->form->setTitle($lng->txt("edit_stylesheet"));
384 $this->form->setFormAction($ctrl->getFormAction($this));
385 }
386
387 public function updateObject(): void
388 {
390 $ctrl = $this->gui_service->ctrl();
391 $tpl = $this->gui_service->ui()->mainTemplate();
392
393 $this->initPropertiesForm("edit");
394 if ($this->form->checkInput()) {
395 $this->object->setTitle($this->form->getInput("style_title"));
396 $this->object->setDescription($this->form->getInput("style_description"));
397 $this->object->writeStyleSetting(
398 "disable_auto_margins",
399 $this->form->getInput("disable_auto_margins")
400 );
401 $this->object->update();
402 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
403 $ctrl->redirect($this, "properties");
404 } else {
405 $this->form->setValuesByPost();
406 $tpl->setContent($this->form->getHTML());
407 }
408 }
409
410
411 public function exportStyleObject(): void
412 {
413 $exp = new ilExport();
414 $r = $exp->exportObject($this->object->getType(), $this->object->getId());
415
416 ilFileDelivery::deliverFileLegacy($r["directory"] . "/" . $r["file"], $r["file"], '', false, true);
417 }
418
422 public function deleteObject($a_error = false): void
423 {
424 $tpl = $this->gui_service->ui()->mainTemplate();
425 $ctrl = $this->gui_service->ctrl();
426
427 // display confirmation message
428 $cgui = new ilConfirmationGUI();
429 $cgui->setFormAction($ctrl->getFormAction($this));
430 $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
431 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
432 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
433
434 $caption = ilObject::_lookupTitle($this->object->getId());
435
436 $cgui->addItem("id[]", "", $caption);
437
438 $tpl->setContent($cgui->getHTML());
439 }
440
441 public function cancelDeleteObject(): void
442 {
443 $this->gui_service->ctrl()->returnToParent($this);
444 }
445
449 public function confirmedDeleteObject(): void
450 {
451 $this->object->delete();
452 $this->gui_service->ctrl()->returnToParent($this);
453 }
454
455 public function saveObject(): void
456 {
457 $ctrl = $this->gui_service->ctrl();
458
459 $form = $this->getCreateForm();
460 $form->checkInput();
461
462 if (!trim($form->getInput("style_title"))) {
463 $ctrl->redirect($this, "create");
464 }
465
466 // copy from default style or ... see #11330
467 $default_style = $this->settings->get("default_content_style_id");
468 if (ilObject::_lookupType((int) $default_style) == "sty") {
469 $style_obj = ilObjectFactory::getInstanceByObjId((int) $default_style);
470 $new_id = $style_obj->ilClone();
471 $newObj = new ilObjStyleSheet($new_id);
472 } else {
473 // ... import from basic zip file
474 // called from creation in the administration
475 // or creation in a repository object
476 $imp = new ilImport();
477 $style_id = $imp->importObject(
478 null,
480 "style.zip",
481 "sty",
482 "components/ILIAS/Style",
483 true
484 );
485
486 $newObj = new ilObjStyleSheet($style_id);
487 }
488
489 $newObj->setTitle($form->getInput("style_title"));
490 $newObj->setDescription($form->getInput("style_description"));
491 $newObj->update();
492 $this->object = $newObj;
493
495
496 // assign style to style sheet folder,
497 // if parent is style sheet folder
498 if ($this->requested_ref_id > 0) {
499 $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
500 if ($fold->getType() == "stys") {
501 $cont_style_settings = new ilContentStyleSettings();
502 $cont_style_settings->addStyle($newObj->getId());
503 $cont_style_settings->update();
504
505 ilObjStyleSheet::_writeStandard($newObj->getId(), true);
506 $this->tpl->setOnScreenMessage("success", $this->lng->txt("object_added"), true);
507 $this->ctrl->setParameterByClass(self::class, "obj_id", (string) $newObj->getId());
508 $this->ctrl->redirectByClass(self::class, "");
509 }
510 }
511 }
512
513 public function copyStyleObject(): int
514 {
515 $ctrl = $this->gui_service->ctrl();
516
517 $form = $this->getCloneForm();
518 $form->checkInput();
519 $new_id = 0;
520
521 if ($form->getInput("source_style") > 0) {
522 $style_obj = ilObjectFactory::getInstanceByObjId((int) $form->getInput("source_style"));
523 $new_id = $style_obj->ilClone();
524 }
525
526 // assign style to style sheet folder,
527 // if parent is style sheet folder
528 if ($this->requested_ref_id > 0) {
529 $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
530 if ($fold->getType() == "stys") {
531 $cont_style_settings = new ilContentStyleSettings();
532 $cont_style_settings->addStyle($new_id);
533 $cont_style_settings->update();
534 ilObjStyleSheet::_writeStandard($new_id, true);
535 $ctrl->returnToParent($this);
536 }
537 }
538 $this->object = new ilObjStyleSheet($new_id);
539
540 return $new_id;
541 }
542
546 public function importStyleObject(): int
547 {
548 $newObj = null;
549 // check file
550 $source = $_FILES["importfile"]["tmp_name"];
551 if (($source == 'none') || (!$source)) {
552 $this->ilias->raiseError("No file selected!", $this->ilias->error_obj->MESSAGE);
553 }
554
555 // check correct file type
556 $info = pathinfo($_FILES["importfile"]["name"]);
557 if (strtolower($info["extension"]) != "zip" && strtolower($info["extension"]) != "xml") {
558 $this->ilias->raiseError("File must be a zip or xml file!", $this->ilias->error_obj->MESSAGE);
559 }
560
561 // new import
562 $fname = explode("_", $_FILES["importfile"]["name"]);
563 if (strtolower($info["extension"]) == "zip" && $fname[4] == "sty") {
564 $imp = new ilImport();
565 $new_id = $imp->importObject(
566 null,
567 $_FILES["importfile"]["tmp_name"],
568 $_FILES["importfile"]["name"],
569 "sty"
570 );
571 if ($new_id > 0) {
572 $newObj = ilObjectFactory::getInstanceByObjId($new_id);
573 }
574 } else { // old import
575 $newObj = new ilObjStyleSheet();
576 $newObj->import($_FILES["importfile"]);
577 }
578
579 // assign style to style sheet folder,
580 // if parent is style sheet folder
581 if ($this->requested_ref_id > 0) {
582 $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
583 if ($fold->getType() == "stys") {
584 $cont_style_settings = new ilContentStyleSettings();
585 $cont_style_settings->addStyle($newObj->getId());
586 $cont_style_settings->update();
587 ilObjStyleSheet::_writeStandard($newObj->getId(), true);
588 $this->ctrl->returnToParent($this);
589 }
590 }
591 $this->object = $newObj;
592 return $newObj->getId();
593 }
594
595 public function handleImport(
596 \ILIAS\FileUpload\FileUpload $upload,
597 \ILIAS\FileUpload\DTO\UploadResult $result
598 ): \ILIAS\FileUpload\Handler\BasicHandlerResult {
599 $new_id = $this->domain->style(0)->importFromUploadResult(
600 $result
601 );
602 return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
603 'obj_id',
604 \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
605 (string) $new_id,
606 ''
607 );
608 }
609
610
611 public function cancelObject(): void
612 {
614
615 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_cancel"), true);
616 $this->ctrl->returnToParent($this);
617 }
618
619 public function getAdminTabs(): void
620 {
621 $this->getTabs();
622 }
623
624 protected function getTabs(): void
625 {
627 $ilHelp = $this->help;
628 $tabs = $this->gui_service->tabs();
629 $ilHelp->setScreenIdComponent("sty");
630 // back to upper context
631 $tabs->setBackTarget(
632 $lng->txt("back"),
633 $this->ctrl->getLinkTarget($this, "returnToUpperContext")
634 );
635
636 // style classes
637 $tabs->addTarget(
638 "sty_style_chars",
639 $this->ctrl->getLinkTarget($this, "edit"),
640 array("edit", ""),
641 get_class($this)
642 );
643
644 // colors
645 $tabs->addTarget(
646 "sty_colors",
647 $this->ctrl->getLinkTarget($this, "listColors"),
648 "listColors",
649 get_class($this)
650 );
651
652 // images
653 $tabs->addTarget(
654 "sty_images",
655 $this->ctrl->getLinkTargetByClass("ilContentStyleImageGUI", ""),
656 "",
657 "ilContentStyleImageGUI"
658 );
659
660 // media queries
661 $tabs->addTarget(
662 "sty_media_queries",
663 $this->ctrl->getLinkTarget($this, "listMediaQueries"),
664 "listMediaQueries",
665 get_class($this)
666 );
667
668
669 // table templates
670 $tabs->addTarget(
671 "sty_templates",
672 $this->ctrl->getLinkTarget($this, "listTemplates"),
673 "listTemplates",
674 get_class($this)
675 );
676
677 // settings
678 $tabs->addTarget(
679 "settings",
680 $this->ctrl->getLinkTarget($this, "properties"),
681 "properties",
682 get_class($this)
683 );
684
685 // export
686 $tabs->addTarget(
687 "export",
688 $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
689 "",
690 "ilexportgui"
691 );
692 }
693
694 public function setTemplatesSubTabs(): void
695 {
696 $ilTabs = $this->gui_service->tabs();
697 $ilCtrl = $this->ctrl;
698
700
701 foreach ($types as $t => $c) {
702 $ilCtrl->setParameter($this, "temp_type", $t);
703 $ilTabs->addSubTabTarget(
704 "sty_" . $t . "_templates",
705 $this->ctrl->getLinkTarget($this, "listTemplates"),
706 array("listTemplates", ""),
707 get_class($this)
708 );
709 }
710
711 $ilCtrl->setParameter($this, "temp_type", $this->style_request->getTempType());
712 }
713
718 protected function addAdminLocatorItems(bool $do_not_add_object = false): void
719 {
720 $ilLocator = $this->gui_service->locator();
721
722 if ($this->style_request->getAdminMode() == "settings") { // system settings
723 parent::addAdminLocatorItems(true);
724
725 $ilLocator->addItem(
726 $this->lng->txt("obj_stys"),
727 $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui", "")
728 );
729
730 $ilLocator->addItem(
731 $this->lng->txt("content_styles"),
732 $this->ctrl->getLinkTargetByClass("ilcontentstylesettingsgui", "")
733 );
734
735 if ($this->style_request->getObjId() > 0) {
736 $ilLocator->addItem(
737 $this->object->getTitle(),
738 $this->ctrl->getLinkTarget($this, "edit")
739 );
740 }
741 }
742 }
743
747 public static function getStyleExampleHTML(
748 string $a_type,
749 string $a_class
750 ): string {
751 global $DIC;
752
753 $lng = $DIC->language();
754
755 $c = explode(":", $a_class);
756 $a_class = $c[0];
757
758 $ex_tpl = new ilTemplate("tpl.style_example.html", true, true, "components/ILIAS/Style/Content");
759
760 if ($ex_tpl->blockExists("Example_" . $a_type)) {
761 $ex_tpl->setCurrentBlock("Example_" . $a_type);
762 } else {
763 $ex_tpl->setCurrentBlock("Example_default");
764 }
765 $ex_tpl->setVariable("EX_CLASS", "ilc_" . $a_type . "_" . $a_class);
766 $ex_tpl->setVariable("EX_TEXT", "ABC abc 123");
767 if (in_array($a_type, array("media_cont", "qimg"))) {
768 //
769 }
770 if (in_array($a_type, array("table", "table_caption"))) {
771 $ex_tpl->setVariable("TXT_CAPTION", $lng->txt("sty_caption"));
772 }
773 if (in_array($a_class, array("OrderListItemHorizontal", "OrderListHorizontal"))) {
774 $ex_tpl->setVariable("HOR", "Horizontal");
775 }
776 $ex_tpl->parseCurrentBlock();
777
778 return $ex_tpl->get();
779 }
780
781
782 //
783 // Color management
784 //
785
789 public function listColorsObject(): void
790 {
791 $tpl = $this->gui_service->ui()->mainTemplate();
792 $ilToolbar = $this->gui_service->toolbar();
793 $ilCtrl = $this->ctrl;
794
795 if ($this->access_manager->checkWrite()) {
796 $ilToolbar->addButton(
797 $this->lng->txt("sty_add_color"),
798 $ilCtrl->getLinkTarget($this, "addColor")
799 );
800 }
801
802 $table_gui = new ilStyleColorTableGUI(
803 $this,
804 "listColors",
805 $this->getStyleSheet(),
806 $this->access_manager
807 );
808 $tpl->setContent($table_gui->getHTML());
809 }
810
811 public function addColorObject(): void
812 {
813 $tpl = $this->gui_service->ui()->mainTemplate();
814
815 $this->initColorForm();
816 $tpl->setContent($this->form_gui->getHTML());
817 }
818
819 public function editColorObject(): void
820 {
821 $tpl = $this->gui_service->ui()->mainTemplate();
822 $ilCtrl = $this->ctrl;
823
824 $ilCtrl->setParameter($this, "c_name", $this->style_request->getColorName());
825 $this->initColorForm("edit");
826 $this->getColorFormValues();
827 $tpl->setContent($this->form_gui->getHTML());
828 }
829
830
831 public function initColorForm(
832 string $a_mode = "create"
833 ): void {
834 $lng = $this->lng;
835 $ilCtrl = $this->ctrl;
836
837 $this->form_gui = new ilPropertyFormGUI();
838
839 $this->form_gui->setTitle($lng->txt("sty_add_color"));
840
841 // name
842 $name_input = new ilRegExpInputGUI($lng->txt("sty_color_name"), "color_name");
843 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
844 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
845 $name_input->setRequired(true);
846 $name_input->setSize(15);
847 $name_input->setMaxLength(15);
848 $this->form_gui->addItem($name_input);
849
850 // code
851 $color_input = new ilColorPickerInputGUI($lng->txt("sty_color_code"), "color_code");
852 $color_input->setRequired(true);
853 $color_input->setDefaultColor("");
854 $this->form_gui->addItem($color_input);
855
856 if ($a_mode == "create") {
857 $this->form_gui->addCommandButton("saveColor", $lng->txt("save"));
858 } else {
859 $this->form_gui->addCommandButton("updateColor", $lng->txt("save"));
860 }
861 $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
862 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
863 }
864
868 public function getColorFormValues(): void
869 {
870 $c_name = $this->style_request->getColorName();
871 if ($c_name != "") {
872 $values["color_name"] = $c_name;
873 $values["color_code"] = $this->object->getColorCodeForName($c_name);
874 $this->form_gui->setValuesByArray($values);
875 }
876 }
877
881 public function cancelColorSavingObject(): void
882 {
883 $ilCtrl = $this->ctrl;
884
885 $ilCtrl->redirect($this, "listColors");
886 }
887
891 public function saveColorObject(): void
892 {
893 $tpl = $this->gui_service->ui()->mainTemplate();
894 $ilCtrl = $this->ctrl;
896
897 $this->initColorForm();
898 if ($this->form_gui->checkInput()) {
899 if ($this->color_manager->colorExists($this->form_gui->getInput("color_name"))) {
900 $col_input = $this->form_gui->getItemByPostVar("color_name");
901 $col_input->setAlert($lng->txt("sty_color_already_exists"));
902 } else {
903 $this->color_manager->addColor(
904 $this->form_gui->getInput("color_name"),
905 $this->form_gui->getInput("color_code")
906 );
907 $ilCtrl->redirect($this, "listColors");
908 }
909 }
910 $this->form_gui->setValuesByPost();
911 $tpl->setContent($this->form_gui->getHTML());
912 }
913
917 public function updateColorObject(): void
918 {
919 $tpl = $this->gui_service->ui()->mainTemplate();
920 $ilCtrl = $this->ctrl;
922
923 $c_name = $this->style_request->getColorName();
924 $ilCtrl->setParameter($this, "c_name", $c_name);
925 $this->initColorForm("edit");
926
927 if ($this->form_gui->checkInput()) {
928 if ($this->color_manager->colorExists($this->form_gui->getInput("color_name")) &&
929 $this->form_gui->getInput("color_name") != $c_name) {
930 $col_input = $this->form_gui->getItemByPostVar("color_name");
931 $col_input->setAlert($lng->txt("sty_color_already_exists"));
932 } else {
933 $this->color_manager->updateColor(
934 $c_name,
935 $this->form_gui->getInput("color_name"),
936 $this->form_gui->getInput("color_code")
937 );
938 $ilCtrl->redirect($this, "listColors");
939 }
940 }
941 $this->form_gui->setValuesByPost();
942 $tpl->setContent($this->form_gui->getHTML());
943 }
944
948 public function deleteColorConfirmationObject(): void
949 {
950 $ilCtrl = $this->ctrl;
951 $tpl = $this->gui_service->ui()->mainTemplate();
953
954 $colors = $this->style_request->getColors();
955 if (count($colors) == 0) {
956 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
957 $ilCtrl->redirect($this, "listColors");
958 } else {
959 $cgui = new ilConfirmationGUI();
960 $cgui->setFormAction($ilCtrl->getFormAction($this));
961 $cgui->setHeaderText($lng->txt("sty_confirm_color_deletion"));
962 $cgui->setCancel($lng->txt("cancel"), "cancelColorDeletion");
963 $cgui->setConfirm($lng->txt("delete"), "deleteColor");
964
965 foreach ($colors as $c) {
966 $cgui->addItem("color[]", ilLegacyFormElementsUtil::prepareFormOutput($c), $c);
967 }
968
969 $tpl->setContent($cgui->getHTML());
970 }
971 }
972
976 public function cancelColorDeletionObject(): void
977 {
978 $ilCtrl = $this->ctrl;
979 $ilCtrl->redirect($this, "listColors");
980 }
981
982 public function deleteColorObject(): void
983 {
984 $ilCtrl = $this->ctrl;
985
986 $colors = $this->style_request->getColors();
987 foreach ($colors as $c) {
988 $this->object->removeColor($c);
989 }
990
991 $ilCtrl->redirect($this, "listColors");
992 }
993
994 //
995 // Media query management
996 //
997
998 public function listMediaQueriesObject(): void
999 {
1000 $tpl = $this->gui_service->ui()->mainTemplate();
1001 $ilToolbar = $this->gui_service->toolbar();
1002 $ilCtrl = $this->ctrl;
1003
1004 if ($this->access_manager->checkWrite()) {
1005 $ilToolbar->addButton(
1006 $this->lng->txt("sty_add_media_query"),
1007 $ilCtrl->getLinkTarget($this, "addMediaQuery")
1008 );
1009 }
1010
1011 $table_gui = new ilStyleMediaQueryTableGUI(
1012 $this,
1013 "listMediaQueries",
1014 $this->getStyleSheet(),
1015 $this->access_manager
1016 );
1017 $tpl->setContent($table_gui->getHTML());
1018 }
1019
1020 public function addMediaQueryObject(): void
1021 {
1022 $tpl = $this->gui_service->ui()->mainTemplate();
1023
1024 $this->initMediaQueryForm();
1025 $tpl->setContent($this->form_gui->getHTML());
1026 }
1027
1028 public function editMediaQueryObject(): void
1029 {
1030 $tpl = $this->gui_service->ui()->mainTemplate();
1031 $ilCtrl = $this->ctrl;
1032
1033 $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
1034 $this->initMediaQueryForm("edit");
1035 $this->getMediaQueryFormValues();
1036 $tpl->setContent($this->form_gui->getHTML());
1037 }
1038
1039
1043 public function initMediaQueryForm(
1044 string $a_mode = "create"
1045 ): void {
1046 $lng = $this->lng;
1047 $ilCtrl = $this->ctrl;
1048
1049 $this->form_gui = new ilPropertyFormGUI();
1050
1051 $this->form_gui->setTitle($lng->txt("sty_add_media_query"));
1052
1053 // media query
1054 $ti = new ilTextInputGUI("@media", "mquery");
1055 $ti->setMaxLength(2000);
1056 $ti->setInfo($lng->txt("sty_add_media_query_info"));
1057 $this->form_gui->addItem($ti);
1058
1059
1060 if ($a_mode == "create") {
1061 $this->form_gui->addCommandButton("saveMediaQuery", $lng->txt("save"));
1062 } else {
1063 $this->form_gui->addCommandButton("updateMediaQuery", $lng->txt("save"));
1064 }
1065 $this->form_gui->addCommandButton("listMediaQueries", $lng->txt("cancel"));
1066 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1067 }
1068
1072 public function getMediaQueryFormValues(): void
1073 {
1074 $values = [];
1075 if ($this->style_request->getMediaQueryId() > 0) {
1076 foreach ($this->object->getMediaQueries() as $mq) {
1077 if ($mq["id"] == $this->style_request->getMediaQueryId()) {
1078 $values["mquery"] = $mq["mquery"];
1079 }
1080 }
1081 $this->form_gui->setValuesByArray($values);
1082 }
1083 }
1084
1088 public function saveMediaQueryObject(): void
1089 {
1090 $tpl = $this->gui_service->ui()->mainTemplate();
1091 $ilCtrl = $this->ctrl;
1092 $lng = $this->lng;
1093
1094 $this->initMediaQueryForm();
1095
1096 if ($this->form_gui->checkInput()) {
1097 $this->object->addMediaQuery($this->form_gui->getInput("mquery"));
1098 $ilCtrl->redirect($this, "listMediaQueries");
1099 }
1100 $this->form_gui->setValuesByPost();
1101 $tpl->setContent($this->form_gui->getHTML());
1102 }
1103
1104 public function updateMediaQueryObject(): void
1105 {
1106 $tpl = $this->gui_service->ui()->mainTemplate();
1107 $ilCtrl = $this->ctrl;
1108
1109 $this->initMediaQueryForm("edit");
1110
1111 if ($this->form_gui->checkInput()) {
1112 $this->object->updateMediaQuery(
1113 $this->style_request->getMediaQueryId(),
1114 $this->form_gui->getInput("mquery")
1115 );
1116 $ilCtrl->redirect($this, "listMediaQueries");
1117 }
1118 $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
1119 $this->form_gui->setValuesByPost();
1120 $tpl->setContent($this->form_gui->getHTML());
1121 }
1122
1124 {
1125 $ilCtrl = $this->ctrl;
1126 $tpl = $this->gui_service->ui()->mainTemplate();
1127 $lng = $this->lng;
1128
1129 $mq_ids = $this->style_request->getMediaQueryIds();
1130 if (count($mq_ids) == 0) {
1131 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1132 $ilCtrl->redirect($this, "listMediaQueries");
1133 } else {
1134 $cgui = new ilConfirmationGUI();
1135 $cgui->setFormAction($ilCtrl->getFormAction($this));
1136 $cgui->setHeaderText($lng->txt("sty_sure_del_mqueries"));
1137 $cgui->setCancel($lng->txt("cancel"), "listMediaQueries");
1138 $cgui->setConfirm($lng->txt("delete"), "deleteMediaQueries");
1139
1140 foreach ($mq_ids as $i) {
1141 $mq = $this->object->getMediaQueryForId($i);
1142 $cgui->addItem("mq_id[]", (string) $i, $mq["mquery"]);
1143 }
1144
1145 $tpl->setContent($cgui->getHTML());
1146 }
1147 }
1148
1149 public function deleteMediaQueriesObject(): void
1150 {
1151 $ilCtrl = $this->ctrl;
1152
1153 $mq_ids = $this->style_request->getMediaQueryIds();
1154 if ($this->access_manager->checkWrite()) {
1155 foreach ($mq_ids as $id) {
1156 $this->object->deleteMediaQuery($id);
1157 }
1158 }
1159 $ilCtrl->redirect($this, "listMediaQueries");
1160 }
1161
1162 public function saveMediaQueryOrderObject(): void
1163 {
1164 $ilCtrl = $this->ctrl;
1165
1166 $order = $this->style_request->getOrder();
1167 if (count($order) > 0) {
1168 $this->getStyleSheet()->saveMediaQueryOrder($order);
1169 }
1170 $ilCtrl->redirect($this, "listMediaQueries");
1171 }
1172
1173
1174 //
1175 // Templates management
1176 //
1177
1181 public function listTemplatesObject(): void
1182 {
1183 $tpl = $this->gui_service->ui()->mainTemplate();
1184 $ilTabs = $this->gui_service->tabs();
1185 $ilCtrl = $this->ctrl;
1186 $ilToolbar = $this->gui_service->toolbar();
1187
1188 $ctype = $this->style_request->getTempType();
1189 if ($ctype == "") {
1190 $ctype = "table";
1191 }
1192
1193 $this->setTemplatesSubTabs();
1194 $ilCtrl->setParameter($this, "temp_type", $ctype);
1195 $ilTabs->setSubTabActive("sty_" . $ctype . "_templates");
1196
1197 // action commands
1198 if ($this->access_manager->checkWrite()) {
1199 if ($ctype == "table") {
1200 $ilToolbar->addButton(
1201 $this->lng->txt("sty_generate_template"),
1202 $ilCtrl->getLinkTarget($this, "generateTemplate")
1203 );
1204 }
1205 $ilToolbar->addButton(
1206 $this->lng->txt("sty_add_template"),
1207 $ilCtrl->getLinkTarget($this, "addTemplate")
1208 );
1209 }
1210
1211
1212
1213 $this->includeCSS();
1214 $table_gui = new ilTableTemplatesTableGUI(
1215 $ctype,
1216 $this,
1217 "listTemplates",
1218 $this->getStyleSheet(),
1219 $this->access_manager
1220 );
1221 $tpl->setContent($table_gui->getHTML());
1222 }
1223
1224 public function addTemplateObject(): void
1225 {
1226 $tpl = $this->gui_service->ui()->mainTemplate();
1227
1228 $this->initTemplateForm();
1229 $tpl->setContent($this->form_gui->getHTML());
1230 }
1231
1232 public function editTemplateObject(): void
1233 {
1234 $ilCtrl = $this->ctrl;
1235
1236 $ilCtrl->setParameter(
1237 $this,
1238 "t_id",
1239 $this->style_request->getTemplateId()
1240 );
1241 $this->initTemplateForm("edit");
1242 $this->getTemplateFormValues();
1243
1244 $this->displayTemplateEditForm();
1245 }
1246
1247 public function getTemplatePreview(
1248 string $a_type,
1249 int $a_t_id,
1250 bool $a_small_mode = false
1251 ): string {
1252 return $this->_getTemplatePreview(
1253 $this->getStyleSheet(),
1254 $a_type,
1255 $a_t_id,
1256 $a_small_mode
1257 );
1258 }
1259
1263 public static function _getTemplatePreview(
1264 ilObjStyleSheet $a_style,
1265 string $a_type,
1266 int $a_t_id,
1267 bool $a_small_mode = false
1268 ): string {
1269 global $DIC;
1270
1271 $lng = $DIC->language();
1272 $p_content = "";
1273
1274 $kr = $kc = 7;
1275 if ($a_small_mode) {
1276 $kr = 6;
1277 $kc = 5;
1278 }
1279
1280 $ts = $a_style->getTemplate($a_t_id);
1281 $t = $ts["classes"];
1282
1283 // preview
1284 if ($a_type == "table") {
1285 $p_content = '<PageContent><Table DataTable="y"';
1286 $t["row_head"] = $t["row_head"] ?? "";
1287 $t["row_foot"] = $t["row_foot"] ?? "";
1288 $t["col_head"] = $t["col_head"] ?? "";
1289 $t["col_foot"] = $t["col_foot"] ?? "";
1290 if ($t["row_head"] != "") {
1291 $p_content .= ' HeaderRows="1"';
1292 }
1293 if ($t["row_foot"] != "") {
1294 $p_content .= ' FooterRows="1"';
1295 }
1296 if ($t["col_head"] != "") {
1297 $p_content .= ' HeaderCols="1"';
1298 }
1299 if ($t["col_foot"] != "") {
1300 $p_content .= ' FooterCols="1"';
1301 }
1302 $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1303 if (!$a_small_mode) {
1304 $p_content .= '<Caption>' . $lng->txt("sty_caption") . '</Caption>';
1305 }
1306 for ($i = 1; $i <= $kr; $i++) {
1307 $p_content .= '<TableRow>';
1308 for ($j = 1; $j <= $kc; $j++) {
1309 if ($a_small_mode) {
1310 $cell = '&lt;div style="height:2px;"&gt;&lt;/div&gt;';
1311 } else {
1312 $cell = 'xxx';
1313 }
1314 $p_content .= '<TableData><PageContent><Paragraph Characteristic="TableContent">' . $cell . '</Paragraph></PageContent></TableData>';
1315 }
1316 $p_content .= '</TableRow>';
1317 }
1318 $p_content .= '</Table></PageContent>';
1319 }
1320
1321 if ($a_type == "vaccordion" || $a_type == "haccordion" || $a_type == "carousel") {
1323
1324 if ($a_small_mode) {
1325 $c = '&amp;nbsp;';
1326 $h = '&amp;nbsp;';
1327 } else {
1328 $c = 'xxx';
1329 $h = 'head';
1330 }
1331 if ($a_type == "vaccordion") {
1332 $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="VerticalAccordion" ';
1333 if ($a_small_mode) {
1334 $p_content .= ' ContentWidth="70"';
1335 }
1336 } elseif ($a_type == "haccordion") {
1337 $p_content = '<PageContent><Tabs Type="HorizontalAccordion"';
1338 $p_content .= ' ContentHeight="40"';
1339 if ($a_small_mode) {
1340 $p_content .= ' ContentWidth="70"';
1341 $c = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
1342 }
1343 } elseif ($a_type == "carousel") {
1344 $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="Carousel" ';
1345 if ($a_small_mode) {
1346 $p_content .= ' ContentWidth="70"';
1347 }
1348 }
1349
1350
1351 $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1352 $p_content .= '<Tab><PageContent><Paragraph>' . $c . '</Paragraph></PageContent>';
1353 $p_content .= '<TabCaption>' . $h . '</TabCaption>';
1354 $p_content .= '</Tab>';
1355 $p_content .= '</Tabs></PageContent>';
1356 }
1357 //echo htmlentities($p_content);
1358 $txml = $a_style->getTemplateXML();
1359 //echo htmlentities($txml); exit;
1360 $p_content .= $txml;
1361 $r_content = ilPCTableGUI::_renderTable($p_content, "");
1362
1363 // fix carousel template visibility
1364 if ($a_type == "carousel") {
1365 $r_content .= "<style>.owl-carousel{ display:block !important; }</style>";
1366 }
1367
1368 //echo htmlentities($r_content); exit;
1369 return $r_content;
1370 }
1371
1375 public function initTemplateForm(string $a_mode = "create"): void
1376 {
1377 $lng = $this->lng;
1378 $ilCtrl = $this->ctrl;
1379
1380 $this->form_gui = new ilPropertyFormGUI();
1381
1382 if ($a_mode == "create") {
1383 $this->form_gui->setTitle($lng->txt("sty_add_template"));
1384 } else {
1385 $this->form_gui->setTitle($lng->txt("sty_edit_template"));
1386 }
1387
1388 // name
1389 $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1390 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1391 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1392 $name_input->setRequired(true);
1393 $name_input->setSize(30);
1394 $name_input->setMaxLength(30);
1395 $this->form_gui->addItem($name_input);
1396
1397 // template style classes
1399 $this->style_request->getTempType()
1400 );
1401
1402 foreach ($scs as $sc => $st) {
1403 $sc_input = new ilSelectInputGUI($lng->txt("sty_" . $sc . "_class"), $sc . "_class");
1404 $chars = $this->object->getCharacteristics($st);
1405 $options = array("" => "");
1406 foreach ($chars as $char) {
1407 $options[$char] = $char;
1408 }
1409 $sc_input->setOptions($options);
1410 $this->form_gui->addItem($sc_input);
1411 }
1412
1413 if ($a_mode == "create") {
1414 $this->form_gui->addCommandButton("saveTemplate", $lng->txt("save"));
1415 } else {
1416 $this->form_gui->addCommandButton("refreshTemplate", $lng->txt("save_refresh"));
1417 $this->form_gui->addCommandButton("updateTemplate", $lng->txt("save_return"));
1418 }
1419 $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1420 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1421 }
1422
1426 public function cancelTemplateSavingObject(): void
1427 {
1428 $ilCtrl = $this->ctrl;
1429 $ilCtrl->redirect($this, "listTemplates");
1430 }
1431
1432
1436 public function saveTemplateObject(): void
1437 {
1438 $tpl = $this->gui_service->ui()->mainTemplate();
1439 $ilCtrl = $this->ctrl;
1440 $lng = $this->lng;
1441
1442 $this->initTemplateForm();
1443 $temp_type = $this->style_request->getTempType();
1444
1445 if ($this->form_gui->checkInput()) {
1446 if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1447 $name_input = $this->form_gui->getItemByPostVar("name");
1448 $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1449 } else {
1450 $classes = array();
1451 foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1452 $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1453 }
1454 $t_id = $this->object->addTemplate(
1455 $temp_type,
1456 $this->form_gui->getInput("name"),
1457 $classes
1458 );
1459 $this->object->writeTemplatePreview(
1460 $t_id,
1461 $this->getTemplatePreview($temp_type, $t_id, true)
1462 );
1463 $ilCtrl->redirect($this, "listTemplates");
1464 }
1465 }
1466 $this->form_gui->setValuesByPost();
1467 $tpl->setContent($this->form_gui->getHTML());
1468 }
1469
1470 public function updateTemplateObject(
1471 bool $a_refresh = false
1472 ): void {
1473 $ilCtrl = $this->ctrl;
1474 $lng = $this->lng;
1475
1476 $ilCtrl->setParameter($this, "t_id", $this->style_request->getTemplateId());
1477 $this->initTemplateForm("edit");
1478 $temp_type = $this->style_request->getTempType();
1479
1480 $t_id = $this->style_request->getTemplateId();
1481 if ($this->form_gui->checkInput()) {
1482 if ($this->object->templateExists($this->form_gui->getInput("name")) &&
1483 $this->form_gui->getInput("name") != ilObjStyleSheet::_lookupTemplateName($t_id)) {
1484 $name_input = $this->form_gui->getItemByPostVar("name");
1485 $name_input->setAlert($lng->txt("sty_template_already_exists"));
1486 } else {
1487 $classes = array();
1488 foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1489 $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1490 }
1491
1492 $this->object->updateTemplate(
1493 $t_id,
1494 $this->form_gui->getInput("name"),
1495 $classes
1496 );
1497 $this->object->writeTemplatePreview(
1498 $t_id,
1499 $this->getTemplatePreview($temp_type, $t_id, true)
1500 );
1501 if (!$a_refresh) {
1502 $ilCtrl->redirect($this, "listTemplates");
1503 }
1504 }
1505 }
1506
1507 $this->form_gui->setValuesByPost();
1508 $this->displayTemplateEditForm();
1509 }
1510
1511 public function displayTemplateEditForm(): void
1512 {
1513 $tpl = $this->gui_service->ui()->mainTemplate();
1514
1515 $a_tpl = new ilTemplate(
1516 "tpl.template_edit.html",
1517 true,
1518 true,
1519 "components/ILIAS/Style/Content"
1520 );
1521 $this->includeCSS();
1522 $a_tpl->setVariable("FORM", $this->form_gui->getHTML());
1523 $a_tpl->setVariable("PREVIEW", $this->getTemplatePreview(
1524 $this->style_request->getTempType(),
1525 $this->style_request->getTemplateId()
1526 ));
1527 $tpl->setContent($a_tpl->get());
1528 }
1529
1533 public function refreshTemplateObject(): void
1534 {
1535 $this->updateTemplateObject(true);
1536 }
1537
1541 public function getTemplateFormValues(): void
1542 {
1543 $t_id = $this->style_request->getTemplateId();
1544 if ($t_id > 0) {
1545 $t = $this->object->getTemplate($t_id);
1546
1547 $values["name"] = $t["name"];
1549 $this->style_request->getTempType()
1550 );
1551 foreach ($scs as $k => $type) {
1552 $values[$k . "_class"] = $t["classes"][$k] ?? "";
1553 }
1554 $this->form_gui->setValuesByArray($values);
1555 }
1556 }
1557
1561 public function deleteTemplateConfirmationObject(): void
1562 {
1563 $ilCtrl = $this->ctrl;
1564 $tpl = $this->gui_service->ui()->mainTemplate();
1565 $lng = $this->lng;
1566
1567 $tids = $this->style_request->getTemplateIds();
1568 if (count($tids) == 0) {
1569 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1570 $ilCtrl->redirect($this, "listTemplates");
1571 } else {
1572 $cgui = new ilConfirmationGUI();
1573 $cgui->setFormAction($ilCtrl->getFormAction($this));
1574 $cgui->setHeaderText($lng->txt("sty_confirm_template_deletion"));
1575 $cgui->setCancel($lng->txt("cancel"), "cancelTemplateDeletion");
1576 $cgui->setConfirm($lng->txt("sty_del_template"), "deleteTemplate");
1577
1578 foreach ($tids as $tid) {
1579 $classes = $this->object->getTemplateClasses($tid);
1580 $cl_str = "";
1581 $listed = array();
1582 foreach ($classes as $cl) {
1583 if ($cl != "" && !($listed[$cl] ?? false)) {
1584 $cl_str .= '<div>- ' .
1585 $cl . "</div>";
1586 $listed[$cl] = true;
1587 }
1588 }
1589 if ($cl_str != "") {
1590 $cl_str = '<div style="padding-left:30px;" class="small">' .
1591 "<div><i>" . $lng->txt("sty_style_class") . "</i></div>" . $cl_str . "</div>";
1592 }
1593 $cgui->addItem("tid[]", (string) $tid, $this->object->lookupTemplateName($tid) . $cl_str);
1594 }
1595
1596 $cgui->addButton($lng->txt("sty_del_template_keep_classes"), "deleteTemplateKeepClasses");
1597
1598 $tpl->setContent($cgui->getHTML());
1599 }
1600 }
1601
1605 public function cancelTemplateDeletionObject(): void
1606 {
1607 $ilCtrl = $this->ctrl;
1608
1609 $ilCtrl->redirect($this, "listTemplates");
1610 }
1611
1612 public function deleteTemplateKeepClassesObject(): void
1613 {
1614 $ilCtrl = $this->ctrl;
1615
1616 $tids = $this->style_request->getTemplateIds();
1617 foreach ($tids as $tid) {
1618 $this->object->removeTemplate($tid);
1619 }
1620
1621 $ilCtrl->redirect($this, "listTemplates");
1622 }
1623
1630 public function deleteTemplateObject(): void
1631 {
1632 $ilCtrl = $this->ctrl;
1633
1634 $tids = $this->style_request->getTemplateIds();
1635 foreach ($tids as $tid) {
1636 $cls = $this->object->getTemplateClasses($tid);
1637 foreach ($cls as $k => $cls2) {
1638 $ty = $this->object->determineTemplateStyleClassType(
1639 $this->style_request->getTempType(),
1640 $k
1641 );
1642 $this->characteristic_manager->deleteCharacteristic($ty, $cls2);
1643 }
1644 $this->object->removeTemplate($tid);
1645 }
1646
1647 $ilCtrl->redirect($this, "listTemplates");
1648 }
1649
1650 public function generateTemplateObject(): void
1651 {
1652 $tpl = $this->gui_service->ui()->mainTemplate();
1653
1654 $this->initTemplateGenerationForm();
1655 $tpl->setContent($this->form_gui->getHTML());
1656 }
1657
1661 public function initTemplateGenerationForm(): void
1662 {
1663 $lng = $this->lng;
1664 $ilCtrl = $this->ctrl;
1665
1666 $this->form_gui = new ilPropertyFormGUI();
1667
1668 $this->form_gui->setTitle($lng->txt("sty_generate_template"));
1669
1670 // name
1671 $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1672 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1673 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1674 $name_input->setRequired(true);
1675 $name_input->setSize(30);
1676 $name_input->setMaxLength(30);
1677 $this->form_gui->addItem($name_input);
1678
1679 // basic layout
1680 $bl_input = new ilSelectInputGUI($lng->txt("sty_template_layout"), "layout");
1681 $options = array(
1682 "coloredZebra" => $lng->txt("sty_table_template_colored_zebra"),
1683 "bwZebra" => $lng->txt("sty_table_template_bw_zebra"),
1684 "noZebra" => $lng->txt("sty_table_template_no_zebra")
1685 );
1686 $bl_input->setOptions($options);
1687 $this->form_gui->addItem($bl_input);
1688
1689 // top bottom padding
1690 $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_top_bottom_padding"), "tb_padding");
1691 $num_input->setAllowPercentage(false);
1692 $num_input->setValue("3px");
1693 $this->form_gui->addItem($num_input);
1694
1695 // left right padding
1696 $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_left_right_padding"), "lr_padding");
1697 $num_input->setAllowPercentage(false);
1698 $num_input->setValue("10px");
1699 $this->form_gui->addItem($num_input);
1700
1701 // base color
1702 $bc_input = new ilSelectInputGUI($lng->txt("sty_base_color"), "base_color");
1703 $cs = $this->object->getColors();
1704 $options = array();
1705 foreach ($cs as $c) {
1706 $options[$c["name"]] = $c["name"];
1707 }
1708 $bc_input->setOptions($options);
1709 $this->form_gui->addItem($bc_input);
1710
1711 // Lightness Settings
1712 $lss = array("border" => 90, "header_text" => 70, "header_bg" => 0,
1713 "cell1_text" => -60, "cell1_bg" => 90, "cell2_text" => -60, "cell2_bg" => 75);
1714 foreach ($lss as $ls => $v) {
1715 $l_input = new ilNumberInputGUI($lng->txt("sty_lightness_" . $ls), "lightness_" . $ls);
1716 $l_input->setMaxValue(100);
1717 $l_input->setMinValue(-100);
1718 $l_input->setValue((string) $v);
1719 $l_input->setSize(4);
1720 $l_input->setMaxLength(4);
1721 $this->form_gui->addItem($l_input);
1722 }
1723
1724 $this->form_gui->addCommandButton("templateGeneration", $lng->txt("generate"));
1725 $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1726 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1727 }
1728
1732 public function templateGenerationObject(): void
1733 {
1734 $tpl = $this->gui_service->ui()->mainTemplate();
1735 $ilCtrl = $this->ctrl;
1736 $lng = $this->lng;
1737
1738 $this->initTemplateGenerationForm();
1739
1740 if ($this->form_gui->checkInput()) {
1741 if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1742 $name_input = $this->form_gui->getItemByPostVar("name");
1743 $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1744 } else {
1745 // -> move to application class!
1746
1747 // cell classes
1748 $cells = array("H" => "header", "C1" => "cell1", "C2" => "cell2");
1749 $tb_p = $this->form_gui->getItemByPostVar("tb_padding");
1750 $tb_padding = $tb_p->getValue();
1751 $lr_p = $this->form_gui->getItemByPostVar("lr_padding");
1752 $lr_padding = $lr_p->getValue();
1753 $cell_color = $this->form_gui->getInput("base_color");
1754
1755 // use mid gray as cell color for bw zebra
1756 if ($this->form_gui->getInput("layout") == "bwZebra") {
1757 $cell_color = "MidGray";
1758 if (!$this->color_manager->colorExists($cell_color)) {
1759 $this->color_manager->addColor($cell_color, "7F7F7F");
1760 }
1761 $this->color_manager->updateColor($cell_color, $cell_color, "7F7F7F");
1762 }
1763
1764 foreach ($cells as $k => $cell) {
1765 $cell_class[$k] = $this->form_gui->getInput("name") . $k;
1766 if (!$this->object->characteristicExists($cell_class[$k], "table_cell")) {
1767 $this->characteristic_manager->addCharacteristic("table_cell", $cell_class[$k], true);
1768 }
1769 if ($this->form_gui->getInput("layout") == "bwZebra" && $k == "H") {
1770 $this->characteristic_manager->replaceParameter(
1771 "td",
1772 $cell_class[$k],
1773 "color",
1774 "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1775 "table_cell"
1776 );
1777 $this->characteristic_manager->replaceParameter(
1778 "td",
1779 $cell_class[$k],
1780 "background-color",
1781 "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1782 "table_cell"
1783 );
1784 } else {
1785 $this->characteristic_manager->replaceParameter(
1786 "td",
1787 $cell_class[$k],
1788 "color",
1789 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1790 "table_cell"
1791 );
1792 $this->characteristic_manager->replaceParameter(
1793 "td",
1794 $cell_class[$k],
1795 "background-color",
1796 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1797 "table_cell"
1798 );
1799 }
1800 $this->characteristic_manager->replaceParameter(
1801 "td",
1802 $cell_class[$k],
1803 "padding-top",
1804 $tb_padding,
1805 "table_cell"
1806 );
1807 $this->characteristic_manager->replaceParameter(
1808 "td",
1809 $cell_class[$k],
1810 "padding-bottom",
1811 $tb_padding,
1812 "table_cell"
1813 );
1814 $this->characteristic_manager->replaceParameter(
1815 "td",
1816 $cell_class[$k],
1817 "padding-left",
1818 $lr_padding,
1819 "table_cell"
1820 );
1821 $this->characteristic_manager->replaceParameter(
1822 "td",
1823 $cell_class[$k],
1824 "padding-right",
1825 $lr_padding,
1826 "table_cell"
1827 );
1828 $this->characteristic_manager->replaceParameter(
1829 "td",
1830 $cell_class[$k],
1831 "border-width",
1832 "1px",
1833 "table_cell"
1834 );
1835 $this->characteristic_manager->replaceParameter(
1836 "td",
1837 $cell_class[$k],
1838 "border-style",
1839 "solid",
1840 "table_cell"
1841 );
1842 $this->characteristic_manager->replaceParameter(
1843 "td",
1844 $cell_class[$k],
1845 "border-color",
1846 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_border") . ")",
1847 "table_cell"
1848 );
1849 $this->characteristic_manager->replaceParameter(
1850 "td",
1851 $cell_class[$k],
1852 "font-weight",
1853 "normal",
1854 "table_cell"
1855 );
1856 }
1857
1858 // table class
1859 $classes["table"] = $this->form_gui->getInput("name") . "T";
1860 if (!$this->object->characteristicExists($classes["table"], "table")) {
1861 $this->characteristic_manager->addCharacteristic("table", $classes["table"], true);
1862 }
1863 $this->characteristic_manager->replaceParameter(
1864 "table",
1865 $classes["table"],
1866 "caption-side",
1867 "bottom",
1868 "table"
1869 );
1870 $this->characteristic_manager->replaceParameter(
1871 "table",
1872 $classes["table"],
1873 "border-collapse",
1874 "collapse",
1875 "table"
1876 );
1877 $this->characteristic_manager->replaceParameter(
1878 "table",
1879 $classes["table"],
1880 "margin-top",
1881 "5px",
1882 "table"
1883 );
1884 $this->characteristic_manager->replaceParameter(
1885 "table",
1886 $classes["table"],
1887 "margin-bottom",
1888 "5px",
1889 "table"
1890 );
1891 if ($this->form_gui->getInput("layout") == "bwZebra") {
1892 $this->characteristic_manager->replaceParameter(
1893 "table",
1894 $classes["table"],
1895 "border-bottom-color",
1896 "!" . $this->form_gui->getInput("base_color"),
1897 "table"
1898 );
1899 $this->characteristic_manager->replaceParameter(
1900 "table",
1901 $classes["table"],
1902 "border-bottom-style",
1903 "solid",
1904 "table"
1905 );
1906 $this->characteristic_manager->replaceParameter(
1907 "table",
1908 $classes["table"],
1909 "border-bottom-width",
1910 "3px",
1911 "table"
1912 );
1913 $sb = array("left", "right", "top");
1914 foreach ($sb as $b) {
1915 $this->characteristic_manager->replaceParameter(
1916 "table",
1917 $classes["table"],
1918 "border-" . $b . "-width",
1919 "0px",
1920 "table"
1921 );
1922 }
1923 }
1924
1925 switch ($this->form_gui->getInput("layout")) {
1926 case "bwZebra":
1927 case "coloredZebra":
1928 $classes["row_head"] = $cell_class["H"];
1929 $classes["odd_row"] = $cell_class["C1"];
1930 $classes["even_row"] = $cell_class["C2"];
1931 break;
1932
1933 case "noZebra":
1934 $classes["row_head"] = $cell_class["H"];
1935 $classes["odd_row"] = $cell_class["C1"];
1936 $classes["even_row"] = $cell_class["C1"];
1937 $classes["col_head"] = $cell_class["C2"];
1938 break;
1939 }
1940
1941
1942 $t_id = $this->object->addTemplate(
1943 $this->style_request->getTempType(),
1944 $this->form_gui->getInput("name"),
1945 $classes
1946 );
1947 $this->object->writeTemplatePreview(
1948 $t_id,
1949 $this->getTemplatePreview(
1950 $this->style_request->getTempType(),
1951 $t_id,
1952 true
1953 )
1954 );
1955 $ilCtrl->redirect($this, "listTemplates");
1956 }
1957 }
1958 $this->form_gui->setValuesByPost();
1959 $tpl->setContent($this->form_gui->getHTML());
1960 }
1961
1962 public function returnToUpperContextObject(): void
1963 {
1964 $ilCtrl = $this->ctrl;
1965 $ilCtrl->returnToParent($this);
1966 }
1967}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Manages access to content style editing.
Main business logic for characteristics.
Main business logic for content style images.
Content style internal ui factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static addCss()
Add required css.
This class represents a checkbox property 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...
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
forwardCommand(object $a_gui_object)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
Export User Interface Class.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
This class represents a file property in a property form.
setFormAction(string $a_formaction)
Help GUI class.
const ID_PART_SCREEN
Import class.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
This class represents a number property in a property form.
This class represents a numeric style property in a property form.
Class ilObjStyleSheetGUI.
Access StyleAccessManager $access_manager
getAdminTabs()
administration tabs show only permissions and trash folder
templateGenerationObject()
Table template generation.
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded)
Content InternalDomainService $domain
cancelObject()
cancel action and go back to previous page
cancelTemplateDeletionObject()
Cancel table template deletion.
Content ImageManager $image_manager
getPropertiesValues()
Get current values for properties from.
Content StandardGUIRequest $style_request
editObject()
Edit -> List characteristics.
deleteObject($a_error=false)
display deletion confirmation screen
refreshTemplateObject()
Refresh table template.
initMediaQueryForm(string $a_mode="create")
Init media query form.
deleteTemplateObject()
Delete template.
deleteColorConfirmationObject()
Delete color confirmation.
cancelColorDeletionObject()
Cancel color deletion.
getColorFormValues()
Set values for color editing.
static getStyleExampleHTML(string $a_type, string $a_class)
Get style example HTML.
getTemplateFormValues()
Set values for table template editing.
Content InternalService $service
initTemplateGenerationForm()
Init table template generation form.
deleteTemplateConfirmationObject()
Delete table template confirmation.
cancelColorSavingObject()
Cancel color saving.
Content InternalGUIService $gui_service
updateObject()
updates object entry in object_data
getRenderedCreationFormsHTML(array $forms)
initPropertiesForm(string $a_mode="edit")
FORM: Init properties form.
importStyleObject()
Import style sheet.
static _getTemplatePreview(ilObjStyleSheet $a_style, string $a_type, int $a_t_id, bool $a_small_mode=false)
Get table template preview.
enableWrite(bool $a_write)
Enable writing.
initTemplateForm(string $a_mode="create")
Init table template form.
updateTemplateObject(bool $a_refresh=false)
createObject()
create new object form
Content ColorManager $color_manager
handleImport(\ILIAS\FileUpload\FileUpload $upload, \ILIAS\FileUpload\DTO\UploadResult $result)
confirmedDeleteObject()
delete selected style objects
initColorForm(string $a_mode="create")
listColorsObject()
List colors of style.
saveTemplateObject()
Save table template.
getMediaQueryFormValues()
Set values for media query editing.
viewObject()
viewObject container presentation for "administration -> repository, trash, permissions"
__construct( $a_data, int $a_id, bool $a_call_by_reference)
getTemplatePreview(string $a_type, int $a_t_id, bool $a_small_mode=false)
ilObjectDefinition $obj_definition
Content CharacteristicManager $characteristic_manager
getTabs()
@abstract overwrite in derived GUI class of your object type
saveMediaQueryObject()
Save media query.
listTemplatesObject()
List templates.
cancelTemplateSavingObject()
Cancel color saving.
Class ilObjStyleSheet.
static _getClonableContentStyles()
Get all clonable styles (active standard styles and individual learning module styles with write perm...
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
getTemplateXML()
Get table template xml.
lookupTemplateName(int $a_t_id)
Lookup table template name for template ID.
static _addMissingStyleClassesToStyle(int $a_id)
Add missing style classes to all styles.
static _writeStandard(int $a_id, bool $a_std)
Write standard flag.
static _getTemplateClassTypes(string $a_template_type="")
Get template class types.
static _getStyleSuperTypeForType(string $a_type)
static _lookupTemplateName(int $a_t_id)
Lookup table template name for template ID.
parses the objects.xml it handles the xml-description of all ilias objects
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjectGUI Basic methods of all Output classes.
ilGlobalTemplateInterface $tpl
setCreationMode(bool $mode=true)
If true, a creation screen is displayed the current [ref_id] does belong to the parent class The mode...
prepareOutput(bool $show_sub_objects=true)
ilLanguage $lng
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static _renderTable(string $content, string $a_mode="table_edit", string $a_submode="", ?ilPCTable $a_table_obj=null, bool $unmask=true, ?ilPageObject $page_object=null)
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
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-...
This class represents a regular expression input property in a property form.
This class represents a selection list property in a property form.
TableGUI class for style editor (image list)
TableGUI class for style editor (image list)
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
$c
Definition: deliver.php:25
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
Class ilObjForumAdministration.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26