ILIAS  release_8 Revision v8.24
class.ilObjQuestionPoolSettingsGeneralGUI.php
Go to the documentation of this file.
1<?php
2
31{
35 public const CMD_SHOW_FORM = 'showForm';
36 public const CMD_SAVE_FORM = 'saveForm';
37
43 protected $ctrl = null;
44
50 protected $access = null;
51
57 protected $lng = null;
58
64 protected $tpl = null;
65
71 protected $tabs = null;
72
78 protected $poolGUI = null;
79
85 protected $poolOBJ = null;
86
91 {
92 $this->ctrl = $ctrl;
93 $this->access = $access;
94 $this->lng = $lng;
95 $this->tpl = $tpl;
96 $this->tabs = $tabs;
97
98 $this->poolGUI = $poolGUI;
99 $this->poolOBJ = $poolGUI->object;
100 }
101
105 public function executeCommand(): void
106 {
107 // allow only write access
108
109 if (!$this->access->checkAccess('write', '', $this->poolGUI->getRefId())) {
110 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cannot_edit_question_pool'), true);
111 $this->ctrl->redirectByClass('ilObjQuestionPoolGUI', 'infoScreen');
112 }
113
114 // activate corresponding tab (auto activation does not work in ilObjTestGUI-Tabs-Salad)
115
116 $this->tabs->activateTab('settings');
117 $this->tabs->activateSubTab('qpl_settings_subtab_general');
118
119 // process command
120
121 $nextClass = $this->ctrl->getNextClass();
122
123 switch ($nextClass) {
124 default:
125 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_FORM) . 'Cmd';
126 $this->$cmd();
127 }
128 }
129
130 private function showFormCmd(ilPropertyFormGUI $form = null): void
131 {
132 if ($form === null) {
133 $form = $this->buildForm();
134 }
135
136 $this->tpl->setContent($this->ctrl->getHTML($form));
137 }
138
139 private function saveFormCmd(): void
140 {
141 $form = $this->buildForm();
142
143 // form validation and initialisation
144
145 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
146 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
147
148 // return to form when any form validation errors exist
149
150 if ($errors) {
151 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
152 $this->showFormCmd($form);
153 }
154
155 // perform saving the form data
156
157 $this->performSaveForm($form);
158
159 // redirect to form output
160
161 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
162 $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
163 }
164
165 private function performSaveForm(ilPropertyFormGUI $form): void
166 {
167 global $DIC; /* @var \ILIAS\DI\Container $DIC */
168
169 include_once 'Services/MetaData/classes/class.ilMD.php';
170 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
171 $md_section = $md_obj->getGeneral();
172
173 // title
174 $md_section->setTitle($form->getItemByPostVar('title')->getValue());
175 $md_section->update();
176
177 // Description
178 $md_desc_ids = $md_section->getDescriptionIds();
179 if ($md_desc_ids) {
180 $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
181 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
182 $md_desc->update();
183 } else {
184 $md_desc = $md_section->addDescription();
185 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
186 $md_desc->save();
187 }
188
189 $this->poolOBJ->setTitle($form->getItemByPostVar('title')->getValue());
190 $this->poolOBJ->setDescription($form->getItemByPostVar('description')->getValue());
191 $this->poolOBJ->update();
192
193 $online = $form->getItemByPostVar('online');
194 $this->poolOBJ->setOnline($online->getChecked());
195
196 $showTax = $form->getItemByPostVar('show_taxonomies');
197 $this->poolOBJ->setShowTaxonomies($showTax->getChecked());
198
199 $navTax = $form->getItemByPostVar('nav_taxonomy');
200 $this->poolOBJ->setNavTaxonomyId($navTax->getValue());
201
202 $DIC->object()->commonSettings()->legacyForm($form, $this->poolOBJ)->saveTileImage();
203
204 if ($this->formPropertyExists($form, 'skill_service')) {
205 $skillService = $form->getItemByPostVar('skill_service');
206 $this->poolOBJ->setSkillServiceEnabled($skillService->getChecked());
207 }
208
209 $this->poolOBJ->saveToDb();
210 }
211
212 private function buildForm(): ilPropertyFormGUI
213 {
214 global $DIC; /* @var \ILIAS\DI\Container $DIC */
215
216 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
217 $form = new ilPropertyFormGUI();
218
219 $form->setFormAction($this->ctrl->getFormAction($this));
220 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
221
222 $form->setTitle($this->lng->txt('qpl_form_general_settings'));
223 $form->setId('properties');
224
225 include_once 'Services/MetaData/classes/class.ilMD.php';
226 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
227 $md_section = $md_obj->getGeneral();
228
229 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
230 $title->setRequired(true);
231 $title->setMaxLength(255);
232 $title->setValue($md_section->getTitle());
233 $form->addItem($title);
234
235 $ids = $md_section->getDescriptionIds();
236 if ($ids) {
237 $desc_obj = $md_section->getDescription(array_pop($ids));
238
239 $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
240 $desc->setCols(50);
241 $desc->setRows(4);
242 $desc->setValue($desc_obj->getDescription());
243 $form->addItem($desc);
244 }
245
246 // online
247
248 $online = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_online'), 'online');
249 $online->setInfo($this->lng->txt('qpl_settings_general_form_property_online_description'));
250 $online->setChecked($this->poolOBJ->getOnline());
251 $form->addItem($online);
252
253 // show taxonomies
254
255 $showTax = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_show_taxonomies'), 'show_taxonomies');
256 $showTax->setInfo($this->lng->txt('qpl_settings_general_form_prop_show_tax_desc'));
257 $showTax->setChecked($this->poolOBJ->getShowTaxonomies());
258 $form->addItem($showTax);
259
260 $taxSelectOptions = $this->getTaxonomySelectInputOptions();
261
262 // pool navigation taxonomy
263
264 $navTax = new ilSelectInputGUI($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy'), 'nav_taxonomy');
265 $navTax->setInfo($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy_description'));
266 $navTax->setValue($this->poolOBJ->getNavTaxonomyId());
267 $navTax->setOptions($taxSelectOptions);
268 $showTax->addSubItem($navTax);
269
270 $section = new ilFormSectionHeaderGUI();
271 $section->setTitle($this->lng->txt('tst_presentation_settings_section'));
272 $form->addItem($section);
273
274 $DIC->object()->commonSettings()->legacyForm($form, $this->poolOBJ)->addTileImage();
275
276 // skill service activation
277
279 $otherHead = new ilFormSectionHeaderGUI();
280 $otherHead->setTitle($this->lng->txt('obj_features'));
281 $form->addItem($otherHead);
282
283 $skillService = new ilCheckboxInputGUI($this->lng->txt('tst_activate_skill_service'), 'skill_service');
284 $skillService->setChecked($this->poolOBJ->isSkillServiceEnabled());
285 $form->addItem($skillService);
286 }
287
288 return $form;
289 }
290
291 private function getTaxonomySelectInputOptions(): array
292 {
293 $taxSelectOptions = array(
294 '0' => $this->lng->txt('qpl_settings_general_form_property_opt_notax_selected')
295 );
296
297 foreach ($this->poolOBJ->getTaxonomyIds() as $taxId) {
298 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
299 }
300
301 return $taxSelectOptions;
302 }
303
304 protected function formPropertyExists(ilPropertyFormGUI $form, $propertyId): bool
305 {
306 return $form->getItemByPostVar($propertyId) instanceof ilFormPropertyGUI;
307 }
308}
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilLanguage $lng, ilGlobalTemplateInterface $tpl, ilTabsGUI $tabs, ilObjQuestionPoolGUI $poolGUI)
Constructor.
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
getItemByPostVar(string $a_post_var)
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...
This class represents a text area property in a property form.
This class represents a text property in a property form.
global $DIC
Definition: feed.php:28
$errors
Definition: imgupload.php:65
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...