ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjQuestionPoolSettingsGeneralGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
20 const CMD_SHOW_FORM = 'showForm';
21 const CMD_SAVE_FORM = 'saveForm';
22
28 protected $ctrl = null;
29
35 protected $access = null;
36
42 protected $lng = null;
43
49 protected $tpl = null;
50
56 protected $tabs = null;
57
63 protected $poolGUI = null;
64
70 protected $poolOBJ = null;
71
76 {
77 $this->ctrl = $ctrl;
78 $this->access = $access;
79 $this->lng = $lng;
80 $this->tpl = $tpl;
81 $this->tabs = $tabs;
82
83 $this->poolGUI = $poolGUI;
84 $this->poolOBJ = $poolGUI->object;
85 }
86
90 public function executeCommand()
91 {
92 // allow only write access
93
94 if (!$this->access->checkAccess('write', '', $this->poolGUI->ref_id)) {
95 ilUtil::sendInfo($this->lng->txt('cannot_edit_question_pool'), true);
96 $this->ctrl->redirectByClass('ilObjQuestionPoolGUI', 'infoScreen');
97 }
98
99 // activate corresponding tab (auto activation does not work in ilObjTestGUI-Tabs-Salad)
100
101 $this->tabs->activateTab('settings');
102
103 // process command
104
105 $nextClass = $this->ctrl->getNextClass();
106
107 switch ($nextClass) {
108 default:
109 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_FORM) . 'Cmd';
110 $this->$cmd();
111 }
112 }
113
114 private function showFormCmd(ilPropertyFormGUI $form = null)
115 {
116 if ($form === null) {
117 $form = $this->buildForm();
118 }
119
120 $this->tpl->setContent($this->ctrl->getHTML($form));
121 }
122
123 private function saveFormCmd()
124 {
125 $form = $this->buildForm();
126
127 // form validation and initialisation
128
129 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
130 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
131
132 // return to form when any form validation errors exist
133
134 if ($errors) {
135 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
136 return $this->showFormCmd($form);
137 }
138
139 // perform saving the form data
140
141 $this->performSaveForm($form);
142
143 // redirect to form output
144
145 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
146 $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
147 }
148
149 private function performSaveForm(ilPropertyFormGUI $form)
150 {
151 global $DIC; /* @var \ILIAS\DI\Container $DIC */
152
153 include_once 'Services/MetaData/classes/class.ilMD.php';
154 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
155 $md_section = $md_obj->getGeneral();
156
157 // title
158 $md_section->setTitle($form->getItemByPostVar('title')->getValue());
159 $md_section->update();
160
161 // Description
162 $md_desc_ids = $md_section->getDescriptionIds();
163 if ($md_desc_ids) {
164 $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
165 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
166 $md_desc->update();
167 } else {
168 $md_desc = $md_section->addDescription();
169 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
170 $md_desc->save();
171 }
172
173 $this->poolOBJ->setTitle($form->getItemByPostVar('title')->getValue());
174 $this->poolOBJ->setDescription($form->getItemByPostVar('description')->getValue());
175 $this->poolOBJ->update();
176
177 $online = $form->getItemByPostVar('online');
178 $this->poolOBJ->setOnline($online->getChecked());
179
180 $showTax = $form->getItemByPostVar('show_taxonomies');
181 $this->poolOBJ->setShowTaxonomies($showTax->getChecked());
182
183 $navTax = $form->getItemByPostVar('nav_taxonomy');
184 $this->poolOBJ->setNavTaxonomyId($navTax->getValue());
185
186 $DIC->object()->commonSettings()->legacyForm($form, $this->poolOBJ)->saveTileImage();
187
188 if ($this->formPropertyExists($form, 'skill_service')) {
189 $skillService = $form->getItemByPostVar('skill_service');
190 $this->poolOBJ->setSkillServiceEnabled($skillService->getChecked());
191 }
192
193 $this->poolOBJ->saveToDb();
194 }
195
196 private function buildForm()
197 {
198 global $DIC; /* @var \ILIAS\DI\Container $DIC */
199
200 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
201 $form = new ilPropertyFormGUI();
202
203 $form->setFormAction($this->ctrl->getFormAction($this));
204 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
205
206 $form->setTitle($this->lng->txt('qpl_form_general_settings'));
207 $form->setId('properties');
208
209 include_once 'Services/MetaData/classes/class.ilMD.php';
210 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
211 $md_section = $md_obj->getGeneral();
212
213 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
214 $title->setRequired(true);
215 $title->setValue($md_section->getTitle());
216 $form->addItem($title);
217
218 $ids = $md_section->getDescriptionIds();
219 if ($ids) {
220 $desc_obj = $md_section->getDescription(array_pop($ids));
221
222 $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
223 $desc->setCols(50);
224 $desc->setRows(4);
225 $desc->setValue($desc_obj->getDescription());
226 $form->addItem($desc);
227 }
228
229 // online
230
231 $online = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_online'), 'online');
232 $online->setInfo($this->lng->txt('qpl_settings_general_form_property_online_description'));
233 $online->setChecked($this->poolOBJ->getOnline());
234 $form->addItem($online);
235
236 // show taxonomies
237
238 $showTax = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_show_taxonomies'), 'show_taxonomies');
239 $showTax->setInfo($this->lng->txt('qpl_settings_general_form_prop_show_tax_desc'));
240 $showTax->setChecked($this->poolOBJ->getShowTaxonomies());
241 $form->addItem($showTax);
242
243 $taxSelectOptions = $this->getTaxonomySelectInputOptions();
244
245 // pool navigation taxonomy
246
247 $navTax = new ilSelectInputGUI($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy'), 'nav_taxonomy');
248 $navTax->setInfo($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy_description'));
249 $navTax->setValue($this->poolOBJ->getNavTaxonomyId());
250 $navTax->setOptions($taxSelectOptions);
251 $showTax->addSubItem($navTax);
252
254 $section->setTitle($this->lng->txt('tst_presentation_settings_section'));
255 $form->addItem($section);
256
257 $DIC->object()->commonSettings()->legacyForm($form, $this->poolOBJ)->addTileImage();
258
259 // skill service activation
260
262 $otherHead = new ilFormSectionHeaderGUI();
263 $otherHead->setTitle($this->lng->txt('obj_features'));
264 $form->addItem($otherHead);
265
266 $skillService = new ilCheckboxInputGUI($this->lng->txt('tst_activate_skill_service'), 'skill_service');
267 $skillService->setChecked($this->poolOBJ->isSkillServiceEnabled());
268 $form->addItem($skillService);
269 }
270
271 return $form;
272 }
273
275 {
276 $taxSelectOptions = array(
277 '0' => $this->lng->txt('qpl_settings_general_form_property_opt_notax_selected')
278 );
279
280 foreach ($this->poolOBJ->getTaxonomyIds() as $taxId) {
281 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
282 }
283
284 return $taxSelectOptions;
285 }
286
287 protected function formPropertyExists(ilPropertyFormGUI $form, $propertyId)
288 {
289 return $form->getItemByPostVar($propertyId) instanceof ilFormPropertyGUI;
290 }
291}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This class provides processing control methods.
This class represents a property in a property form.
This class represents a section header in a property form.
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($a_id)
lookup object title
This class represents a property form user interface.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a selection list property in a property form.
Tabs GUI.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
$errors
Definition: imgupload.php:49
Interface ilAccessHandler.