ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjectCustomIconConfigurationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 const DEFAULT_CMD = 'showForm';
11
13 protected $dic;
14
16 protected $object;
17
19 protected $parentGui;
20
25
32 public function __construct(\ILIAS\DI\Container $dic, $parentGui, \ilObject $object)
33 {
34 $this->dic = $dic;
35 $this->parentGui = $parentGui;
36 $this->object = $object;
37 }
38
43 {
44 $this->uploadFieldInformationText = $uploadFieldInformationText;
45 }
46
47 public function executeCommand()
48 {
49 $nextClass = $this->dic->ctrl()->getNextClass($this);
50 $cmd = $this->dic->ctrl()->getCmd(self::DEFAULT_CMD);
51
52 switch (true) {
53 case method_exists($this, $cmd):
54 $this->{$cmd}();
55 break;
56
57 default:
58 $this->{self::DEFAULT_CMD}();
59 break;
60 }
61 }
62
66 protected function showForm(\ilPropertyFormGUI $form = null)
67 {
68 if (!$form) {
69 $form = $this->getForm();
70 }
71
72 $this->dic->ui()->mainTemplate()->setContent($form->getHTML());
73 }
74
78 protected function getForm() : \ilPropertyFormGUI
79 {
80 $this->dic->language()->loadLanguageModule('cntr');
81
82 $form = new \ilPropertyFormGUI();
83 $form->setFormAction($this->dic->ctrl()->getFormAction($this, 'saveForm'));
84 $form->setTitle($this->dic->language()->txt('icon_settings'));
85
86 $this->addSettingsToForm($form);
87
88 $form->addCommandButton('saveForm', $this->dic->language()->txt('save'));
89
90 return $form;
91 }
92
98 public function addSettingsToForm(ilPropertyFormGUI $form)
99 {
101 $customIconFactory = $this->dic['object.customicons.factory'];
102 $customIcon = $customIconFactory->getByObjId($this->object->getId(), $this->object->getType());
103
104 $icon = new \ilImageFileInputGUI($this->dic->language()->txt('cont_custom_icon'), 'icon');
105 if (is_string($this->uploadFieldInformationText)) {
106 $icon->setInfo($this->uploadFieldInformationText);
107 }
108 $icon->setSuffixes($customIcon->getSupportedFileExtensions());
109 $icon->setUseCache(false);
110 if ($customIcon->exists()) {
111 $icon->setImage($customIcon->getFullPath());
112 } else {
113 $icon->setImage('');
114 }
115 $form->addItem($icon);
116 }
117
121 protected function saveForm()
122 {
123 $form = $this->getForm();
124 if ($form->checkInput()) {
125 $this->saveIcon($form);
126
127 ilUtil::sendSuccess($this->dic->language()->txt('msg_obj_modified'), true);
128 $this->dic->ctrl()->redirect($this, 'showForm');
129 }
130
131 $form->setValuesByPost();
132 $this->showForm($form);
133 }
134
140 public function saveIcon(ilPropertyFormGUI $form)
141 {
143 $customIconFactory = $this->dic['object.customicons.factory'];
144 $customIcon = $customIconFactory->getByObjId($this->object->getId(), $this->object->getType());
145
147 $fileData = (array) $form->getInput('icon');
148 $item = $form->getItemByPostVar('icon');
149
150 if ($item->getDeletionFlag()) {
151 $customIcon->remove();
152 }
153
154 if ($fileData['tmp_name']) {
155 $customIcon->saveFromHttpRequest();
156 }
157 }
158}
An exception for terminatinating execution or to throw for unit testing.
__construct(\ILIAS\DI\Container $dic, $parentGui, \ilObject $object)
ilObjectCustomIconConfigurationGUI constructor.
Class ilObject Basic functions for all objects.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
checkInput()
Check Post Input.
setValuesByPost()
Set form values from POST values.
getItemByPostVar($a_post_var)
Get Item by POST variable.
Class HTTPServicesTest.
Class ChatMainBarProvider \MainMenu\Provider.