ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.assFormulaQuestionGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
5include_once "./Modules/TestQuestionPool/classes/class.assFormulaQuestion.php";
6include_once "./Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php";
7include_once "./Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php";
8include_once "./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnit.php";
9include_once "./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnitCategory.php";
10include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
11require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
12
23{
30 function __construct($id = -1)
31 {
32 parent::__construct();
33 $this->object = new assFormulaQuestion();
34 $this->newUnitId = null;
35 if($id >= 0)
36 {
37 $this->object->loadFromDb($id);
38 }
39 }
40
46 function setQuestionTabs()
47 {
48 global $rbacsystem, $ilTabs;
49
50 $ilTabs->clearTargets();
51
52 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
53 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
54 $q_type = $this->object->getQuestionType();
55
56 if(strlen($q_type))
57 {
58 $classname = $q_type . "GUI";
59 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
60 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
61 }
62
63 if($_GET["q_id"])
64 {
65 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
66 {
67 // edit page
68 $ilTabs->addTarget("edit_page",
69 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
70 array("edit", "insert", "exec_pg"),
71 "", "", $force_active);
72 }
73
74 $this->addTab_QuestionPreview($ilTabs);
75 }
76
77 $force_active = false;
78 if($rbacsystem->checkAccess('write', $_GET["ref_id"]))
79 {
80 $url = "";
81
82 if($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
83 $commands = $_POST["cmd"];
84 if(is_array($commands))
85 {
86 foreach($commands as $key => $value)
87 {
88 if(preg_match("/^suggestrange_.*/", $key, $matches))
89 {
90 $force_active = true;
91 }
92 }
93 }
94 // edit question properties
95 $ilTabs->addTarget("edit_properties",
96 $url,
97 array(
98 "editQuestion", "save", "cancel", "addSuggestedSolution",
99 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
100 "parseQuestion", "saveEdit", "suggestRange"
101 ),
102 $classname, "", $force_active);
103 }
104
105 if($_GET["q_id"])
106 {
107 // add tab for question feedback within common class assQuestionGUI
108 $this->addTab_QuestionFeedback($ilTabs);
109 }
110
111 if($_GET["q_id"])
112 {
113 // add tab for question hint within common class assQuestionGUI
114 $this->addTab_QuestionHints($ilTabs);
115 }
116
117 // Unit editor
118 if($_GET['q_id'])
119 {
120 // add tab for question hint within common class assQuestionGUI
121 $this->addTab_Units($ilTabs);
122 }
123
124 // Assessment of questions sub menu entry
125 if($_GET["q_id"])
126 {
127 $ilTabs->addTarget("statistics",
128 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
129 array("assessment"),
130 $classname, "");
131 }
132
133 $this->addBackTab($ilTabs);
134 }
135
136 function getCommand($cmd)
137 {
138 if(preg_match("/suggestrange_(.*?)/", $cmd, $matches))
139 {
140 $cmd = "suggestRange";
141 }
142 return $cmd;
143 }
144
149 function suggestRange()
150 {
151 if($this->writePostData())
152 {
154 }
155 $this->editQuestion();
156 }
157
161 protected function writePostData($always = false)
162 {
163 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
164 $checked = true;
165 if(!$hasErrors)
166 {
167 $this->object->setTitle($_POST["title"]);
168 $this->object->setAuthor($_POST["author"]);
169 $this->object->setComment($_POST["comment"]);
170 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
171 $questiontext = ilUtil::stripOnlySlashes($_POST["question"]);
172 $this->object->setQuestion($questiontext);
173 $this->object->setEstimatedWorkingTime(
174 $_POST["Estimated"]["hh"],
175 $_POST["Estimated"]["mm"],
176 $_POST["Estimated"]["ss"]
177 );
178
179 $this->object->parseQuestionText();
180 $found_vars = array();
181 $found_results = array();
182
183
184 foreach($_POST as $key => $value)
185 {
186 if(preg_match("/^unit_(\\\$v\d+)$/", $key, $matches))
187 {
188 array_push($found_vars, $matches[1]);
189 }
190 if(preg_match("/^unit_(\\\$r\d+)$/", $key, $matches))
191 {
192 array_push($found_results, $matches[1]);
193 }
194 }
195
196// if(!$this->object->checkForDuplicateVariables())
197// {
198//
199// $this->addErrorMessage($this->lng->txt("err_duplicate_variables"));
200// $checked = FALSE;
201// }
202 if(!$this->object->checkForDuplicateResults())
203 {
204 $this->addErrorMessage($this->lng->txt("err_duplicate_results"));
205 $checked = FALSE;
206 }
207
208 foreach($found_vars as $variable)
209 {
210 if($this->object->getVariable($variable) != null)
211 {
212 $varObj = new assFormulaQuestionVariable($variable, $_POST["range_min_$variable"], $_POST["range_max_$variable"], $this->object->getUnitrepository()->getUnit($_POST["unit_$variable"]), $_POST["precision_$variable"], $_POST["intprecision_$variable"]);
213 $varObj->setRangeMinTxt($_POST["range_min_$variable"]);
214 $varObj->setRangeMaxTxt($_POST["range_max_$variable"]);
215 $this->object->addVariable($varObj);
216 }
217 }
218
219 $tmp_form_vars = array();
220 $tmp_quest_vars = array();
221 foreach($found_results as $result)
222 {
223 $tmp_res_match = preg_match_all("/([$][v][0-9]*)/", $_POST["formula_$result"], $form_vars);
224 $tmp_form_vars = array_merge($tmp_form_vars,$form_vars[0]);
225
226 $tmp_que_match = preg_match_all("/([$][v][0-9]*)/", $_POST['question'] , $quest_vars);
227 $tmp_quest_vars= array_merge($tmp_quest_vars,$quest_vars[0]);
228 }
229 $result_has_undefined_vars = array_diff($tmp_form_vars, $found_vars);
230 $question_has_unused_vars = array_diff($tmp_quest_vars, $tmp_form_vars);
231
232 if(count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0)
233 {
234 $error_message = '';
235 if(count($result_has_undefined_vars) > 0)
236 {
237 $error_message .= $this->lng->txt("res_contains_undef_var"). '<br>';
238 }
239 if(count($question_has_unused_vars) > 0)
240 {
241 $error_message .= $this->lng->txt("que_contains_unused_var");
242 }
243 $checked = false;
244 if($this->isSaveCommand())
245 {
246 ilUtil::sendFailure($error_message);
247 }
248 }
249 foreach($found_results as $result)
250 {
251 if(is_object($this->object->getUnitrepository()->getUnit($_POST["unit_$result"])))
252 {
253 $tmp_result_unit = $this->object->getUnitrepository()->getUnit($_POST["unit_$result"]);
254 }
255 else
256 {
257 $tmp_result_unit = NULL;
258 }
259
260 if($this->object->getResult($result) != null)
261 {
262 $use_simple_rating = ($_POST["rating_advanced_$result"] == 1) ? FALSE : TRUE;
263 $resObj = new assFormulaQuestionResult(
264 $result,
265 $_POST["range_min_$result"],
266 $_POST["range_max_$result"],
267 $_POST["tolerance_$result"],
268
269 $tmp_result_unit,
270 $_POST["formula_$result"],
271 $_POST["points_$result"],
272 $_POST["precision_$result"],
273 $use_simple_rating,
274 ($_POST["rating_advanced_$result"] == 1) ? $_POST["rating_sign_$result"] : "",
275 ($_POST["rating_advanced_$result"] == 1) ? $_POST["rating_value_$result"] : "",
276 ($_POST["rating_advanced_$result"] == 1) ? $_POST["rating_unit_$result"] : "",
277 $_POST["result_type_$result"] != 0 ? $_POST["result_type_$result"] : 0
278 );
279 $resObj->setRangeMinTxt($_POST["range_min_$result"]);
280 $resObj->setRangeMaxTxt($_POST["range_max_$result"]);
281 $this->object->addResult($resObj);
282 $this->object->addResultUnits($resObj, $_POST["units_$result"]);
283 }
284 }
285 if($checked == false)
286 {
287 return 1;
288 }
289 else
290 {
291 $this->resetSavedPreviewSession();
292 return 0;
293 }
294 }
295 else
296 {
297 return 1;
298 }
299 }
300
302 {
303 global $ilUser;
304 $user_id = $ilUser->getId();
305 $question_id = $this->object->getId();
306 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
307 $ilAssQuestionPreviewSession = new ilAssQuestionPreviewSession($user_id, $question_id);
308 $ilAssQuestionPreviewSession->setParticipantsSolution(array());
309 }
310
311 function isSaveCommand()
312 {
313 return in_array($this->ctrl->getCmd(), array('saveFQ', 'saveEdit', 'saveReturnFQ'));
314 }
315
321 public function editQuestion($checkonly = FALSE)
322 {
323 $save = $this->isSaveCommand();
324
325 $this->getQuestionTemplate();
326
327 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
328 $form = new ilPropertyFormGUI();
329 $this->editForm = $form;
330
331 $form->setFormAction($this->ctrl->getFormAction($this));
332 $form->setTitle($this->outQuestionType());
333 $form->setMultipart(FALSE);
334 $form->setTableWidth('100%');
335 $form->setId('assformulaquestion');
336
337 // title, author, description, question, working time (assessment mode)
338 $this->addBasicQuestionFormProperties($form);
339
340 // Add info text
341 $question = $form->getItemByPostVar('question');
342 $question->setInfo($this->lng->txt('fq_question_desc'));
343
344 $variables = $this->object->getVariables();
345 $categorized_units = $this->object->getUnitrepository()->getCategorizedUnits();
346 $result_units = $this->object->__get('resultunits');
347
348 $unit_options = array();
349 $category_name = '';
350 $new_category = false;
351 foreach((array)$categorized_units as $item)
352 {
356 if($item instanceof assFormulaQuestionUnitCategory)
357 {
358 if($category_name != $item->getDisplayString())
359 {
360 $new_category = true;
361 $category_name = $item->getDisplayString();
362 }
363 continue;
364 }
365 $unit_options[$item->getId()] = $item->getDisplayString() . ($new_category ? ' (' . $category_name . ')' : '');
366 $new_category = false;
367 }
368
369 if(count($variables))
370 {
371 uasort($variables, function(assFormulaQuestionVariable $v1, assFormulaQuestionVariable $v2) {
372 $num_v1 = (int)substr($v1->getVariable(), 2);
373 $num_v2 = (int)substr($v2->getVariable(), 2);
374 if($num_v1 > $num_v2)
375 {
376 return 1;
377 }
378 else if($num_v1 < $num_v2)
379 {
380 return -1;
381 }
382
383 return 0;
384 });
385
386 foreach($variables as $variable)
387 {
391 $variable_header = new ilFormSectionHeaderGUI();
392 $variable_header->setTitle(sprintf($this->lng->txt('variable_x'), $variable->getVariable()));
393
394 $range_min = new ilNumberInputGUI($this->lng->txt('range_min'), 'range_min_' . $variable->getVariable());
395 $range_min->allowDecimals(true);
396 $range_min->setSize(3);
397 $range_min->setRequired(true);
398 $range_min->setValue($variable->getRangeMin());
399
400 $range_max = new ilNumberInputGUI($this->lng->txt('range_max'), 'range_max_' . $variable->getVariable());
401 $range_max->allowDecimals(true);
402 $range_max->setSize(3);
403 $range_max->setRequired(true);
404 $range_max->setValue($variable->getRangeMax());
405
406 $units = new ilSelectInputGUI($this->lng->txt('unit'), 'unit_' . $variable->getVariable());
407 $units->setOptions(array(0 => $this->lng->txt('no_selection')) + $unit_options);
408 if(is_object($variable->getUnit()))
409 {
410 $units->setValue($variable->getUnit()->getId());
411 }
412
413 $precision = new ilNumberInputGUI($this->lng->txt('precision'), 'precision_' . $variable->getVariable());
414 $precision->setRequired(true);
415 $precision->setSize(3);
416 $precision->setMinValue(0);
417 $precision->setValue($variable->getPrecision());
418 $precision->setInfo($this->lng->txt('fq_precision_info'));
419
420 $intprecision = new ilNumberInputGUI($this->lng->txt('intprecision'), 'intprecision_' . $variable->getVariable());
421 $intprecision->setSize(3);
422 $intprecision->setMinValue(1);
423 $intprecision->setValue($variable->getIntprecision());
424 $intprecision->setInfo($this->lng->txt('intprecision_info'));
425
426 $form->addItem($variable_header);
427 $form->addItem($range_min);
428 $form->addItem($range_max);
429 $form->addItem($units);
430 $form->addItem($precision);
431 $form->addItem($intprecision);
432 }
433 }
434
435 $results = $this->object->getResults();
436 if(count($results))
437 {
438 require_once 'Services/Form/classes/class.ilMultiSelectInputGUI.php';
439
441 $num_r1 = (int)substr($r1->getResult(), 2);
442 $num_r2 = (int)substr($r2->getResult(), 2);
443 if($num_r1 > $num_r2)
444 {
445 return 1;
446 }
447 else if($num_r1 < $num_r2)
448 {
449 return -1;
450 }
451
452 return 0;
453 });
454
455 foreach($results as $result)
456 {
460 $result_header = new ilFormSectionHeaderGUI();
461 $result_header->setTitle(sprintf($this->lng->txt('result_x'), $result->getResult()));
462
463 $formula = new ilTextInputGUI($this->lng->txt('formula'), 'formula_' . $result->getResult());
464 $formula->setInfo($this->lng->txt('fq_formula_desc'));
465 $formula->setRequired(true);
466 $formula->setSize(50);
467 $formula->setValue($result->getFormula());
468 $formula->setSuffix(' = ' . $result->getResult());
469
470 if(
471 preg_match("/suggestrange_(.*)/", $this->ctrl->getCmd(), $matches) &&
472 strcmp($matches[1], $result->getResult()) == 0
473 )
474 {
475 // suggest a range for the result
476 if(strlen($result->substituteFormula($variables, $results)))
477 {
478 $result->suggestRange($variables, $results);
479 }
480 }
481
482 $range_min = new ilNumberInputGUI($this->lng->txt('range_min'), 'range_min_' . $result->getResult());
483 $range_min->allowDecimals(true);
484 $range_min->setSize(3);
485 $range_min->setRequired(true);
486 $range_min->setValue($result->getRangeMin());
487
488 $range_max = new ilNumberInputGUI($this->lng->txt('range_max'), 'range_max_' . $result->getResult());
489 $range_max->allowDecimals(true);
490 $range_max->setSize(3);
491 $range_max->setRequired(true);
492 $range_max->setValue($result->getRangeMax());
493
494 $matches = array();
495
496 $precision = new ilNumberInputGUI($this->lng->txt('precision'), 'precision_' . $result->getResult());
497 $precision->setRequired(true);
498 $precision->setSize(3);
499 $precision->setMinValue(0);
500 $precision->setInfo($this->lng->txt('fq_precision_info'));
501 $precision->setValue($result->getPrecision());
502
503 $tolerance = new ilNumberInputGUI($this->lng->txt('tolerance'), 'tolerance_' . $result->getResult());
504 $tolerance->setSize(3);
505 $tolerance->setMinValue(0);
506 $tolerance->setMaxValue(100);
507 $tolerance->allowDecimals(false);
508 $tolerance->setInfo($this->lng->txt('tolerance_info'));
509 $tolerance->setValue($result->getTolerance());
510
511 $suggest_range_button = new ilCustomInputGUI('', '');
512 $suggest_range_button->setHtml('<input type="submit" class="btn btn-default" name="cmd[suggestrange_'.$result->getResult().']" value="'.$this->lng->txt("suggest_range").'" />');
513
514 $sel_result_units = new ilSelectInputGUI($this->lng->txt('unit'), 'unit_' . $result->getResult());
515 $sel_result_units->setOptions(array(0 => $this->lng->txt('no_selection')) + $unit_options);
516 $sel_result_units->setInfo($this->lng->txt('result_unit_info'));
517 if(is_object($result->getUnit()))
518 {
519 $sel_result_units->setValue($result->getUnit()->getId());
520 }
521
522 $mc_result_units = new ilMultiSelectInputGUI($this->lng->txt('result_units'), 'units_' . $result->getResult());
523 $mc_result_units->setOptions($unit_options);
524 $mc_result_units->setInfo($this->lng->txt('result_units_info'));
525 $selectedvalues = array();
526 foreach($unit_options as $unit_id => $txt)
527 {
528 if($this->hasResultUnit($result, $unit_id, $result_units))
529 {
530 $selectedvalues[] = $unit_id;
531 }
532 }
533 $mc_result_units->setValue($selectedvalues);
534
535 $result_type = new ilRadioGroupInputGUI($this->lng->txt('result_type_selection'), 'result_type_' . $result->getResult());
536 $result_type->setRequired(true);
537
538 $no_type = new ilRadioOption($this->lng->txt('no_result_type'), 0);
539 $no_type->setInfo($this->lng->txt('fq_no_restriction_info'));
540
541 $result_dec = new ilRadioOption($this->lng->txt('result_dec'), 1);
542 $result_dec->setInfo($this->lng->txt('result_dec_info'));
543
544 $result_frac = new ilRadioOption($this->lng->txt('result_frac'), 2);
545 $result_frac->setInfo($this->lng->txt('result_frac_info'));
546
547 $result_co_frac = new ilRadioOption($this->lng->txt('result_co_frac'), 3);
548 $result_co_frac->setInfo($this->lng->txt('result_co_frac_info'));
549
550 $result_type->addOption($no_type);
551 $result_type->addOption($result_dec);
552 $result_type->addOption($result_frac);
553 $result_type->addOption($result_co_frac);
554 $result_type->setValue(strlen($result->getResultType()) ? $result->getResultType() : 0);
555
556 $points = new ilNumberInputGUI($this->lng->txt('points'), 'points_' . $result->getResult());
557 $points->allowDecimals(true);
558 $points->setRequired(true);
559 $points->setSize(3);
560 $points->setMinValue(0);
561 $points->setValue(strlen($result->getPoints()) ? $result->getPoints() : 1);
562
563 $rating_type = new ilCheckboxInputGUI($this->lng->txt('advanced_rating'), 'rating_advanced_' . $result->getResult());
564 $rating_type->setValue(1);
565 $rating_type->setInfo($this->lng->txt('advanced_rating_info'));
566
567 if(!$save)
568 {
569 $advanced_rating = $this->canUseAdvancedRating($result);
570 if(!$advanced_rating)
571 {
572 $rating_type->setDisabled(true);
573 $rating_type->setChecked(false);
574 }
575 else
576 {
577 $rating_type->setChecked(strlen($result->getRatingSimple()) && $result->getRatingSimple() ? false : true);
578 }
579 }
580
581 $sign = new ilNumberInputGUI($this->lng->txt('rating_sign'), 'rating_sign_' . $result->getResult());
582 $sign->setRequired(true);
583 $sign->setSize(3);
584 $sign->setMinValue(0);
585 $sign->setValue($result->getRatingSign());
586 $rating_type->addSubItem($sign);
587
588 $value = new ilNumberInputGUI($this->lng->txt('rating_value'), 'rating_value_' . $result->getResult());
589 $value->setRequired(true);
590 $value->setSize(3);
591 $value->setMinValue(0);
592 $value->setValue($result->getRatingValue());
593 $rating_type->addSubItem($value);
594
595 $unit = new ilNumberInputGUI($this->lng->txt('rating_unit'), 'rating_unit_' . $result->getResult());
596 $unit->setRequired(true);
597 $unit->setSize(3);
598 $unit->setMinValue(0);
599 $unit->setValue($result->getRatingUnit());
600 $rating_type->addSubItem($unit);
601
602 $info_text = new ilNonEditableValueGUI($this->lng->txt('additional_rating_info'));
603 $rating_type->addSubItem($info_text);
604
605 $form->addItem($result_header);
606 $form->addItem($formula);
607 $form->addItem($range_min);
608 $form->addItem($range_max);
609 $form->addItem($suggest_range_button);
610 $form->addItem($precision);
611 $form->addItem($tolerance);
612 $form->addItem($sel_result_units);
613 $form->addItem($mc_result_units);
614 $form->addItem($result_type);
615 $form->addItem($points);
616 $form->addItem($rating_type);
617 }
618
619 $defined_result_vars = array();
620 $quest_vars = array();
621
622 $defined_result_res = array();
623 $result_vars = array();
624
625 foreach($variables as $key => $object)
626 {
627 $quest_vars[$key] = $key;
628 }
629
630 foreach($results as $key => $object)
631 {
632 $result_vars[$key] = $key;
633 }
634
635 foreach($results as $tmp_result)
636 {
640 $formula = $tmp_result->getFormula();
641
642 preg_match_all("/([$][v][0-9]*)/", $formula, $form_vars);
643 preg_match_all("/([$][r][0-9]*)/", $formula, $form_res);
644 foreach($form_vars[0] as $res_var)
645 {
646 $defined_result_vars[$res_var] = $res_var;
647 }
648
649 foreach($form_res[0] as $res_res)
650 {
651 $defined_result_res[$res_res] = $res_res;
652 }
653 }
654 }
655
656 $result_has_undefined_vars = array();
657 $question_has_unused_vars = array();
658
659 if(is_array($quest_vars) && count($quest_vars) > 0)
660 {
661 $result_has_undefined_vars = array_diff($defined_result_vars, $quest_vars);
662 $question_has_unused_vars = array_diff($quest_vars, $defined_result_vars);
663 }
664
665 if(is_array($result_vars) && count($result_vars) > 0)
666 {
667 $result_has_undefined_res = array_diff($defined_result_res, $result_vars);
668
669 }
670 $error_message = '';
671
672 if(count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0)
673 {
674 if(count($result_has_undefined_vars) > 0)
675 {
676 $error_message .= $this->lng->txt("res_contains_undef_var"). '<br>';
677 }
678 if(count($question_has_unused_vars) > 0)
679 {
680 $error_message .= $this->lng->txt("que_contains_unused_var"). '<br>';
681 }
682
683 $checked = false;
684 if($save)
685 {
686 ilUtil::sendFailure($error_message);
687 }
688 }
689
690 if(count($result_has_undefined_res) > 0)
691 {
692 $error_message .= $this->lng->txt("res_contains_undef_res"). '<br>';
693 $checked = false;
694 }
695
696 if($save && !$checked)
697 {
698 ilUtil::sendFailure($error_message);
699 }
700
701 if($this->object->getId())
702 {
703 $hidden = new ilHiddenInputGUI("", "ID");
704 $hidden->setValue($this->object->getId());
705 $form->addItem($hidden);
706 }
707
708 $this->populateTaxonomyFormSection($form);
709
710 $form->addCommandButton('parseQuestion', $this->lng->txt("parseQuestion"));
711 $form->addCommandButton('saveReturnFQ', $this->lng->txt("save_return"));
712 $form->addCommandButton('saveFQ', $this->lng->txt("save"));
713
714 $errors = $checked;
715
716 if($save)
717 {
718 $found_vars = array();
719 $found_results = array();
720 foreach((array)$_POST as $key => $value)
721 {
722 if(preg_match("/^unit_(\\\$v\d+)$/", $key, $matches))
723 {
724 array_push($found_vars, $matches[1]);
725 }
726 if(preg_match("/^unit_(\\\$r\d+)$/", $key, $matches))
727 {
728 array_push($found_results, $matches[1]);
729 }
730 }
731
732 $form->setValuesByPost();
733 $errors = !$form->checkInput();
734
735 $custom_errors = false;
736 if(count($variables))
737 {
738 foreach($variables as $variable)
739 {
743 $min_range = $form->getItemByPostVar('range_min_' . $variable->getVariable());
744 $max_range = $form->getItemByPostVar('range_max_' . $variable->getVariable());
745 if($min_range->getValue() > $max_range->getValue())
746 {
747 $min_range->setAlert($this->lng->txt('err_range'));
748 $max_range->setAlert($this->lng->txt('err_range'));
749 $custom_errors = true;
750 }
751 }
752 }
753
754 if(count($results))
755 {
756 foreach($results as $result)
757 {
761 $min_range = $form->getItemByPostVar('range_min_' . $result->getResult());
762 $max_range = $form->getItemByPostVar('range_max_' . $result->getResult());
763 if($min_range->getValue() > $max_range->getValue())
764 {
765 $min_range->setAlert($this->lng->txt('err_range'));
766 $max_range->setAlert($this->lng->txt('err_range'));
767 $custom_errors = true;
768 }
769
770
771 $formula = $form->getItemByPostVar('formula_' . $result->getResult());
772 if(strpos($formula->getValue(), $result->getResult()) !== FALSE)
773 {
774 $formula->setAlert($this->lng->txt('errRecursionInResult'));
775 $custom_errors = true;
776 }
777
778 $result_unit = $form->getItemByPostVar('unit_' . $result->getResult());
779 $rating_advanced = $form->getItemByPostVar('rating_advanced_' . $result->getResult());
780 if(((int)$result_unit->getValue() <= 0) && $rating_advanced->getChecked())
781 {
782 unset($_POST['rating_advanced_' . $result->getResult()]);
783 $rating_advanced->setDisabled(true);
784 $rating_advanced->setChecked(false);
785 $rating_advanced->setAlert($this->lng->txt('err_rating_advanced_not_allowed'));
786 $custom_errors = true;
787 }
788 else if($rating_advanced->getChecked())
789 {
790 $rating_sign = $form->getItemByPostVar('rating_sign_' . $result->getResult());
791 $rating_value = $form->getItemByPostVar('rating_value_' . $result->getResult());
792 $rating_unit = $form->getItemByPostVar('rating_unit_' . $result->getResult());
793
794 $percentage = $rating_sign->getValue() + $rating_value->getValue() + $rating_unit->getValue();
795 if($percentage != 100)
796 {
797 $rating_advanced->setAlert($this->lng->txt('err_wrong_rating_advanced'));
798 $custom_errors = true;
799 }
800 }
801
802 preg_match_all("/([$][v][0-9]*)/", $formula->getValue(), $form_vars);
803 $result_has_undefined_vars = array_diff($form_vars[0], (array)$found_vars);
804 if(count($result_has_undefined_vars))
805 {
806 $errors = true;
807 ilUtil::sendInfo($this->lng->txt('res_contains_undef_var'));
808 }
809 }
810 }
811
812 if($custom_errors && !$errors)
813 {
814 $errors = true;
815 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
816 }
817 $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
818 if($errors)
819 {
820 $checkonly = false;
821 }
822 }
823
824 if(!$checkonly)
825 {
826 $this->tpl->setVariable('QUESTION_DATA', $form->getHTML());
827 }
828 return $errors;
829 }
830
831 private function hasResultUnit($result, $unit_id, $resultunits)
832 {
833 if (array_key_exists($result->getResult(), $resultunits))
834 {
835 if (array_key_exists($unit_id, $resultunits[$result->getResult()])) return TRUE;
836 }
837 return FALSE;
838 }
839
848 {
849 $resultunit = $result->getUnit();
850
851 /*
852 * if there is a result-unit (unit selectbox) selected it is possible to use advanced rating
853 * if there is no result-unit selected it is NOT possible to use advanced rating, because there is no
854 * definition if the result-value or the unit-value should be the correct solution!!
855 *
856 */
857 if(is_object($resultunit))
858 {
859 return true;
860 }
861 else
862 {
863 return false;
864 }
865 }
866
867 public function parseQuestion()
868 {
869 $this->writePostData();
870 $this->editQuestion();
871 }
872
873 public function saveReturnFQ()
874 {
875 global $ilUser;
876 $old_id = $_GET["q_id"];
877 $result = $this->writePostData();
878 if ($result == 0)
879 {
880 $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
881 $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
883 $this->object->saveToDb();
884 $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
885 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
886 if (($_GET["calling_test"] || (isset($_GET['calling_consumer']) && (int)$_GET['calling_consumer'])) && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
887 {
888 $this->ctrl->redirect($this, "originalSyncForm");
889 return;
890 }
891 elseif ($_GET["calling_test"])
892 {
893 require_once 'Modules/Test/classes/class.ilObjTest.php';
894 $test = new ilObjTest($_GET["calling_test"]);
895 #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()));
896 $q_id = $this->object->getId();
897 if(!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()))
898 {
899 global $tree, $ilDB, $ilPluginAdmin;
900
901 include_once("./Modules/Test/classes/class.ilObjTest.php");
902 $_GET["ref_id"] = $_GET["calling_test"];
903 $test = new ilObjTest($_GET["calling_test"], true);
904
905 require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
906 $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
907
908 $new_id = $test->insertQuestion(
909 $testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId()
910 );
911
912 $q_id = $new_id;
913 if(isset($_REQUEST['prev_qid']))
914 {
915 $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']);
916 }
917
918 $this->ctrl->setParameter($this, 'q_id', $new_id);
919 $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']);
920 #$this->ctrl->setParameter($this, 'test_ref_id', false);
921
922 }
923 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
924 if($_REQUEST['test_express_mode'])
925 {
927 }
928 else
929 {
930 ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=" . $_GET["calling_test"]);
931 }
932 }
933 else
934 {
935 if ($this->object->getId() != $old_id)
936 {
937 $this->callNewIdListeners($this->object->getId());
938 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
939 $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
940 }
941 if (strcmp($_SESSION["info"], "") != 0)
942 {
943 ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
944 }
945 else
946 {
947 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
948 }
949 $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
950 }
951 }
952 else
953 {
954 $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
955 $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
956 $this->object->saveToDb();
957 $this->editQuestion();
958 }
959 }
960
961 public function saveFQ()
962 {
963 $result = $this->writePostData();
964
965 if($result == 1)
966 {
967 $this->editQuestion();
968 }
969 else
970 {
972 $this->save();
973 }
974 }
978 function checkInput()
979 {
980 if((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
981 {
982 $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
983 return FALSE;
984 }
985
986
987 return TRUE;
988 }
989
1003 $active_id,
1004 $pass = NULL,
1005 $graphicalOutput = FALSE,
1006 $result_output = FALSE,
1007 $show_question_only = TRUE,
1008 $show_feedback = FALSE,
1009 $show_correct_solution = FALSE,
1010 $show_manual_scoring = FALSE,
1011 $show_question_text = TRUE
1012 )
1013 {
1014 // get the solution of the user for the active pass or from the last pass if allowed
1015 $user_solution = array();
1016 if(($active_id > 0) && (!$show_correct_solution))
1017 {
1018 $solutions = array();
1019 include_once "./Modules/Test/classes/class.ilObjTest.php";
1020 if(!ilObjTest::_getUsePreviousAnswers($active_id, true))
1021 {
1022 if(is_null($pass)) $pass = ilObjTest::_getPass($active_id);
1023 }
1024 $user_solution["active_id"] = $active_id;
1025 $user_solution["pass"] = $pass;
1026 $solutions =& $this->object->getSolutionValues($active_id, $pass);
1027 foreach($solutions as $idx => $solution_value)
1028 {
1029 if(preg_match("/^(\\\$v\\d+)$/", $solution_value["value1"], $matches))
1030 {
1031 $user_solution[$matches[1]] = $solution_value["value2"];
1032 }
1033 else if(preg_match("/^(\\\$r\\d+)$/", $solution_value["value1"], $matches))
1034 {
1035 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1036 $user_solution[$matches[1]]["value"] = $solution_value["value2"];
1037 }
1038 else if(preg_match("/^(\\\$r\\d+)_unit$/", $solution_value["value1"], $matches))
1039 {
1040 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1041 $user_solution[$matches[1]]["unit"] = $solution_value["value2"];
1042 }
1043 }
1044 }
1045 else if($active_id)
1046 {
1047 $solutions = NULL;
1048 include_once "./Modules/Test/classes/class.ilObjTest.php";
1049 if(!ilObjTest::_getUsePreviousAnswers($active_id, true))
1050 {
1051 if(is_null($pass)) $pass = ilObjTest::_getPass($active_id);
1052 }
1053 $user_solution = (array)$this->object->getBestSolution($this->object->getSolutionValues($active_id, $pass));
1054 }
1055 elseif( is_object($this->getPreviewSession()) )
1056 {
1057 $solutionValues = array();
1058
1059 foreach($this->getPreviewSession()->getParticipantsSolution() as $val1 => $val2)
1060 {
1061 $solutionValues[] = array('value1' => $val1, 'value2' => $val2);
1062 }
1063
1064 $user_solution = (array)$this->object->getBestSolution($solutionValues);
1065 }
1066
1067 $template = new ilTemplate("tpl.il_as_qpl_formulaquestion_output_solution.html", true, true, 'Modules/TestQuestionPool');
1068 $questiontext = $this->object->substituteVariables($user_solution, $graphicalOutput, TRUE, $result_output);
1069
1070 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1071 $questionoutput = $template->get();
1072 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
1073 $feedback = ($show_feedback) ? $this->getGenericFeedbackOutput($active_id, $pass) : "";
1074 if (strlen($feedback))
1075 {
1076 $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
1078 );
1079
1080 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
1081 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
1082 }
1083 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
1084
1085 $solutionoutput = $solutiontemplate->get();
1086 if(!$show_question_only)
1087 {
1088 // get page object output
1089 $solutionoutput = $this->getILIASPage($solutionoutput);
1090 }
1091 return $solutionoutput;
1092 }
1093
1094 function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
1095 {
1096 $user_solution = array();
1097
1098 if( is_object($this->getPreviewSession()) )
1099 {
1100 $solutions = (array)$this->getPreviewSession()->getParticipantsSolution();
1101
1102 foreach($solutions as $val1 => $val2)
1103 {
1104 if(preg_match("/^(\\\$v\\d+)$/", $val1, $matches))
1105 {
1106 $user_solution[$matches[1]] = $val2;
1107 }
1108 else if(preg_match("/^(\\\$r\\d+)$/", $val1, $matches))
1109 {
1110
1111 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1112 $user_solution[$matches[1]]["value"] = $val2;
1113 }
1114 else if(preg_match("/^(\\\$r\\d+)_unit$/", $val1, $matches))
1115 {
1116 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1117 $user_solution[$matches[1]]["unit"] = $val2;
1118 }
1119
1120 if(preg_match("/^(\\\$r\\d+)/", $val1, $matches) && $user_solution[$matches[1]]["result_type"] == 0)
1121 {
1122 $user_solution[$matches[1]]["result_type"] = assFormulaQuestionResult::getResultTypeByQstId($this->object->getId(), $val1);
1123 }
1124 }
1125 }
1126
1127 if( !$this->object->hasRequiredVariableSolutionValues($user_solution) )
1128 {
1129 $user_solution = $this->object->getInitialVariableSolutionValues();
1130
1131 if( is_object($this->getPreviewSession()) )
1132 {
1133 $this->getPreviewSession()->setParticipantsSolution($user_solution);
1134 }
1135 }
1136
1137 $template = new ilTemplate("tpl.il_as_qpl_formulaquestion_output.html", true, true, 'Modules/TestQuestionPool');
1138 if( is_object($this->getPreviewSession()) )
1139 {
1140 $questiontext = $this->object->substituteVariables($user_solution, false, false, false);
1141 }
1142 else
1143 {
1144 $questiontext = $this->object->substituteVariables(array());
1145 }
1146 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1147 $questionoutput = $template->get();
1148 if(!$show_question_only)
1149 {
1150 // get page object output
1151 $questionoutput = $this->getILIASPage($questionoutput);
1152 }
1153 return $questionoutput;
1154 }
1155
1156 // hey: prevPassSolutions - pass will be always available from now on
1157 function getTestOutput($active_id, $pass, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
1158 // hey.
1159 {
1160 ilUtil::sendInfo($this->lng->txt('enter_valid_values'));
1161 // get the solution of the user for the active pass or from the last pass if allowed
1162 $user_solution = array();
1163 if($active_id)
1164 {
1165 $solutions = (array)$this->object->getTestOutputSolutions($active_id, $pass);
1166
1167 $actualPassIndex = null;
1168 if( $this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled() )
1169 {
1170 require_once 'Modules/Test/classes/class.ilObjTest.php';
1171 $actualPassIndex = ilObjTest::_getPass($active_id);
1172 }
1173
1174 foreach($solutions as $idx => $solution_value)
1175 {
1176 if(preg_match("/^(\\\$v\\d+)$/", $solution_value["value1"], $matches))
1177 {
1178 if( $this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled() )
1179 {
1180 $this->object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value["value2"], true);
1181 }
1182
1183 $user_solution[$matches[1]] = $solution_value["value2"];
1184 }
1185 else if(preg_match("/^(\\\$r\\d+)$/", $solution_value["value1"], $matches))
1186 {
1187
1188 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1189 $user_solution[$matches[1]]["value"] = $solution_value["value2"];
1190 }
1191 else if(preg_match("/^(\\\$r\\d+)_unit$/", $solution_value["value1"], $matches))
1192 {
1193 if(!array_key_exists($matches[1], $user_solution)) $user_solution[$matches[1]] = array();
1194 $user_solution[$matches[1]]["unit"] = $solution_value["value2"];
1195 }
1196
1197 if(preg_match("/^(\\\$r\\d+)/", $solution_value["value1"], $matches) && $user_solution[$matches[1]]["result_type"] == 0)
1198 {
1199 $user_solution[$matches[1]]["result_type"] = assFormulaQuestionResult::getResultTypeByQstId($this->object->getId(), $solution_value["value1"]);
1200 }
1201 }
1202 }
1203
1204// fau: testNav - take question variables always from authorized solution because they are saved with this flag, even if an authorized solution is not saved
1205 $solutions = $this->object->getSolutionValues($active_id, $pass, true);
1206 foreach($solutions as $idx => $solution_value)
1207 {
1208 if (preg_match("/^(\\\$v\\d+)$/", $solution_value["value1"], $matches))
1209 {
1210 $user_solution[$matches[1]] = $solution_value["value2"];
1211 }
1212 }
1213// fau.
1214
1215 if( !$this->object->hasRequiredVariableSolutionValues($user_solution) )
1216 {
1217 foreach($this->object->getInitialVariableSolutionValues() as $val1 => $val2)
1218 {
1219 $this->object->saveCurrentSolution($active_id, $pass, $val1, $val2, true);
1220 }
1221 }
1222
1223 // generate the question output
1224 $template = new ilTemplate("tpl.il_as_qpl_formulaquestion_output.html", true, true, 'Modules/TestQuestionPool');
1225
1226 $questiontext = $this->object->substituteVariables($user_solution);
1227
1228 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1229
1230 $questionoutput = $template->get();
1231 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1232 return $pageoutput;
1233 }
1234
1235 public function getSpecificFeedbackOutput($active_id, $pass)
1236 {
1237 return '';
1238 }
1239}
sprintf('%.4f', $callTime)
$result
$test
Definition: Utf8Test.php:84
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Single choice question GUI representation The assFormulaQuestionGUI class encapsulates the GUI repres...
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
canUseAdvancedRating($result)
Check if advanced rating can be used for a result.
hasResultUnit($result, $unit_id, $resultunits)
suggestRange()
Suggest a range for a result @access public.
setQuestionTabs()
Sets the ILIAS tabs for this question type Sets the ILIAS tabs for this question type @access public.
getSolutionOutput( $active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE, $show_feedback=FALSE, $show_correct_solution=FALSE, $show_manual_scoring=FALSE, $show_question_text=TRUE)
Get the question solution output.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
getTestOutput($active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
__construct($id=-1)
assFormulaQuestionGUI constructor The constructor takes possible arguments an creates an instance of ...
writePostData($always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
static getResultTypeByQstId($a_qst_id, $a_result)
Class for single choice questions assFormulaQuestion is a class for single choice questions.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
callNewIdListeners($a_new_id)
Call the new id listeners.
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
addErrorMessage($errormessage)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
static _questionExistsInTest($question_id, $test_id)
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a multi selection list property in a property form.
This class represents a non editable value in a property form.
This class represents a number property in a property form.
static _getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
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.
special template class to simplify handling of ITX/PEAR
static getReturnToPageLink($q_id=null)
This class represents a text property in a property form.
static stripOnlySlashes($a_str)
strip slashes if magic qoutes is enabled
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
http redirect to other script
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$txt
Definition: error.php:12
$cmd
Definition: sahs_server.php:35
$results
$url
Definition: shib_logout.php:72
global $ilDB
$errors
$ilUser
Definition: imgupload.php:18