ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 ilObject::_lookupType($this->requested_ref_id, true) === "stys") {
500 $cont_style_settings = new ilContentStyleSettings();
501 $cont_style_settings->addStyle($newObj->getId());
502 $cont_style_settings->update();
503
504 ilObjStyleSheet::_writeStandard($newObj->getId(), true);
505 $this->tpl->setOnScreenMessage("success", $this->lng->txt("object_added"), true);
506 $this->ctrl->setParameterByClass(self::class, "obj_id", (string) $newObj->getId());
507 $this->ctrl->redirectByClass(self::class, "");
508 }
509 }
510
511 public function copyStyleObject(): int
512 {
513 $ctrl = $this->gui_service->ctrl();
514
515 $form = $this->getCloneForm();
516 $form->checkInput();
517 $new_id = 0;
518
519 if ($form->getInput("source_style") > 0) {
520 $style_obj = ilObjectFactory::getInstanceByObjId((int) $form->getInput("source_style"));
521 $new_id = $style_obj->ilClone();
522 }
523
524 // assign style to style sheet folder,
525 // if parent is style sheet folder
526 if ($this->requested_ref_id > 0) {
527 $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
528 if ($fold->getType() == "stys") {
529 $cont_style_settings = new ilContentStyleSettings();
530 $cont_style_settings->addStyle($new_id);
531 $cont_style_settings->update();
532 ilObjStyleSheet::_writeStandard($new_id, true);
533 $ctrl->returnToParent($this);
534 }
535 }
536 $this->object = new ilObjStyleSheet($new_id);
537
538 return $new_id;
539 }
540
544 public function importStyleObject(): int
545 {
546 $newObj = null;
547 // check file
548 $source = $_FILES["importfile"]["tmp_name"];
549 if (($source == 'none') || (!$source)) {
550 $this->ilias->raiseError("No file selected!", $this->ilias->error_obj->MESSAGE);
551 }
552
553 // check correct file type
554 $info = pathinfo($_FILES["importfile"]["name"]);
555 if (strtolower($info["extension"]) != "zip" && strtolower($info["extension"]) != "xml") {
556 $this->ilias->raiseError("File must be a zip or xml file!", $this->ilias->error_obj->MESSAGE);
557 }
558
559 // new import
560 $fname = explode("_", $_FILES["importfile"]["name"]);
561 if (strtolower($info["extension"]) == "zip" && $fname[4] == "sty") {
562 $imp = new ilImport();
563 $new_id = $imp->importObject(
564 null,
565 $_FILES["importfile"]["tmp_name"],
566 $_FILES["importfile"]["name"],
567 "sty"
568 );
569 if ($new_id > 0) {
570 $newObj = ilObjectFactory::getInstanceByObjId($new_id);
571 }
572 } else { // old import
573 $newObj = new ilObjStyleSheet();
574 $newObj->import($_FILES["importfile"]);
575 }
576
577 // assign style to style sheet folder,
578 // if parent is style sheet folder
579 if ($this->requested_ref_id > 0) {
580 $fold = ilObjectFactory::getInstanceByRefId($this->requested_ref_id);
581 if ($fold->getType() == "stys") {
582 $cont_style_settings = new ilContentStyleSettings();
583 $cont_style_settings->addStyle($newObj->getId());
584 $cont_style_settings->update();
585 ilObjStyleSheet::_writeStandard($newObj->getId(), true);
586 $this->ctrl->returnToParent($this);
587 }
588 }
589 $this->object = $newObj;
590 return $newObj->getId();
591 }
592
593 public function handleImport(
594 \ILIAS\FileUpload\FileUpload $upload,
595 \ILIAS\FileUpload\DTO\UploadResult $result
596 ): \ILIAS\FileUpload\Handler\BasicHandlerResult {
597 $new_id = $this->domain->style(0)->importFromUploadResult(
598 $result
599 );
600 return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
601 'obj_id',
602 \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
603 (string) $new_id,
604 ''
605 );
606 }
607
608
609 public function cancelObject(): void
610 {
612
613 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_cancel"), true);
614 $this->ctrl->returnToParent($this);
615 }
616
617 public function getAdminTabs(): void
618 {
619 $this->getTabs();
620 }
621
622 protected function getTabs(): void
623 {
625 $ilHelp = $this->help;
626 $tabs = $this->gui_service->tabs();
627 $ilHelp->setScreenIdComponent("sty");
628 // back to upper context
629 $tabs->setBackTarget(
630 $lng->txt("back"),
631 $this->ctrl->getLinkTarget($this, "returnToUpperContext")
632 );
633
634 // style classes
635 $tabs->addTarget(
636 "sty_style_chars",
637 $this->ctrl->getLinkTarget($this, "edit"),
638 array("edit", ""),
639 get_class($this)
640 );
641
642 // colors
643 $tabs->addTarget(
644 "sty_colors",
645 $this->ctrl->getLinkTarget($this, "listColors"),
646 "listColors",
647 get_class($this)
648 );
649
650 // images
651 $tabs->addTarget(
652 "sty_images",
653 $this->ctrl->getLinkTargetByClass("ilContentStyleImageGUI", ""),
654 "",
655 "ilContentStyleImageGUI"
656 );
657
658 // media queries
659 $tabs->addTarget(
660 "sty_media_queries",
661 $this->ctrl->getLinkTarget($this, "listMediaQueries"),
662 "listMediaQueries",
663 get_class($this)
664 );
665
666
667 // table templates
668 $tabs->addTarget(
669 "sty_templates",
670 $this->ctrl->getLinkTarget($this, "listTemplates"),
671 "listTemplates",
672 get_class($this)
673 );
674
675 // settings
676 $tabs->addTarget(
677 "settings",
678 $this->ctrl->getLinkTarget($this, "properties"),
679 "properties",
680 get_class($this)
681 );
682
683 // export
684 $tabs->addTarget(
685 "export",
686 $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
687 "",
688 "ilexportgui"
689 );
690 }
691
692 public function setTemplatesSubTabs(): void
693 {
694 $ilTabs = $this->gui_service->tabs();
695 $ilCtrl = $this->ctrl;
696
698
699 foreach ($types as $t => $c) {
700 $ilCtrl->setParameter($this, "temp_type", $t);
701 $ilTabs->addSubTabTarget(
702 "sty_" . $t . "_templates",
703 $this->ctrl->getLinkTarget($this, "listTemplates"),
704 array("listTemplates", ""),
705 get_class($this)
706 );
707 }
708
709 $ilCtrl->setParameter($this, "temp_type", $this->style_request->getTempType());
710 }
711
716 protected function addAdminLocatorItems(bool $do_not_add_object = false): void
717 {
718 $ilLocator = $this->gui_service->locator();
719
720 if ($this->style_request->getAdminMode() == "settings") { // system settings
721 parent::addAdminLocatorItems(true);
722
723 $ilLocator->addItem(
724 $this->lng->txt("obj_stys"),
725 $this->ctrl->getLinkTargetByClass("ilobjstylesettingsgui", "")
726 );
727
728 $ilLocator->addItem(
729 $this->lng->txt("content_styles"),
730 $this->ctrl->getLinkTargetByClass("ilcontentstylesettingsgui", "")
731 );
732
733 if ($this->style_request->getObjId() > 0) {
734 $ilLocator->addItem(
735 $this->object->getTitle(),
736 $this->ctrl->getLinkTarget($this, "edit")
737 );
738 }
739 }
740 }
741
745 public static function getStyleExampleHTML(
746 string $a_type,
747 string $a_class
748 ): string {
749 global $DIC;
750
751 $lng = $DIC->language();
752
753 $c = explode(":", $a_class);
754 $a_class = $c[0];
755
756 $ex_tpl = new ilTemplate("tpl.style_example.html", true, true, "components/ILIAS/Style/Content");
757
758 if ($ex_tpl->blockExists("Example_" . $a_type)) {
759 $ex_tpl->setCurrentBlock("Example_" . $a_type);
760 } else {
761 $ex_tpl->setCurrentBlock("Example_default");
762 }
763 $ex_tpl->setVariable("EX_CLASS", "ilc_" . $a_type . "_" . $a_class);
764 $ex_tpl->setVariable("EX_TEXT", "ABC abc 123");
765 if (in_array($a_type, array("media_cont", "qimg"))) {
766 //
767 }
768 if (in_array($a_type, array("table", "table_caption"))) {
769 $ex_tpl->setVariable("TXT_CAPTION", $lng->txt("sty_caption"));
770 }
771 if (in_array($a_class, array("OrderListItemHorizontal", "OrderListHorizontal"))) {
772 $ex_tpl->setVariable("HOR", "Horizontal");
773 }
774 $ex_tpl->parseCurrentBlock();
775
776 return $ex_tpl->get();
777 }
778
779
780 //
781 // Color management
782 //
783
787 public function listColorsObject(): void
788 {
789 $tpl = $this->gui_service->ui()->mainTemplate();
790 $ilToolbar = $this->gui_service->toolbar();
791 $ilCtrl = $this->ctrl;
792
793 if ($this->access_manager->checkWrite()) {
794 $ilToolbar->addButton(
795 $this->lng->txt("sty_add_color"),
796 $ilCtrl->getLinkTarget($this, "addColor")
797 );
798 }
799
800 $table_gui = new ilStyleColorTableGUI(
801 $this,
802 "listColors",
803 $this->getStyleSheet(),
804 $this->access_manager
805 );
806 $tpl->setContent($table_gui->getHTML());
807 }
808
809 public function addColorObject(): void
810 {
811 $tpl = $this->gui_service->ui()->mainTemplate();
812
813 $this->initColorForm();
814 $tpl->setContent($this->form_gui->getHTML());
815 }
816
817 public function editColorObject(): void
818 {
819 $tpl = $this->gui_service->ui()->mainTemplate();
820 $ilCtrl = $this->ctrl;
821
822 $ilCtrl->setParameter($this, "c_name", $this->style_request->getColorName());
823 $this->initColorForm("edit");
824 $this->getColorFormValues();
825 $tpl->setContent($this->form_gui->getHTML());
826 }
827
828
829 public function initColorForm(
830 string $a_mode = "create"
831 ): void {
832 $lng = $this->lng;
833 $ilCtrl = $this->ctrl;
834
835 $this->form_gui = new ilPropertyFormGUI();
836
837 $this->form_gui->setTitle($lng->txt("sty_add_color"));
838
839 // name
840 $name_input = new ilRegExpInputGUI($lng->txt("sty_color_name"), "color_name");
841 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
842 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
843 $name_input->setRequired(true);
844 $name_input->setSize(15);
845 $name_input->setMaxLength(15);
846 $this->form_gui->addItem($name_input);
847
848 // code
849 $color_input = new ilColorPickerInputGUI($lng->txt("sty_color_code"), "color_code");
850 $color_input->setRequired(true);
851 $color_input->setDefaultColor("");
852 $this->form_gui->addItem($color_input);
853
854 if ($a_mode == "create") {
855 $this->form_gui->addCommandButton("saveColor", $lng->txt("save"));
856 } else {
857 $this->form_gui->addCommandButton("updateColor", $lng->txt("save"));
858 }
859 $this->form_gui->addCommandButton("cancelColorSaving", $lng->txt("cancel"));
860 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
861 }
862
866 public function getColorFormValues(): void
867 {
868 $c_name = $this->style_request->getColorName();
869 if ($c_name != "") {
870 $values["color_name"] = $c_name;
871 $values["color_code"] = $this->object->getColorCodeForName($c_name);
872 $this->form_gui->setValuesByArray($values);
873 }
874 }
875
879 public function cancelColorSavingObject(): void
880 {
881 $ilCtrl = $this->ctrl;
882
883 $ilCtrl->redirect($this, "listColors");
884 }
885
889 public function saveColorObject(): void
890 {
891 $tpl = $this->gui_service->ui()->mainTemplate();
892 $ilCtrl = $this->ctrl;
894
895 $this->initColorForm();
896 if ($this->form_gui->checkInput()) {
897 if ($this->color_manager->colorExists($this->form_gui->getInput("color_name"))) {
898 $col_input = $this->form_gui->getItemByPostVar("color_name");
899 $col_input->setAlert($lng->txt("sty_color_already_exists"));
900 } else {
901 $this->color_manager->addColor(
902 $this->form_gui->getInput("color_name"),
903 $this->form_gui->getInput("color_code")
904 );
905 $ilCtrl->redirect($this, "listColors");
906 }
907 }
908 $this->form_gui->setValuesByPost();
909 $tpl->setContent($this->form_gui->getHTML());
910 }
911
915 public function updateColorObject(): void
916 {
917 $tpl = $this->gui_service->ui()->mainTemplate();
918 $ilCtrl = $this->ctrl;
920
921 $c_name = $this->style_request->getColorName();
922 $ilCtrl->setParameter($this, "c_name", $c_name);
923 $this->initColorForm("edit");
924
925 if ($this->form_gui->checkInput()) {
926 if ($this->color_manager->colorExists($this->form_gui->getInput("color_name")) &&
927 $this->form_gui->getInput("color_name") != $c_name) {
928 $col_input = $this->form_gui->getItemByPostVar("color_name");
929 $col_input->setAlert($lng->txt("sty_color_already_exists"));
930 } else {
931 $this->color_manager->updateColor(
932 $c_name,
933 $this->form_gui->getInput("color_name"),
934 $this->form_gui->getInput("color_code")
935 );
936 $ilCtrl->redirect($this, "listColors");
937 }
938 }
939 $this->form_gui->setValuesByPost();
940 $tpl->setContent($this->form_gui->getHTML());
941 }
942
946 public function deleteColorConfirmationObject(): void
947 {
948 $ilCtrl = $this->ctrl;
949 $tpl = $this->gui_service->ui()->mainTemplate();
951
952 $colors = $this->style_request->getColors();
953 if (count($colors) == 0) {
954 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
955 $ilCtrl->redirect($this, "listColors");
956 } else {
957 $cgui = new ilConfirmationGUI();
958 $cgui->setFormAction($ilCtrl->getFormAction($this));
959 $cgui->setHeaderText($lng->txt("sty_confirm_color_deletion"));
960 $cgui->setCancel($lng->txt("cancel"), "cancelColorDeletion");
961 $cgui->setConfirm($lng->txt("delete"), "deleteColor");
962
963 foreach ($colors as $c) {
964 $cgui->addItem("color[]", ilLegacyFormElementsUtil::prepareFormOutput($c), $c);
965 }
966
967 $tpl->setContent($cgui->getHTML());
968 }
969 }
970
974 public function cancelColorDeletionObject(): void
975 {
976 $ilCtrl = $this->ctrl;
977 $ilCtrl->redirect($this, "listColors");
978 }
979
980 public function deleteColorObject(): void
981 {
982 $ilCtrl = $this->ctrl;
983
984 $colors = $this->style_request->getColors();
985 foreach ($colors as $c) {
986 $this->object->removeColor($c);
987 }
988
989 $ilCtrl->redirect($this, "listColors");
990 }
991
992 //
993 // Media query management
994 //
995
996 public function listMediaQueriesObject(): void
997 {
998 $tpl = $this->gui_service->ui()->mainTemplate();
999 $ilToolbar = $this->gui_service->toolbar();
1000 $ilCtrl = $this->ctrl;
1001
1002 if ($this->access_manager->checkWrite()) {
1003 $ilToolbar->addButton(
1004 $this->lng->txt("sty_add_media_query"),
1005 $ilCtrl->getLinkTarget($this, "addMediaQuery")
1006 );
1007 }
1008
1009 $table_gui = new ilStyleMediaQueryTableGUI(
1010 $this,
1011 "listMediaQueries",
1012 $this->getStyleSheet(),
1013 $this->access_manager
1014 );
1015 $tpl->setContent($table_gui->getHTML());
1016 }
1017
1018 public function addMediaQueryObject(): void
1019 {
1020 $tpl = $this->gui_service->ui()->mainTemplate();
1021
1022 $this->initMediaQueryForm();
1023 $tpl->setContent($this->form_gui->getHTML());
1024 }
1025
1026 public function editMediaQueryObject(): void
1027 {
1028 $tpl = $this->gui_service->ui()->mainTemplate();
1029 $ilCtrl = $this->ctrl;
1030
1031 $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
1032 $this->initMediaQueryForm("edit");
1033 $this->getMediaQueryFormValues();
1034 $tpl->setContent($this->form_gui->getHTML());
1035 }
1036
1037
1041 public function initMediaQueryForm(
1042 string $a_mode = "create"
1043 ): void {
1044 $lng = $this->lng;
1045 $ilCtrl = $this->ctrl;
1046
1047 $this->form_gui = new ilPropertyFormGUI();
1048
1049 $this->form_gui->setTitle($lng->txt("sty_add_media_query"));
1050
1051 // media query
1052 $ti = new ilTextInputGUI("@media", "mquery");
1053 $ti->setMaxLength(2000);
1054 $ti->setInfo($lng->txt("sty_add_media_query_info"));
1055 $this->form_gui->addItem($ti);
1056
1057
1058 if ($a_mode == "create") {
1059 $this->form_gui->addCommandButton("saveMediaQuery", $lng->txt("save"));
1060 } else {
1061 $this->form_gui->addCommandButton("updateMediaQuery", $lng->txt("save"));
1062 }
1063 $this->form_gui->addCommandButton("listMediaQueries", $lng->txt("cancel"));
1064 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1065 }
1066
1070 public function getMediaQueryFormValues(): void
1071 {
1072 $values = [];
1073 if ($this->style_request->getMediaQueryId() > 0) {
1074 foreach ($this->object->getMediaQueries() as $mq) {
1075 if ($mq["id"] == $this->style_request->getMediaQueryId()) {
1076 $values["mquery"] = $mq["mquery"];
1077 }
1078 }
1079 $this->form_gui->setValuesByArray($values);
1080 }
1081 }
1082
1086 public function saveMediaQueryObject(): void
1087 {
1088 $tpl = $this->gui_service->ui()->mainTemplate();
1089 $ilCtrl = $this->ctrl;
1090 $lng = $this->lng;
1091
1092 $this->initMediaQueryForm();
1093
1094 if ($this->form_gui->checkInput()) {
1095 $this->object->addMediaQuery($this->form_gui->getInput("mquery"));
1096 $ilCtrl->redirect($this, "listMediaQueries");
1097 }
1098 $this->form_gui->setValuesByPost();
1099 $tpl->setContent($this->form_gui->getHTML());
1100 }
1101
1102 public function updateMediaQueryObject(): void
1103 {
1104 $tpl = $this->gui_service->ui()->mainTemplate();
1105 $ilCtrl = $this->ctrl;
1106
1107 $this->initMediaQueryForm("edit");
1108
1109 if ($this->form_gui->checkInput()) {
1110 $this->object->updateMediaQuery(
1111 $this->style_request->getMediaQueryId(),
1112 $this->form_gui->getInput("mquery")
1113 );
1114 $ilCtrl->redirect($this, "listMediaQueries");
1115 }
1116 $ilCtrl->setParameter($this, "mq_id", $this->style_request->getMediaQueryId());
1117 $this->form_gui->setValuesByPost();
1118 $tpl->setContent($this->form_gui->getHTML());
1119 }
1120
1122 {
1123 $ilCtrl = $this->ctrl;
1124 $tpl = $this->gui_service->ui()->mainTemplate();
1125 $lng = $this->lng;
1126
1127 $mq_ids = $this->style_request->getMediaQueryIds();
1128 if (count($mq_ids) == 0) {
1129 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1130 $ilCtrl->redirect($this, "listMediaQueries");
1131 } else {
1132 $cgui = new ilConfirmationGUI();
1133 $cgui->setFormAction($ilCtrl->getFormAction($this));
1134 $cgui->setHeaderText($lng->txt("sty_sure_del_mqueries"));
1135 $cgui->setCancel($lng->txt("cancel"), "listMediaQueries");
1136 $cgui->setConfirm($lng->txt("delete"), "deleteMediaQueries");
1137
1138 foreach ($mq_ids as $i) {
1139 $mq = $this->object->getMediaQueryForId($i);
1140 $cgui->addItem("mq_id[]", (string) $i, $mq["mquery"]);
1141 }
1142
1143 $tpl->setContent($cgui->getHTML());
1144 }
1145 }
1146
1147 public function deleteMediaQueriesObject(): void
1148 {
1149 $ilCtrl = $this->ctrl;
1150
1151 $mq_ids = $this->style_request->getMediaQueryIds();
1152 if ($this->access_manager->checkWrite()) {
1153 foreach ($mq_ids as $id) {
1154 $this->object->deleteMediaQuery($id);
1155 }
1156 }
1157 $ilCtrl->redirect($this, "listMediaQueries");
1158 }
1159
1160 public function saveMediaQueryOrderObject(): void
1161 {
1162 $ilCtrl = $this->ctrl;
1163
1164 $order = $this->style_request->getOrder();
1165 if (count($order) > 0) {
1166 $this->getStyleSheet()->saveMediaQueryOrder($order);
1167 }
1168 $ilCtrl->redirect($this, "listMediaQueries");
1169 }
1170
1171
1172 //
1173 // Templates management
1174 //
1175
1179 public function listTemplatesObject(): void
1180 {
1181 $tpl = $this->gui_service->ui()->mainTemplate();
1182 $ilTabs = $this->gui_service->tabs();
1183 $ilCtrl = $this->ctrl;
1184 $ilToolbar = $this->gui_service->toolbar();
1185
1186 $ctype = $this->style_request->getTempType();
1187 if ($ctype == "") {
1188 $ctype = "table";
1189 }
1190
1191 $this->setTemplatesSubTabs();
1192 $ilCtrl->setParameter($this, "temp_type", $ctype);
1193 $ilTabs->setSubTabActive("sty_" . $ctype . "_templates");
1194
1195 // action commands
1196 if ($this->access_manager->checkWrite()) {
1197 if ($ctype == "table") {
1198 $ilToolbar->addButton(
1199 $this->lng->txt("sty_generate_template"),
1200 $ilCtrl->getLinkTarget($this, "generateTemplate")
1201 );
1202 }
1203 $ilToolbar->addButton(
1204 $this->lng->txt("sty_add_template"),
1205 $ilCtrl->getLinkTarget($this, "addTemplate")
1206 );
1207 }
1208
1209
1210
1211 $this->includeCSS();
1212 $table_gui = new ilTableTemplatesTableGUI(
1213 $ctype,
1214 $this,
1215 "listTemplates",
1216 $this->getStyleSheet(),
1217 $this->access_manager
1218 );
1219 $tpl->setContent($table_gui->getHTML());
1220 }
1221
1222 public function addTemplateObject(): void
1223 {
1224 $tpl = $this->gui_service->ui()->mainTemplate();
1225
1226 $this->initTemplateForm();
1227 $tpl->setContent($this->form_gui->getHTML());
1228 }
1229
1230 public function editTemplateObject(): void
1231 {
1232 $ilCtrl = $this->ctrl;
1233
1234 $ilCtrl->setParameter(
1235 $this,
1236 "t_id",
1237 $this->style_request->getTemplateId()
1238 );
1239 $this->initTemplateForm("edit");
1240 $this->getTemplateFormValues();
1241
1242 $this->displayTemplateEditForm();
1243 }
1244
1245 public function getTemplatePreview(
1246 string $a_type,
1247 int $a_t_id,
1248 bool $a_small_mode = false
1249 ): string {
1250 return $this->_getTemplatePreview(
1251 $this->getStyleSheet(),
1252 $a_type,
1253 $a_t_id,
1254 $a_small_mode
1255 );
1256 }
1257
1261 public static function _getTemplatePreview(
1262 ilObjStyleSheet $a_style,
1263 string $a_type,
1264 int $a_t_id,
1265 bool $a_small_mode = false
1266 ): string {
1267 global $DIC;
1268
1269 $lng = $DIC->language();
1270 $p_content = "";
1271
1272 $kr = $kc = 7;
1273 if ($a_small_mode) {
1274 $kr = 6;
1275 $kc = 5;
1276 }
1277
1278 $ts = $a_style->getTemplate($a_t_id);
1279 $t = $ts["classes"];
1280
1281 // preview
1282 if ($a_type == "table") {
1283 $p_content = '<PageContent><Table DataTable="y"';
1284 $t["row_head"] = $t["row_head"] ?? "";
1285 $t["row_foot"] = $t["row_foot"] ?? "";
1286 $t["col_head"] = $t["col_head"] ?? "";
1287 $t["col_foot"] = $t["col_foot"] ?? "";
1288 if ($t["row_head"] != "") {
1289 $p_content .= ' HeaderRows="1"';
1290 }
1291 if ($t["row_foot"] != "") {
1292 $p_content .= ' FooterRows="1"';
1293 }
1294 if ($t["col_head"] != "") {
1295 $p_content .= ' HeaderCols="1"';
1296 }
1297 if ($t["col_foot"] != "") {
1298 $p_content .= ' FooterCols="1"';
1299 }
1300 $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1301 if (!$a_small_mode) {
1302 $p_content .= '<Caption>' . $lng->txt("sty_caption") . '</Caption>';
1303 }
1304 for ($i = 1; $i <= $kr; $i++) {
1305 $p_content .= '<TableRow>';
1306 for ($j = 1; $j <= $kc; $j++) {
1307 if ($a_small_mode) {
1308 $cell = '&lt;div style="height:2px;"&gt;&lt;/div&gt;';
1309 } else {
1310 $cell = 'xxx';
1311 }
1312 $p_content .= '<TableData><PageContent><Paragraph Characteristic="TableContent">' . $cell . '</Paragraph></PageContent></TableData>';
1313 }
1314 $p_content .= '</TableRow>';
1315 }
1316 $p_content .= '</Table></PageContent>';
1317 }
1318
1319 if ($a_type == "vaccordion" || $a_type == "haccordion" || $a_type == "carousel") {
1321
1322 if ($a_small_mode) {
1323 $c = '&amp;nbsp;';
1324 $h = '&amp;nbsp;';
1325 } else {
1326 $c = 'xxx';
1327 $h = 'head';
1328 }
1329 if ($a_type == "vaccordion") {
1330 $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="VerticalAccordion" ';
1331 if ($a_small_mode) {
1332 $p_content .= ' ContentWidth="70"';
1333 }
1334 } elseif ($a_type == "haccordion") {
1335 $p_content = '<PageContent><Tabs Type="HorizontalAccordion"';
1336 $p_content .= ' ContentHeight="40"';
1337 if ($a_small_mode) {
1338 $p_content .= ' ContentWidth="70"';
1339 $c = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
1340 }
1341 } elseif ($a_type == "carousel") {
1342 $p_content = '<PageContent><Tabs HorizontalAlign="Left" Type="Carousel" ';
1343 if ($a_small_mode) {
1344 $p_content .= ' ContentWidth="70"';
1345 }
1346 }
1347
1348
1349 $p_content .= ' Template="' . $a_style->lookupTemplateName($a_t_id) . '">';
1350 $p_content .= '<Tab><PageContent><Paragraph>' . $c . '</Paragraph></PageContent>';
1351 $p_content .= '<TabCaption>' . $h . '</TabCaption>';
1352 $p_content .= '</Tab>';
1353 $p_content .= '</Tabs></PageContent>';
1354 }
1355 //echo htmlentities($p_content);
1356 $txml = $a_style->getTemplateXML();
1357 //echo htmlentities($txml); exit;
1358 $p_content .= $txml;
1359 $r_content = ilPCTableGUI::_renderTable($p_content, "");
1360
1361 // fix carousel template visibility
1362 if ($a_type == "carousel") {
1363 $r_content .= "<style>.owl-carousel{ display:block !important; }</style>";
1364 }
1365
1366 //echo htmlentities($r_content); exit;
1367 return $r_content;
1368 }
1369
1373 public function initTemplateForm(string $a_mode = "create"): void
1374 {
1375 $lng = $this->lng;
1376 $ilCtrl = $this->ctrl;
1377
1378 $this->form_gui = new ilPropertyFormGUI();
1379
1380 if ($a_mode == "create") {
1381 $this->form_gui->setTitle($lng->txt("sty_add_template"));
1382 } else {
1383 $this->form_gui->setTitle($lng->txt("sty_edit_template"));
1384 }
1385
1386 // name
1387 $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1388 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1389 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1390 $name_input->setRequired(true);
1391 $name_input->setSize(30);
1392 $name_input->setMaxLength(30);
1393 $this->form_gui->addItem($name_input);
1394
1395 // template style classes
1397 $this->style_request->getTempType()
1398 );
1399
1400 foreach ($scs as $sc => $st) {
1401 $sc_input = new ilSelectInputGUI($lng->txt("sty_" . $sc . "_class"), $sc . "_class");
1402 $chars = $this->object->getCharacteristics($st);
1403 $options = array("" => "");
1404 foreach ($chars as $char) {
1405 $options[$char] = $char;
1406 }
1407 $sc_input->setOptions($options);
1408 $this->form_gui->addItem($sc_input);
1409 }
1410
1411 if ($a_mode == "create") {
1412 $this->form_gui->addCommandButton("saveTemplate", $lng->txt("save"));
1413 } else {
1414 $this->form_gui->addCommandButton("refreshTemplate", $lng->txt("save_refresh"));
1415 $this->form_gui->addCommandButton("updateTemplate", $lng->txt("save_return"));
1416 }
1417 $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1418 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1419 }
1420
1424 public function cancelTemplateSavingObject(): void
1425 {
1426 $ilCtrl = $this->ctrl;
1427 $ilCtrl->redirect($this, "listTemplates");
1428 }
1429
1430
1434 public function saveTemplateObject(): void
1435 {
1436 $tpl = $this->gui_service->ui()->mainTemplate();
1437 $ilCtrl = $this->ctrl;
1438 $lng = $this->lng;
1439
1440 $this->initTemplateForm();
1441 $temp_type = $this->style_request->getTempType();
1442
1443 if ($this->form_gui->checkInput()) {
1444 if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1445 $name_input = $this->form_gui->getItemByPostVar("name");
1446 $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1447 } else {
1448 $classes = array();
1449 foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1450 $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1451 }
1452 $t_id = $this->object->addTemplate(
1453 $temp_type,
1454 $this->form_gui->getInput("name"),
1455 $classes
1456 );
1457 $this->object->writeTemplatePreview(
1458 $t_id,
1459 $this->getTemplatePreview($temp_type, $t_id, true)
1460 );
1461 $ilCtrl->redirect($this, "listTemplates");
1462 }
1463 }
1464 $this->form_gui->setValuesByPost();
1465 $tpl->setContent($this->form_gui->getHTML());
1466 }
1467
1468 public function updateTemplateObject(
1469 bool $a_refresh = false
1470 ): void {
1471 $ilCtrl = $this->ctrl;
1472 $lng = $this->lng;
1473
1474 $ilCtrl->setParameter($this, "t_id", $this->style_request->getTemplateId());
1475 $this->initTemplateForm("edit");
1476 $temp_type = $this->style_request->getTempType();
1477
1478 $t_id = $this->style_request->getTemplateId();
1479 if ($this->form_gui->checkInput()) {
1480 if ($this->object->templateExists($this->form_gui->getInput("name")) &&
1481 $this->form_gui->getInput("name") != ilObjStyleSheet::_lookupTemplateName($t_id)) {
1482 $name_input = $this->form_gui->getItemByPostVar("name");
1483 $name_input->setAlert($lng->txt("sty_template_already_exists"));
1484 } else {
1485 $classes = array();
1486 foreach (ilObjStyleSheet::_getTemplateClassTypes($temp_type) as $tct => $ct) {
1487 $classes[$tct] = $this->form_gui->getInput($tct . "_class");
1488 }
1489
1490 $this->object->updateTemplate(
1491 $t_id,
1492 $this->form_gui->getInput("name"),
1493 $classes
1494 );
1495 $this->object->writeTemplatePreview(
1496 $t_id,
1497 $this->getTemplatePreview($temp_type, $t_id, true)
1498 );
1499 if (!$a_refresh) {
1500 $ilCtrl->redirect($this, "listTemplates");
1501 }
1502 }
1503 }
1504
1505 $this->form_gui->setValuesByPost();
1506 $this->displayTemplateEditForm();
1507 }
1508
1509 public function displayTemplateEditForm(): void
1510 {
1511 $tpl = $this->gui_service->ui()->mainTemplate();
1512
1513 $a_tpl = new ilTemplate(
1514 "tpl.template_edit.html",
1515 true,
1516 true,
1517 "components/ILIAS/Style/Content"
1518 );
1519 $this->includeCSS();
1520 $a_tpl->setVariable("FORM", $this->form_gui->getHTML());
1521 $a_tpl->setVariable("PREVIEW", $this->getTemplatePreview(
1522 $this->style_request->getTempType(),
1523 $this->style_request->getTemplateId()
1524 ));
1525 $tpl->setContent($a_tpl->get());
1526 }
1527
1531 public function refreshTemplateObject(): void
1532 {
1533 $this->updateTemplateObject(true);
1534 }
1535
1539 public function getTemplateFormValues(): void
1540 {
1541 $t_id = $this->style_request->getTemplateId();
1542 if ($t_id > 0) {
1543 $t = $this->object->getTemplate($t_id);
1544
1545 $values["name"] = $t["name"];
1547 $this->style_request->getTempType()
1548 );
1549 foreach ($scs as $k => $type) {
1550 $values[$k . "_class"] = $t["classes"][$k] ?? "";
1551 }
1552 $this->form_gui->setValuesByArray($values);
1553 }
1554 }
1555
1559 public function deleteTemplateConfirmationObject(): void
1560 {
1561 $ilCtrl = $this->ctrl;
1562 $tpl = $this->gui_service->ui()->mainTemplate();
1563 $lng = $this->lng;
1564
1565 $tids = $this->style_request->getTemplateIds();
1566 if (count($tids) == 0) {
1567 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1568 $ilCtrl->redirect($this, "listTemplates");
1569 } else {
1570 $cgui = new ilConfirmationGUI();
1571 $cgui->setFormAction($ilCtrl->getFormAction($this));
1572 $cgui->setHeaderText($lng->txt("sty_confirm_template_deletion"));
1573 $cgui->setCancel($lng->txt("cancel"), "cancelTemplateDeletion");
1574 $cgui->setConfirm($lng->txt("sty_del_template"), "deleteTemplate");
1575
1576 foreach ($tids as $tid) {
1577 $classes = $this->object->getTemplateClasses($tid);
1578 $cl_str = "";
1579 $listed = array();
1580 foreach ($classes as $cl) {
1581 if ($cl != "" && !($listed[$cl] ?? false)) {
1582 $cl_str .= '<div>- ' .
1583 $cl . "</div>";
1584 $listed[$cl] = true;
1585 }
1586 }
1587 if ($cl_str != "") {
1588 $cl_str = '<div style="padding-left:30px;" class="small">' .
1589 "<div><i>" . $lng->txt("sty_style_class") . "</i></div>" . $cl_str . "</div>";
1590 }
1591 $cgui->addItem("tid[]", (string) $tid, $this->object->lookupTemplateName($tid) . $cl_str);
1592 }
1593
1594 $cgui->addButton($lng->txt("sty_del_template_keep_classes"), "deleteTemplateKeepClasses");
1595
1596 $tpl->setContent($cgui->getHTML());
1597 }
1598 }
1599
1603 public function cancelTemplateDeletionObject(): void
1604 {
1605 $ilCtrl = $this->ctrl;
1606
1607 $ilCtrl->redirect($this, "listTemplates");
1608 }
1609
1610 public function deleteTemplateKeepClassesObject(): void
1611 {
1612 $ilCtrl = $this->ctrl;
1613
1614 $tids = $this->style_request->getTemplateIds();
1615 foreach ($tids as $tid) {
1616 $this->object->removeTemplate($tid);
1617 }
1618
1619 $ilCtrl->redirect($this, "listTemplates");
1620 }
1621
1628 public function deleteTemplateObject(): void
1629 {
1630 $ilCtrl = $this->ctrl;
1631
1632 $tids = $this->style_request->getTemplateIds();
1633 foreach ($tids as $tid) {
1634 $cls = $this->object->getTemplateClasses($tid);
1635 foreach ($cls as $k => $cls2) {
1636 $ty = $this->object->determineTemplateStyleClassType(
1637 $this->style_request->getTempType(),
1638 $k
1639 );
1640 $this->characteristic_manager->deleteCharacteristic($ty, $cls2);
1641 }
1642 $this->object->removeTemplate($tid);
1643 }
1644
1645 $ilCtrl->redirect($this, "listTemplates");
1646 }
1647
1648 public function generateTemplateObject(): void
1649 {
1650 $tpl = $this->gui_service->ui()->mainTemplate();
1651
1652 $this->initTemplateGenerationForm();
1653 $tpl->setContent($this->form_gui->getHTML());
1654 }
1655
1659 public function initTemplateGenerationForm(): void
1660 {
1661 $lng = $this->lng;
1662 $ilCtrl = $this->ctrl;
1663
1664 $this->form_gui = new ilPropertyFormGUI();
1665
1666 $this->form_gui->setTitle($lng->txt("sty_generate_template"));
1667
1668 // name
1669 $name_input = new ilRegExpInputGUI($lng->txt("sty_template_name"), "name");
1670 $name_input->setPattern("/^[a-zA-Z]+[a-zA-Z0-9]*$/");
1671 $name_input->setNoMatchMessage($lng->txt("sty_msg_color_must_only_include") . " A-Z, a-z, 1-9");
1672 $name_input->setRequired(true);
1673 $name_input->setSize(30);
1674 $name_input->setMaxLength(30);
1675 $this->form_gui->addItem($name_input);
1676
1677 // basic layout
1678 $bl_input = new ilSelectInputGUI($lng->txt("sty_template_layout"), "layout");
1679 $options = array(
1680 "coloredZebra" => $lng->txt("sty_table_template_colored_zebra"),
1681 "bwZebra" => $lng->txt("sty_table_template_bw_zebra"),
1682 "noZebra" => $lng->txt("sty_table_template_no_zebra")
1683 );
1684 $bl_input->setOptions($options);
1685 $this->form_gui->addItem($bl_input);
1686
1687 // top bottom padding
1688 $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_top_bottom_padding"), "tb_padding");
1689 $num_input->setAllowPercentage(false);
1690 $num_input->setValue("3px");
1691 $this->form_gui->addItem($num_input);
1692
1693 // left right padding
1694 $num_input = new ilNumericStyleValueInputGUI($lng->txt("sty_left_right_padding"), "lr_padding");
1695 $num_input->setAllowPercentage(false);
1696 $num_input->setValue("10px");
1697 $this->form_gui->addItem($num_input);
1698
1699 // base color
1700 $bc_input = new ilSelectInputGUI($lng->txt("sty_base_color"), "base_color");
1701 $cs = $this->object->getColors();
1702 $options = array();
1703 foreach ($cs as $c) {
1704 $options[$c["name"]] = $c["name"];
1705 }
1706 $bc_input->setOptions($options);
1707 $this->form_gui->addItem($bc_input);
1708
1709 // Lightness Settings
1710 $lss = array("border" => 90, "header_text" => 70, "header_bg" => 0,
1711 "cell1_text" => -60, "cell1_bg" => 90, "cell2_text" => -60, "cell2_bg" => 75);
1712 foreach ($lss as $ls => $v) {
1713 $l_input = new ilNumberInputGUI($lng->txt("sty_lightness_" . $ls), "lightness_" . $ls);
1714 $l_input->setMaxValue(100);
1715 $l_input->setMinValue(-100);
1716 $l_input->setValue((string) $v);
1717 $l_input->setSize(4);
1718 $l_input->setMaxLength(4);
1719 $this->form_gui->addItem($l_input);
1720 }
1721
1722 $this->form_gui->addCommandButton("templateGeneration", $lng->txt("generate"));
1723 $this->form_gui->addCommandButton("cancelTemplateSaving", $lng->txt("cancel"));
1724 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1725 }
1726
1730 public function templateGenerationObject(): void
1731 {
1732 $tpl = $this->gui_service->ui()->mainTemplate();
1733 $ilCtrl = $this->ctrl;
1734 $lng = $this->lng;
1735
1736 $this->initTemplateGenerationForm();
1737
1738 if ($this->form_gui->checkInput()) {
1739 if ($this->object->templateExists($this->form_gui->getInput("name"))) {
1740 $name_input = $this->form_gui->getItemByPostVar("name");
1741 $name_input->setAlert($lng->txt("sty_table_template_already_exists"));
1742 } else {
1743 // -> move to application class!
1744
1745 // cell classes
1746 $cells = array("H" => "header", "C1" => "cell1", "C2" => "cell2");
1747 $tb_p = $this->form_gui->getItemByPostVar("tb_padding");
1748 $tb_padding = $tb_p->getValue();
1749 $lr_p = $this->form_gui->getItemByPostVar("lr_padding");
1750 $lr_padding = $lr_p->getValue();
1751 $cell_color = $this->form_gui->getInput("base_color");
1752
1753 // use mid gray as cell color for bw zebra
1754 if ($this->form_gui->getInput("layout") == "bwZebra") {
1755 $cell_color = "MidGray";
1756 if (!$this->color_manager->colorExists($cell_color)) {
1757 $this->color_manager->addColor($cell_color, "7F7F7F");
1758 }
1759 $this->color_manager->updateColor($cell_color, $cell_color, "7F7F7F");
1760 }
1761
1762 foreach ($cells as $k => $cell) {
1763 $cell_class[$k] = $this->form_gui->getInput("name") . $k;
1764 if (!$this->object->characteristicExists($cell_class[$k], "table_cell")) {
1765 $this->characteristic_manager->addCharacteristic("table_cell", $cell_class[$k], true);
1766 }
1767 if ($this->form_gui->getInput("layout") == "bwZebra" && $k == "H") {
1768 $this->characteristic_manager->replaceParameter(
1769 "td",
1770 $cell_class[$k],
1771 "color",
1772 "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1773 "table_cell"
1774 );
1775 $this->characteristic_manager->replaceParameter(
1776 "td",
1777 $cell_class[$k],
1778 "background-color",
1779 "!" . $this->form_gui->getInput("base_color") . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1780 "table_cell"
1781 );
1782 } else {
1783 $this->characteristic_manager->replaceParameter(
1784 "td",
1785 $cell_class[$k],
1786 "color",
1787 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_text") . ")",
1788 "table_cell"
1789 );
1790 $this->characteristic_manager->replaceParameter(
1791 "td",
1792 $cell_class[$k],
1793 "background-color",
1794 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_" . $cell . "_bg") . ")",
1795 "table_cell"
1796 );
1797 }
1798 $this->characteristic_manager->replaceParameter(
1799 "td",
1800 $cell_class[$k],
1801 "padding-top",
1802 $tb_padding,
1803 "table_cell"
1804 );
1805 $this->characteristic_manager->replaceParameter(
1806 "td",
1807 $cell_class[$k],
1808 "padding-bottom",
1809 $tb_padding,
1810 "table_cell"
1811 );
1812 $this->characteristic_manager->replaceParameter(
1813 "td",
1814 $cell_class[$k],
1815 "padding-left",
1816 $lr_padding,
1817 "table_cell"
1818 );
1819 $this->characteristic_manager->replaceParameter(
1820 "td",
1821 $cell_class[$k],
1822 "padding-right",
1823 $lr_padding,
1824 "table_cell"
1825 );
1826 $this->characteristic_manager->replaceParameter(
1827 "td",
1828 $cell_class[$k],
1829 "border-width",
1830 "1px",
1831 "table_cell"
1832 );
1833 $this->characteristic_manager->replaceParameter(
1834 "td",
1835 $cell_class[$k],
1836 "border-style",
1837 "solid",
1838 "table_cell"
1839 );
1840 $this->characteristic_manager->replaceParameter(
1841 "td",
1842 $cell_class[$k],
1843 "border-color",
1844 "!" . $cell_color . "(" . $this->form_gui->getInput("lightness_border") . ")",
1845 "table_cell"
1846 );
1847 $this->characteristic_manager->replaceParameter(
1848 "td",
1849 $cell_class[$k],
1850 "font-weight",
1851 "normal",
1852 "table_cell"
1853 );
1854 }
1855
1856 // table class
1857 $classes["table"] = $this->form_gui->getInput("name") . "T";
1858 if (!$this->object->characteristicExists($classes["table"], "table")) {
1859 $this->characteristic_manager->addCharacteristic("table", $classes["table"], true);
1860 }
1861 $this->characteristic_manager->replaceParameter(
1862 "table",
1863 $classes["table"],
1864 "caption-side",
1865 "bottom",
1866 "table"
1867 );
1868 $this->characteristic_manager->replaceParameter(
1869 "table",
1870 $classes["table"],
1871 "border-collapse",
1872 "collapse",
1873 "table"
1874 );
1875 $this->characteristic_manager->replaceParameter(
1876 "table",
1877 $classes["table"],
1878 "margin-top",
1879 "5px",
1880 "table"
1881 );
1882 $this->characteristic_manager->replaceParameter(
1883 "table",
1884 $classes["table"],
1885 "margin-bottom",
1886 "5px",
1887 "table"
1888 );
1889 if ($this->form_gui->getInput("layout") == "bwZebra") {
1890 $this->characteristic_manager->replaceParameter(
1891 "table",
1892 $classes["table"],
1893 "border-bottom-color",
1894 "!" . $this->form_gui->getInput("base_color"),
1895 "table"
1896 );
1897 $this->characteristic_manager->replaceParameter(
1898 "table",
1899 $classes["table"],
1900 "border-bottom-style",
1901 "solid",
1902 "table"
1903 );
1904 $this->characteristic_manager->replaceParameter(
1905 "table",
1906 $classes["table"],
1907 "border-bottom-width",
1908 "3px",
1909 "table"
1910 );
1911 $sb = array("left", "right", "top");
1912 foreach ($sb as $b) {
1913 $this->characteristic_manager->replaceParameter(
1914 "table",
1915 $classes["table"],
1916 "border-" . $b . "-width",
1917 "0px",
1918 "table"
1919 );
1920 }
1921 }
1922
1923 switch ($this->form_gui->getInput("layout")) {
1924 case "bwZebra":
1925 case "coloredZebra":
1926 $classes["row_head"] = $cell_class["H"];
1927 $classes["odd_row"] = $cell_class["C1"];
1928 $classes["even_row"] = $cell_class["C2"];
1929 break;
1930
1931 case "noZebra":
1932 $classes["row_head"] = $cell_class["H"];
1933 $classes["odd_row"] = $cell_class["C1"];
1934 $classes["even_row"] = $cell_class["C1"];
1935 $classes["col_head"] = $cell_class["C2"];
1936 break;
1937 }
1938
1939
1940 $t_id = $this->object->addTemplate(
1941 $this->style_request->getTempType(),
1942 $this->form_gui->getInput("name"),
1943 $classes
1944 );
1945 $this->object->writeTemplatePreview(
1946 $t_id,
1947 $this->getTemplatePreview(
1948 $this->style_request->getTempType(),
1949 $t_id,
1950 true
1951 )
1952 );
1953 $ilCtrl->redirect($this, "listTemplates");
1954 }
1955 }
1956 $this->form_gui->setValuesByPost();
1957 $tpl->setContent($this->form_gui->getHTML());
1958 }
1959
1960 public function returnToUpperContextObject(): void
1961 {
1962 $ilCtrl = $this->ctrl;
1963 $ilCtrl->returnToParent($this);
1964 }
1965}
$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(?array $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