ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjTestDynamicQuestionSetConfigGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilObjTestDynamicQuestionSetConfig.php';
5
17{
21 const CMD_SHOW_FORM = 'showForm';
22 const CMD_SAVE_FORM = 'saveForm';
23 const CMD_GET_TAXONOMY_OPTIONS_ASYNC = 'getTaxonomyOptionsAsync';
24
30 protected $ctrl = null;
31
37 protected $access = null;
38
44 protected $tabs = null;
45
51 protected $lng = null;
52
58 protected $tpl = null;
59
65 protected $db = null;
66
72 protected $tree = null;
73
79 protected $testOBJ = null;
80
86 protected $questionSetConfig = null;
87
88 const QUESTION_ORDERING_TYPE_UPDATE_DATE = 'ordering_by_date';
89 const QUESTION_ORDERING_TYPE_TAXONOMY = 'ordering_by_tax';
90
95 {
96 $this->ctrl = $ctrl;
97 $this->access = $access;
98 $this->tabs = $tabs;
99 $this->lng = $lng;
100 $this->tpl = $tpl;
101 $this->db = $db;
102 $this->tree = $tree;
103 $this->pluginAdmin = $pluginAdmin;
104
105 $this->testOBJ = $testOBJ;
106
107 $this->questionSetConfig = new ilObjTestDynamicQuestionSetConfig($this->tree, $this->db, $this->pluginAdmin, $this->testOBJ);
108 }
109
113 public function executeCommand()
114 {
115 // allow only write access
116
117 if (!$this->access->checkAccess("write", "", $this->testOBJ->getRefId())) {
118 ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
119 $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
120 }
121
122 // activate corresponding tab (auto activation does not work in ilObjTestGUI-Tabs-Salad)
123
124 $this->tabs->activateTab('assQuestions');
125
126 // process command
127
128 $nextClass = $this->ctrl->getNextClass();
129
130 switch ($nextClass) {
131 default:
132 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_FORM) . 'Cmd';
133 $this->$cmd();
134 }
135 }
136
138 {
139 $questionPoolId = (int) $_POST['question_pool_id'];
140
141 echo $this->buildTaxonomySelectInputOptionJson($questionPoolId);
142 exit;
143 }
144
150 public function showFormCmd(ilPropertyFormGUI $form = null)
151 {
152 $this->questionSetConfig->loadFromDb();
153
154 if ($this->questionSetConfig->areDepenciesBroken($this->tree)) {
155 ilUtil::sendFailure($this->questionSetConfig->getDepenciesBrokenMessage($this->lng));
156 } elseif ($this->questionSetConfig->areDepenciesInVulnerableState($this->tree)) {
157 ilUtil::sendInfo($this->questionSetConfig->getDepenciesInVulnerableStateMessage($this->lng));
158 }
159
160 if ($form === null) {
161 $form = $this->buildForm($this->questionSetConfig->getSourceQuestionPoolId());
162 }
163
164 $this->tpl->setContent($this->ctrl->getHTML($form));
165
166 $this->tpl->addJavaScript('Modules/Test/js/ilTestDynamicQuestionSetConfig.js');
167 }
168
173 {
174 return (int) $_POST['source_qpl_id'];
175 }
176
183 public function saveFormCmd()
184 {
185 $form = $this->buildForm(
187 );
188
189 if ($this->testOBJ->participantDataExist()) {
190 ilUtil::sendFailure($this->lng->txt("tst_msg_cannot_modify_dynamic_question_set_conf_due_to_part"), true);
191 return $this->showFormCmd($form);
192 }
193
194 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
195 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
196
197 if ($errors) {
198 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
199 return $this->showFormCmd($form);
200 }
201
202 $this->performSaveForm($form);
203
204 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
205
206 ilUtil::sendSuccess($this->lng->txt("tst_msg_dynamic_question_set_config_modified"), true);
207 $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
208 }
209
216 {
217 $this->questionSetConfig->setSourceQuestionPoolId(
218 $form->getItemByPostVar('source_qpl_id')->getValue()
219 );
220
221 $this->questionSetConfig->setSourceQuestionPoolTitle(ilObject::_lookupTitle(
222 $form->getItemByPostVar('source_qpl_id')->getValue()
223 ));
224
225 switch ($form->getItemByPostVar('question_ordering')->getValue()) {
227 $this->questionSetConfig->setOrderingTaxonomyId(null);
228 break;
229
231 $this->questionSetConfig->setOrderingTaxonomyId(
232 $form->getItemByPostVar('ordering_tax')->getValue()
233 );
234 break;
235 }
236
237 $this->questionSetConfig->setTaxonomyFilterEnabled(
238 $form->getItemByPostVar('tax_filter_enabled')->getChecked()
239 );
240
241 $this->questionSetConfig->setAnswerStatusFilterEnabled(
242 $form->getItemByPostVar('answer_status_filter_enabled')->getChecked()
243 );
244
245 $this->questionSetConfig->saveToDb($this->testOBJ->getTestId());
246 }
247
254 private function buildForm($sourceQuestionPoolId)
255 {
256 $this->questionSetConfig->loadFromDb($this->testOBJ->getTestId());
257
258 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
259 $form = new ilPropertyFormGUI();
260
261 $form->setFormAction($this->ctrl->getFormAction($this));
262
263 $form->setId("tst_form_dynamic_question_set_config");
264 $form->setTitle($this->lng->txt('tst_form_dynamic_question_set_config'));
265 $form->setTableWidth("100%");
266
267 $hiddenInputTaxSelectOptAsyncUrl = new ilHiddenInputGUI('taxSelectOptAsyncUrl');
268 $hiddenInputTaxSelectOptAsyncUrl->setValue(
269 $this->ctrl->getLinkTarget($this, self::CMD_GET_TAXONOMY_OPTIONS_ASYNC, '', true)
270 );
271 $form->addItem($hiddenInputTaxSelectOptAsyncUrl);
272
273 if ($this->testOBJ->participantDataExist()) {
274 $pool = new ilNonEditableValueGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_title');
275 $pool->setValue($this->questionSetConfig->getSourceQuestionPoolSummaryString($this->lng, $this->tree));
276 $pool->setDisabled(true);
277 $form->addItem($pool);
278 } else {
279 $poolInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_id');
280 $poolInput->setOptions($this->buildQuestionPoolSelectInputOptionArray(
281 $this->testOBJ->getAvailableQuestionpools(true, false, false, true, true)
282 ));
283 $poolInput->setValue($sourceQuestionPoolId);
284 $poolInput->setRequired(true);
285 $form->addItem($poolInput);
286 }
287
288 $questionOderingInput = new ilRadioGroupInputGUI(
289 $this->lng->txt('tst_input_dynamic_question_set_question_ordering'),
290 'question_ordering'
291 );
292 $questionOderingInput->setValue(
293 $this->questionSetConfig->getOrderingTaxonomyId() ?
294 self::QUESTION_ORDERING_TYPE_TAXONOMY : self::QUESTION_ORDERING_TYPE_UPDATE_DATE
295 );
296 $optionOrderByDate = new ilRadioOption(
297 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_date'),
298 self::QUESTION_ORDERING_TYPE_UPDATE_DATE,
299 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_date_desc')
300 );
301 $questionOderingInput->addOption($optionOrderByDate);
302 $optionOrderByTax = new ilRadioOption(
303 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_tax'),
304 self::QUESTION_ORDERING_TYPE_TAXONOMY,
305 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_tax_desc')
306 );
307 $orderTaxInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_ordering_tax'), 'ordering_tax');
308 $orderTaxInput->setInfo($this->lng->txt('tst_input_dynamic_question_set_ordering_tax_description'));
309 $orderTaxInput->setValue($this->questionSetConfig->getOrderingTaxonomyId());
310 $orderTaxInput->setRequired(true);
311 $orderTaxInput->setOptions($this->buildTaxonomySelectInputOptionArray($sourceQuestionPoolId));
312 $optionOrderByTax->addSubItem($orderTaxInput);
313 $questionOderingInput->addOption($optionOrderByTax);
314 $form->addItem($questionOderingInput);
315
316 $taxFilterInput = new ilCheckboxInputGUI($this->lng->txt('tst_input_dynamic_question_set_taxonomie_filter_enabled'), 'tax_filter_enabled');
317 $taxFilterInput->setValue(1);
318 $taxFilterInput->setChecked($this->questionSetConfig->isTaxonomyFilterEnabled());
319 $form->addItem($taxFilterInput);
320
321 $answStatusFilterInput = new ilCheckboxInputGUI(
322 $this->lng->txt('tst_input_dyn_quest_set_answer_status_filter_enabled'),
323 'answer_status_filter_enabled'
324 );
325 $answStatusFilterInput->setValue(1);
326 $answStatusFilterInput->setChecked($this->questionSetConfig->isAnswerStatusFilterEnabled());
327 $form->addItem($answStatusFilterInput);
328
329 if ($this->testOBJ->participantDataExist()) {
330 $questionOderingInput->setDisabled(true);
331 $taxFilterInput->setDisabled(true);
332 $answStatusFilterInput->setDisabled(true);
333 } else {
334 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
335 }
336
337 return $form;
338 }
339
346 private function buildQuestionPoolSelectInputOptionArray($questionPoolsData)
347 {
348 $questionPoolSelectInputOptions = array( '' => $this->lng->txt('please_select') );
349
350 foreach ($questionPoolsData as $qplId => $qplData) {
351 $questionPoolSelectInputOptions[$qplId] = $qplData['title'];
352 }
353
354 return $questionPoolSelectInputOptions;
355 }
356
357 private function buildTaxonomySelectInputOptionArray($questionPoolId)
358 {
359 $taxSelectOptions = array(
360 0 => $this->lng->txt('please_select')
361 );
362
363 if ($questionPoolId) {
364 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
365
366 $taxIds = ilObjTaxonomy::getUsageOfObject($questionPoolId);
367
368 foreach ($taxIds as $taxId) {
369 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
370 }
371 }
372
373 return $taxSelectOptions;
374 }
375
376 private function buildTaxonomySelectInputOptionJson($questionPoolId)
377 {
378 $options = array();
379
380 foreach ($this->buildTaxonomySelectInputOptionArray($questionPoolId) as $optValue => $optLabel) {
381 $options[] = array('value' => $optValue, 'label' => $optLabel);
382 }
383
384 return json_encode($options);
385 }
386}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_POST["username"]
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 hidden form property in a property form.
language handling
This class represents a non editable value in a property form.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
showFormCmd(ilPropertyFormGUI $form=null)
command method that prints the question set config form
buildQuestionPoolSelectInputOptionArray($questionPoolsData)
converts the passed question pools data array to select input option array
saveFormCmd()
command method that checks the question set config form
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilTabsGUI $tabs, ilLanguage $lng, ilTemplate $tpl, ilDBInterface $db, ilTree $tree, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
Constructor.
buildForm($sourceQuestionPoolId)
builds the question set config form and initialises the fields with the config currently saved in dat...
performSaveForm(ilPropertyFormGUI $form)
saves the form fields to the database
static _lookupTitle($a_id)
lookup object title
Administration class for plugins.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Tabs GUI.
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Interface ilAccessHandler.
Interface ilDBInterface.
$errors
Definition: index.php:6
if(isset($_POST['submit'])) $form