ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 {
119 ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
120 $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
121 }
122
123 // activate corresponding tab (auto activation does not work in ilObjTestGUI-Tabs-Salad)
124
125 $this->tabs->activateTab('assQuestions');
126
127 // process command
128
129 $nextClass = $this->ctrl->getNextClass();
130
131 switch($nextClass)
132 {
133 default:
134 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_FORM).'Cmd';
135 $this->$cmd();
136 }
137 }
138
140 {
141 $questionPoolId = (int)$_POST['question_pool_id'];
142
143 echo $this->buildTaxonomySelectInputOptionJson($questionPoolId);
144 exit;
145 }
146
152 public function showFormCmd(ilPropertyFormGUI $form = null)
153 {
154 $this->questionSetConfig->loadFromDb();
155
156 if( $this->questionSetConfig->areDepenciesBroken($this->tree) )
157 {
158 ilUtil::sendFailure( $this->questionSetConfig->getDepenciesBrokenMessage($this->lng) );
159 }
160 elseif( $this->questionSetConfig->areDepenciesInVulnerableState($this->tree) )
161 {
162 ilUtil::sendInfo( $this->questionSetConfig->getDepenciesInVulnerableStateMessage($this->lng) );
163 }
164
165 if( $form === null )
166 {
167 $form = $this->buildForm($this->questionSetConfig->getSourceQuestionPoolId());
168 }
169
170 $this->tpl->setContent( $this->ctrl->getHTML($form) );
171
172 $this->tpl->addJavaScript('Modules/Test/js/ilTestDynamicQuestionSetConfig.js');
173 }
174
179 {
180 return (int)$_POST['source_qpl_id'];
181 }
182
189 public function saveFormCmd()
190 {
191 $form = $this->buildForm(
193 );
194
195 if( $this->testOBJ->participantDataExist() )
196 {
197 ilUtil::sendFailure($this->lng->txt("tst_msg_cannot_modify_dynamic_question_set_conf_due_to_part"), true);
198 return $this->showFormCmd($form);
199 }
200
201 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
202 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
203
204 if($errors)
205 {
206 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
207 return $this->showFormCmd($form);
208 }
209
210 $this->performSaveForm($form);
211
212 $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
213
214 ilUtil::sendSuccess($this->lng->txt("tst_msg_dynamic_question_set_config_modified"), true);
215 $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
216 }
217
223 private function performSaveForm(ilPropertyFormGUI $form)
224 {
225 $this->questionSetConfig->setSourceQuestionPoolId(
226 $form->getItemByPostVar('source_qpl_id')->getValue()
227 );
228
229 $this->questionSetConfig->setSourceQuestionPoolTitle( ilObject::_lookupTitle(
230 $form->getItemByPostVar('source_qpl_id')->getValue()
231 ));
232
233 switch( $form->getItemByPostVar('question_ordering')->getValue() )
234 {
236 $this->questionSetConfig->setOrderingTaxonomyId(null);
237 break;
238
240 $this->questionSetConfig->setOrderingTaxonomyId(
241 $form->getItemByPostVar('ordering_tax')->getValue()
242 );
243 break;
244 }
245
246 $this->questionSetConfig->setTaxonomyFilterEnabled(
247 $form->getItemByPostVar('tax_filter_enabled')->getChecked()
248 );
249
250 $this->questionSetConfig->setAnswerStatusFilterEnabled(
251 $form->getItemByPostVar('answer_status_filter_enabled')->getChecked()
252 );
253
254 $this->questionSetConfig->setPreviousQuestionsListEnabled(
255 $form->getItemByPostVar('prev_quest_list_enabled')->getChecked()
256 );
257
258 $this->questionSetConfig->saveToDb( $this->testOBJ->getTestId() );
259 }
260
267 private function buildForm($sourceQuestionPoolId)
268 {
269 $this->questionSetConfig->loadFromDb( $this->testOBJ->getTestId() );
270
271 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
272 $form = new ilPropertyFormGUI();
273
274 $form->setFormAction($this->ctrl->getFormAction($this));
275
276 $form->setId("tst_form_dynamic_question_set_config");
277 $form->setTitle($this->lng->txt('tst_form_dynamic_question_set_config'));
278 $form->setTableWidth("100%");
279
280 $hiddenInputTaxSelectOptAsyncUrl = new ilHiddenInputGUI('taxSelectOptAsyncUrl');
281 $hiddenInputTaxSelectOptAsyncUrl->setValue(
282 $this->ctrl->getLinkTarget($this, self::CMD_GET_TAXONOMY_OPTIONS_ASYNC, '', true)
283 );
284 $form->addItem($hiddenInputTaxSelectOptAsyncUrl);
285
286 if( $this->testOBJ->participantDataExist() )
287 {
288 $pool = new ilNonEditableValueGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_title');
289 $pool->setValue( $this->questionSetConfig->getSourceQuestionPoolSummaryString($this->lng, $this->tree) );
290 $pool->setDisabled(true);
291 $form->addItem($pool);
292 }
293 else
294 {
295 $poolInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_id');
296 $poolInput->setOptions($this->buildQuestionPoolSelectInputOptionArray(
297 $this->testOBJ->getAvailableQuestionpools(true, false, false, true, true)
298 ));
299 $poolInput->setValue( $sourceQuestionPoolId );
300 $poolInput->setRequired(true);
301 $form->addItem($poolInput);
302 }
303
304 $questionOderingInput = new ilRadioGroupInputGUI(
305 $this->lng->txt('tst_input_dynamic_question_set_question_ordering'), 'question_ordering'
306 );
307 $questionOderingInput->setValue( $this->questionSetConfig->getOrderingTaxonomyId() ?
308 self::QUESTION_ORDERING_TYPE_TAXONOMY : self::QUESTION_ORDERING_TYPE_UPDATE_DATE
309 );
310 $optionOrderByDate = new ilRadioOption(
311 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_date'),
312 self::QUESTION_ORDERING_TYPE_UPDATE_DATE,
313 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_date_desc')
314 );
315 $questionOderingInput->addOption($optionOrderByDate);
316 $optionOrderByTax = new ilRadioOption(
317 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_tax'),
318 self::QUESTION_ORDERING_TYPE_TAXONOMY,
319 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_tax_desc')
320 );
321 $orderTaxInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_ordering_tax'), 'ordering_tax');
322 $orderTaxInput->setInfo($this->lng->txt('tst_input_dynamic_question_set_ordering_tax_description'));
323 $orderTaxInput->setValue($this->questionSetConfig->getOrderingTaxonomyId());
324 $orderTaxInput->setRequired(true);
325 $orderTaxInput->setOptions($this->buildTaxonomySelectInputOptionArray( $sourceQuestionPoolId ));
326 $optionOrderByTax->addSubItem($orderTaxInput);
327 $questionOderingInput->addOption($optionOrderByTax);
328 $form->addItem($questionOderingInput);
329
330 $taxFilterInput = new ilCheckboxInputGUI($this->lng->txt('tst_input_dynamic_question_set_taxonomie_filter_enabled'), 'tax_filter_enabled');
331 $taxFilterInput->setValue(1);
332 $taxFilterInput->setChecked( $this->questionSetConfig->isTaxonomyFilterEnabled() );
333 $form->addItem($taxFilterInput);
334
335 $answStatusFilterInput = new ilCheckboxInputGUI(
336 $this->lng->txt('tst_input_dyn_quest_set_answer_status_filter_enabled'), 'answer_status_filter_enabled'
337 );
338 $answStatusFilterInput->setValue(1);
339 $answStatusFilterInput->setChecked( $this->questionSetConfig->isAnswerStatusFilterEnabled() );
340 $form->addItem($answStatusFilterInput);
341
342 $previousQuestionsListInput = new ilCheckboxInputGUI(
343 $this->lng->txt('tst_input_dyn_quest_set_prev_quest_list_enabled'), 'prev_quest_list_enabled'
344 );
345 $previousQuestionsListInput->setValue(1);
346 $previousQuestionsListInput->setChecked( $this->questionSetConfig->isPreviousQuestionsListEnabled() );
347 $form->addItem($previousQuestionsListInput);
348
349 if( $this->testOBJ->participantDataExist() )
350 {
351 $questionOderingInput->setDisabled(true);
352 $taxFilterInput->setDisabled(true);
353 $answStatusFilterInput->setDisabled(true);
354 $previousQuestionsListInput->setDisabled(true);
355 }
356 else
357 {
358 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
359 }
360
361 return $form;
362 }
363
370 private function buildQuestionPoolSelectInputOptionArray($questionPoolsData)
371 {
372 $questionPoolSelectInputOptions = array( '' => $this->lng->txt('please_select') );
373
374 foreach($questionPoolsData as $qplId => $qplData)
375 {
376 $questionPoolSelectInputOptions[$qplId] = $qplData['title'];
377 }
378
379 return $questionPoolSelectInputOptions;
380 }
381
382 private function buildTaxonomySelectInputOptionArray($questionPoolId)
383 {
384 $taxSelectOptions = array(
385 0 => $this->lng->txt('please_select')
386 );
387
388 if( $questionPoolId )
389 {
390 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
391
392 $taxIds = ilObjTaxonomy::getUsageOfObject($questionPoolId);
393
394 foreach($taxIds as $taxId)
395 {
396 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
397 }
398 }
399
400 return $taxSelectOptions;
401 }
402
403 private function buildTaxonomySelectInputOptionJson($questionPoolId)
404 {
405 $options = array();
406
407 foreach($this->buildTaxonomySelectInputOptionArray($questionPoolId) as $optValue => $optLabel)
408 {
409 $options[] = array('value' => $optValue, 'label' => $optLabel);
410 }
411
412 return json_encode($options);
413 }
414}
Class ilAccessHandler.
This class represents a checkbox property in a property form.
This class provides processing control methods.
Database Wrapper.
Definition: class.ilDB.php:29
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.
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilTabsGUI $tabs, ilLanguage $lng, ilTemplate $tpl, ilDB $db, ilTree $tree, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
Constructor.
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
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.
getItemByPostVar($a_post_var)
Get Item by POST variable.
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.
$_POST['username']
Definition: cron.php:12
exit
Definition: login.php:54
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options
$errors