ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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->saveToDb( $this->testOBJ->getTestId() );
255 }
256
263 private function buildForm($sourceQuestionPoolId)
264 {
265 $this->questionSetConfig->loadFromDb( $this->testOBJ->getTestId() );
266
267 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
268 $form = new ilPropertyFormGUI();
269
270 $form->setFormAction($this->ctrl->getFormAction($this));
271
272 $form->setId("tst_form_dynamic_question_set_config");
273 $form->setTitle($this->lng->txt('tst_form_dynamic_question_set_config'));
274 $form->setTableWidth("100%");
275
276 $hiddenInputTaxSelectOptAsyncUrl = new ilHiddenInputGUI('taxSelectOptAsyncUrl');
277 $hiddenInputTaxSelectOptAsyncUrl->setValue(
278 $this->ctrl->getLinkTarget($this, self::CMD_GET_TAXONOMY_OPTIONS_ASYNC, '', true)
279 );
280 $form->addItem($hiddenInputTaxSelectOptAsyncUrl);
281
282 if( $this->testOBJ->participantDataExist() )
283 {
284 $pool = new ilNonEditableValueGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_title');
285 $pool->setValue( $this->questionSetConfig->getSourceQuestionPoolSummaryString($this->lng, $this->tree) );
286 $pool->setDisabled(true);
287 $form->addItem($pool);
288 }
289 else
290 {
291 $poolInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_source_questionpool'), 'source_qpl_id');
292 $poolInput->setOptions($this->buildQuestionPoolSelectInputOptionArray(
293 $this->testOBJ->getAvailableQuestionpools(true, false, false, true, true)
294 ));
295 $poolInput->setValue( $sourceQuestionPoolId );
296 $poolInput->setRequired(true);
297 $form->addItem($poolInput);
298 }
299
300 $questionOderingInput = new ilRadioGroupInputGUI(
301 $this->lng->txt('tst_input_dynamic_question_set_question_ordering'), 'question_ordering'
302 );
303 $questionOderingInput->setValue( $this->questionSetConfig->getOrderingTaxonomyId() ?
304 self::QUESTION_ORDERING_TYPE_TAXONOMY : self::QUESTION_ORDERING_TYPE_UPDATE_DATE
305 );
306 $optionOrderByDate = new ilRadioOption(
307 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_date'),
308 self::QUESTION_ORDERING_TYPE_UPDATE_DATE,
309 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_date_desc')
310 );
311 $questionOderingInput->addOption($optionOrderByDate);
312 $optionOrderByTax = new ilRadioOption(
313 $this->lng->txt('tst_input_dynamic_question_set_question_ordering_by_tax'),
314 self::QUESTION_ORDERING_TYPE_TAXONOMY,
315 $this->lng->txt('tst_inp_dyn_quest_set_quest_ordering_by_tax_desc')
316 );
317 $orderTaxInput = new ilSelectInputGUI($this->lng->txt('tst_input_dynamic_question_set_ordering_tax'), 'ordering_tax');
318 $orderTaxInput->setInfo($this->lng->txt('tst_input_dynamic_question_set_ordering_tax_description'));
319 $orderTaxInput->setValue($this->questionSetConfig->getOrderingTaxonomyId());
320 $orderTaxInput->setRequired(true);
321 $orderTaxInput->setOptions($this->buildTaxonomySelectInputOptionArray( $sourceQuestionPoolId ));
322 $optionOrderByTax->addSubItem($orderTaxInput);
323 $questionOderingInput->addOption($optionOrderByTax);
324 $form->addItem($questionOderingInput);
325
326 $taxFilterInput = new ilCheckboxInputGUI($this->lng->txt('tst_input_dynamic_question_set_taxonomie_filter_enabled'), 'tax_filter_enabled');
327 $taxFilterInput->setValue(1);
328 $taxFilterInput->setChecked( $this->questionSetConfig->isTaxonomyFilterEnabled() );
329 $form->addItem($taxFilterInput);
330
331 $answStatusFilterInput = new ilCheckboxInputGUI(
332 $this->lng->txt('tst_input_dyn_quest_set_answer_status_filter_enabled'), 'answer_status_filter_enabled'
333 );
334 $answStatusFilterInput->setValue(1);
335 $answStatusFilterInput->setChecked( $this->questionSetConfig->isAnswerStatusFilterEnabled() );
336 $form->addItem($answStatusFilterInput);
337
338 if( $this->testOBJ->participantDataExist() )
339 {
340 $questionOderingInput->setDisabled(true);
341 $taxFilterInput->setDisabled(true);
342 $answStatusFilterInput->setDisabled(true);
343 }
344 else
345 {
346 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
347 }
348
349 return $form;
350 }
351
358 private function buildQuestionPoolSelectInputOptionArray($questionPoolsData)
359 {
360 $questionPoolSelectInputOptions = array( '' => $this->lng->txt('please_select') );
361
362 foreach($questionPoolsData as $qplId => $qplData)
363 {
364 $questionPoolSelectInputOptions[$qplId] = $qplData['title'];
365 }
366
367 return $questionPoolSelectInputOptions;
368 }
369
370 private function buildTaxonomySelectInputOptionArray($questionPoolId)
371 {
372 $taxSelectOptions = array(
373 0 => $this->lng->txt('please_select')
374 );
375
376 if( $questionPoolId )
377 {
378 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
379
380 $taxIds = ilObjTaxonomy::getUsageOfObject($questionPoolId);
381
382 foreach($taxIds as $taxId)
383 {
384 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
385 }
386 }
387
388 return $taxSelectOptions;
389 }
390
391 private function buildTaxonomySelectInputOptionJson($questionPoolId)
392 {
393 $options = array();
394
395 foreach($this->buildTaxonomySelectInputOptionArray($questionPoolId) as $optValue => $optLabel)
396 {
397 $options[] = array('value' => $optValue, 'label' => $optLabel);
398 }
399
400 return json_encode($options);
401 }
402}
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
$errors
if(!is_array($argv)) $options