ILIAS  release_8 Revision v8.24
class.ilSettingsTemplateGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
29{
33 protected ilLanguage $lng;
34
36 protected \ILIAS\DI\Container $dic;
41
42 public function __construct(ilSettingsTemplateConfig $a_config)
43 {
45 global $DIC;
46
47 $this->dic = $DIC;
48 $this->rbacsystem = $this->dic->rbac()->system();
49 $this->ctrl = $this->dic->ctrl();
50 $this->tpl = $this->dic["tpl"];
51 $this->toolbar = $this->dic->toolbar();
52 $this->lng = $this->dic->language();
53 $ilCtrl = $this->dic->ctrl();
54
55 $this->request = new SettingsTemplateGUIRequest(
56 $DIC->http(),
57 $DIC->refinery()
58 );
59
60 $ilCtrl->saveParameter($this, array("templ_id"));
61 $this->setConfig($a_config);
62 $this->readSettingsTemplate();
63 }
64
65 public function executeCommand(): void
66 {
67 $ilCtrl = $this->ctrl;
68
69 $cmd = $ilCtrl->getCmd("listSettingsTemplates");
70 $this->$cmd();
71 }
72
73 public function setConfig(ilSettingsTemplateConfig $a_val): void
74 {
75 $this->config = $a_val;
76 }
77
79 {
80 return $this->config;
81 }
82
83 public function readSettingsTemplate(): void
84 {
85 if ($this->getConfig()) {
86 $this->settings_template = new ilSettingsTemplate(
87 $this->request->getTemplateId(),
88 $this->getConfig()
89 );
90 } else {
91 $this->settings_template = new ilSettingsTemplate(
92 $this->request->getTemplateId()
93 );
94 }
95 }
96
97 public function listSettingsTemplates(): void
98 {
100 $ilToolbar = $this->toolbar;
101 $ilCtrl = $this->ctrl;
103
104 if ($this->rbacsystem->checkAccess('write', $this->request->getRefId())) {
105 $ilToolbar->addButton(
106 $lng->txt("adm_add_settings_template"),
107 $ilCtrl->getLinkTarget($this, "addSettingsTemplate")
108 );
109 }
110
111 $table = new ilSettingsTemplateTableGUI(
112 $this,
113 "listSettingsTemplates",
114 $this->getConfig()->getType()
115 );
116
117 $tpl->setContent($table->getHTML());
118 }
119
120 public function addSettingsTemplate(): void
121 {
123
124 $this->initSettingsTemplateForm("create");
125 $tpl->setContent($this->form->getHTML());
126 }
127
128 public function editSettingsTemplate(): void
129 {
131
132 $this->initSettingsTemplateForm("edit");
134 $tpl->setContent($this->form->getHTML());
135 }
136
137 public function initSettingsTemplateForm(string $a_mode = "edit"): void
138 {
140 $ilCtrl = $this->ctrl;
141
142 $this->form = new ilPropertyFormGUI();
143
144 // title
145 $ti = new ilTextInputGUI($lng->txt("title"), "title");
146 $ti->setMaxLength(200);
147 $ti->setRequired(true);
148 // begin-patch lok
149 if ($this->settings_template->getAutoGenerated()) {
150 $ti->setDisabled(true);
151 }
152 // end-patch lok
153 $this->form->addItem($ti);
154
155 // description
156 $ti = new ilTextAreaInputGUI($lng->txt("description"), "description");
157 // begin-patch lok
158 if ($this->settings_template->getAutoGenerated()) {
159 $ti->setDisabled(true);
160 }
161 $this->form->addItem($ti);
162
163 // hidable tabs
164 $tabs = $this->getConfig()->getHidableTabs();
165 if (is_array($tabs) && count($tabs) > 0) {
166 $sec = new ilFormSectionHeaderGUI();
167 $sec->setTitle($lng->txt("adm_hide_tabs"));
168 $this->form->addItem($sec);
169
170 foreach ($tabs as $t) {
171 // hide tab $t?
172 $cb = new ilCheckboxInputGUI($t["text"], "tab_" . $t["id"]);
173 $this->form->addItem($cb);
174 }
175 }
176
177 // settings
178 $settings = $this->getConfig()->getSettings();
179 if (is_array($settings) && count($settings) > 0) {
180 $sec = new ilFormSectionHeaderGUI();
181 $sec->setTitle($lng->txt("adm_predefined_settings"));
182 $this->form->addItem($sec);
183
184 foreach ($settings as $s) {
185 // setting
186 $cb = new ilCheckboxInputGUI($s["text"], "set_" . $s["id"]);
187 $this->form->addItem($cb);
188
189 switch ($s["type"]) {
191
192 $ti = new ilTextInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
193 //$ti->setMaxLength();
194 //$ti->setSize();
195 $cb->addSubItem($ti);
196 break;
197
199 $cb2 = new ilCheckboxInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
200 $cb->addSubItem($cb2);
201 break;
202
204 $si = new ilSelectInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
205 $si->setOptions($s["options"]);
206 $cb->addSubItem($si);
207 break;
208
210 $chbs = new ilCheckboxGroupInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
211 foreach ($s['options'] as $key => $value) {
212 $chbs->addOption($c = new ilCheckboxInputGUI($value, $key));
213 $c->setValue($key);
214 }
215 $cb->addSubItem($chbs);
216 break;
217 }
218
219 if ($s['hidable']) {
220 // hide setting
221 $cb_hide = new ilCheckboxInputGUI($lng->txt("adm_hide"), "hide_" . $s["id"]);
222 $cb->addSubItem($cb_hide);
223 }
224 }
225 }
226
227 if ($this->rbacsystem->checkAccess('write', $this->request->getRefId())) {
228 // save and cancel commands
229 if ($a_mode === "create") {
230 $this->form->addCommandButton("saveSettingsTemplate", $lng->txt("save"));
231 $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
232 $this->form->setTitle($lng->txt("adm_add_settings_template"));
233 } else {
234 $this->form->addCommandButton("updateSettingsTemplate", $lng->txt("save"));
235 $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
236 $this->form->setTitle($lng->txt("adm_edit_settings_template"));
237 }
238 }
239
240 $this->form->setFormAction($ilCtrl->getFormAction($this));
241 }
242
243 public function getSettingsTemplateValues(): void
244 {
245 $values = array();
246
247 $values["title"] = $this->settings_template->getTitle();
248 $values["description"] = $this->settings_template->getDescription();
249
250 // save tabs to be hidden
251 $tabs = $this->settings_template->getHiddenTabs();
252 foreach ($tabs as $t) {
253 $values["tab_" . $t] = true;
254 }
255
256 // save settings values
257 $set = $this->settings_template->getSettings();
258 foreach ($this->getConfig()->getSettings() as $s) {
259 if (isset($set[$s["id"]])) {
260 $values["set_" . $s["id"]] = true;
261
262 if ($s['type'] === ilSettingsTemplateConfig::CHECKBOX) {
263 if (!is_array($set[$s["id"]]["value"])) {
264 $ar = unserialize($set[$s["id"]]["value"], ['allowed_classes' => false]);
265 } else {
266 $ar = $set[$s["id"]]["value"];
267 }
268 $values["value_" . $s["id"]] = is_array($ar) ? $ar : array();
269 } else {
270 $values["value_" . $s["id"]] = $set[$s["id"]]["value"];
271 }
272
273 $values["hide_" . $s["id"]] = $set[$s["id"]]["hide"];
274 }
275 }
276 $this->form->setValuesByArray($values);
277 }
278
279 public function saveSettingsTemplate(): void
280 {
283 $ilCtrl = $this->ctrl;
284
285 $this->initSettingsTemplateForm("create");
286 if ($this->form->checkInput()) {
287 $settings_template = new ilSettingsTemplate();
288 $settings_template->setType($this->getConfig()->getType());
289
290 $this->setValuesFromForm($settings_template);
292
293 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
294 $ilCtrl->redirect($this, "listSettingsTemplates");
295 }
296
297 $this->form->setValuesByPost();
298 $tpl->setContent($this->form->getHTML());
299 }
300
301 public function updateSettingsTemplate(): void
302 {
304 $ilCtrl = $this->ctrl;
306
307 $this->initSettingsTemplateForm("edit");
308 if ($this->form->checkInput()) {
309 $this->setValuesFromForm($this->settings_template);
310 $this->settings_template->update();
311
312 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
313 $ilCtrl->redirect($this, "listSettingsTemplates");
314 }
315
316 $this->form->setValuesByPost();
317 $tpl->setContent($this->form->getHTML());
318 }
319
320 public function setValuesFromForm(ilSettingsTemplate $a_set_templ): void
321 {
322 // perform update
323 $a_set_templ->setTitle($this->form->getInput("title"));
324 $a_set_templ->setDescription($this->form->getInput("description"));
325
326 // save tabs to be hidden
327 $a_set_templ->removeAllHiddenTabs();
328 foreach ($this->getConfig()->getHidableTabs() as $t) {
329 if ($this->request->getTab($t["id"])) {
330 $a_set_templ->addHiddenTab($t["id"]);
331 }
332 }
333
334 // save settings values
335 $a_set_templ->removeAllSettings();
336 foreach ($this->getConfig()->getSettings() as $s) {
337 if ($this->request->getSetting($s["id"])) {
338 $a_set_templ->setSetting(
339 $s["id"],
340 $this->request->getValue($s["id"]),
341 $this->request->getHide($s["id"])
342 );
343 }
344 }
345 }
346
347 public function confirmSettingsTemplateDeletion(): void
348 {
349 $ilCtrl = $this->ctrl;
352
353 if (count($this->request->getTemplateIds()) === 0) {
354 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
355 $ilCtrl->redirect($this, "listSettingsTemplates");
356 } else {
357 $cgui = new ilConfirmationGUI();
358 $cgui->setFormAction($ilCtrl->getFormAction($this));
359 $cgui->setHeaderText($lng->txt("adm_sure_delete_settings_template"));
360 $cgui->setCancel($lng->txt("cancel"), "listSettingsTemplates");
361 $cgui->setConfirm($lng->txt("delete"), "deleteSettingsTemplate");
362
363 foreach ($this->request->getTemplateIds() as $i) {
364 $cgui->addItem("tid[]", (string) $i, ilSettingsTemplate::lookupTitle($i));
365 }
366
367 $tpl->setContent($cgui->getHTML());
368 }
369 }
370
371 public function deleteSettingsTemplate(): void
372 {
373 $ilCtrl = $this->ctrl;
374
375 foreach ($this->request->getTemplateIds() as $i) {
376 $templ = new ilSettingsTemplate($i);
377 $templ->delete();
378 }
379 $this->tpl->setOnScreenMessage('success', "msg_obj_modified");
380 $ilCtrl->redirect($this, "listSettingsTemplates");
381 }
382}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
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...
This class represents a property form user interface.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValuesFromForm(ilSettingsTemplate $a_set_templ)
ilSettingsTemplateConfig $config
setConfig(ilSettingsTemplateConfig $a_val)
ilGlobalTemplateInterface $tpl
initSettingsTemplateForm(string $a_mode="edit")
SettingsTemplateGUIRequest $request
Settings template application class.
setSetting(string $a_setting, $a_value, bool $a_hide=false)
Set setting.
addHiddenTab(string $a_tab_id)
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCmd(string $fallback_command=null)
Returns the command passed with the current POST or GET request.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
getSettings()
Get an array of all setting values.
Definition: System.php:287
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
form( $class_path, string $cmd)