19 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
45 $this->
object->loadFromDb(
$id);
51 $ilTabs->
addTarget(
'units', $this->
ctrl->getLinkTargetByClass(
'ilLocalUnitConfigurationGUI',
''),
'',
'illocalunitconfigurationgui');
56 if (preg_match(
'/suggestrange_(\$r\d+)/', $cmd, $matches)) {
62 public function suggestRange(
string $suggest_range_for_result): void
67 $this->editQuestion(
false, $suggest_range_for_result);
75 $hasErrors = (!$always) ? $this->editQuestion(
true) :
false;
78 $this->
object->setTitle($_POST[
"title"]);
79 $this->
object->setAuthor($_POST[
"author"]);
80 $this->
object->setComment($_POST[
"comment"]);
81 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
83 $this->
object->setQuestion($questiontext);
85 $this->
object->parseQuestionText();
86 $found_vars = array();
87 $found_results = array();
89 foreach ($this->request->getParsedBody() as
$key => $value) {
90 if (preg_match(
"/^unit_(\\\$v\d+)$/", $key, $matches)) {
91 array_push($found_vars, $matches[1]);
93 if (preg_match(
"/^unit_(\\\$r\d+)$/", $key, $matches)) {
94 array_push($found_results, $matches[1]);
100 $this->
object->setLifecycle($lifecycle);
104 if (!$this->
object->checkForDuplicateResults()) {
109 foreach ($found_vars as $variable) {
110 if ($this->
object->getVariable($variable) != null) {
113 $_POST[
"range_min_$variable"],
114 $_POST[
"range_max_$variable"],
115 isset($_POST[
"unit_$variable"]) ? $this->
object->getUnitrepository()->getUnit(
116 $_POST[
"unit_$variable"]
118 $_POST[
"precision_$variable"],
119 $_POST[
"intprecision_$variable"]
122 $varObj->setRangeMaxTxt($_POST[
"range_max_$variable"]);
123 $this->
object->addVariable($varObj);
127 $tmp_form_vars = array();
128 $tmp_quest_vars = array();
129 foreach ($found_results as $result) {
130 $tmp_res_match = preg_match_all(
"/([$][v][0-9]*)/", $_POST[
"formula_$result"], $form_vars);
131 $tmp_form_vars = array_merge($tmp_form_vars, $form_vars[0]);
133 $tmp_que_match = preg_match_all(
"/([$][v][0-9]*)/", $_POST[
'question'], $quest_vars);
134 $tmp_quest_vars = array_merge($tmp_quest_vars, $quest_vars[0]);
136 $result_has_undefined_vars = array_diff($tmp_form_vars, $found_vars);
137 $question_has_unused_vars = array_diff($tmp_quest_vars, $tmp_form_vars);
139 if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
141 if (count($result_has_undefined_vars) > 0) {
142 $error_message .= $this->
lng->txt(
"res_contains_undef_var") .
'<br>';
144 if (count($question_has_unused_vars) > 0) {
145 $error_message .= $this->
lng->txt(
"que_contains_unused_var");
149 $this->tpl->setOnScreenMessage(
'failure', $error_message);
152 foreach ($found_results as $result) {
153 if (is_object($this->
object->getUnitrepository()->getUnit($_POST[
"unit_$result"]))) {
154 $tmp_result_unit = $this->
object->getUnitrepository()->getUnit($_POST[
"unit_$result"]);
156 $tmp_result_unit = null;
159 if ($this->
object->getResult($result) != null) {
160 $use_simple_rating = $this->request->int(
"rating_advanced_$result") !== 1;
163 $_POST[
"range_min_$result"],
164 $_POST[
"range_max_$result"],
165 str_replace(
',',
'.', $_POST[
"tolerance_$result"]),
167 $_POST[
"formula_$result"],
168 $_POST[
"points_$result"],
169 $_POST[
"precision_$result"],
171 $this->request->int(
"rating_advanced_$result") === 1 ? $_POST[
"rating_sign_$result"] :
"",
172 $this->request->int(
"rating_advanced_$result") === 1 ? $_POST[
"rating_value_$result"] :
"",
173 $this->request->int(
"rating_advanced_$result") === 1 ? $_POST[
"rating_unit_$result"] :
"",
174 $this->request->int(
"result_type_$result")
177 $resObj->setRangeMaxTxt($_POST[
"range_max_$result"]);
178 $this->
object->addResult($resObj);
179 if (isset($_POST[
"units_$result"]) && is_array($_POST[
"units_$result"])) {
180 $this->
object->addResultUnits($resObj, $_POST[
"units_$result"]);
184 if ($checked ==
false) {
200 $question_id = $this->
object->getId();
201 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
203 $ilAssQuestionPreviewSession->setParticipantsSolution(array());
208 return in_array($this->
ctrl->getCmd(), array(
'saveFQ',
'saveEdit',
'saveReturnFQ'));
214 public function editQuestion($checkonly =
false,
string $suggest_range_for_result =
''):
bool 221 $this->editForm = $form;
223 $form->setFormAction($this->
ctrl->getFormAction($this));
225 $form->setMultipart(
false);
226 $form->setTableWidth(
'100%');
227 $form->setId(
'assformulaquestion');
232 $question = $form->getItemByPostVar(
'question');
233 $question->setInfo($this->
lng->txt(
'fq_question_desc'));
235 $variables = $this->
object->getVariables();
236 $categorized_units = $this->
object->getUnitrepository()->getCategorizedUnits();
237 $result_units = $this->
object->getAllResultUnits();
239 $unit_options = array();
241 $new_category =
false;
242 foreach ($categorized_units as $item) {
247 if ($category_name != $item->getDisplayString()) {
248 $new_category =
true;
249 $category_name = $item->getDisplayString();
253 $unit_options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
254 $new_category =
false;
257 if (count($variables)) {
261 if ($num_v1 > $num_v2) {
263 } elseif ($num_v1 < $num_v2) {
270 foreach ($variables as $variable) {
275 $variable_header->setTitle(sprintf($this->
lng->txt(
'variable_x'), $variable->getVariable()));
277 $range_min =
new ilNumberInputGUI($this->
lng->txt(
'range_min'),
'range_min_' . $variable->getVariable());
279 $range_min->setSize(3);
280 $range_min->setRequired(
true);
281 $range_min->setValue($variable->getRangeMin());
283 $range_max =
new ilNumberInputGUI($this->
lng->txt(
'range_max'),
'range_max_' . $variable->getVariable());
285 $range_max->setSize(3);
286 $range_max->setRequired(
true);
287 $range_max->setValue($variable->getRangeMax());
289 $units =
new ilSelectInputGUI($this->
lng->txt(
'unit'),
'unit_' . $variable->getVariable());
290 $units->setOptions(array(0 => $this->
lng->txt(
'no_selection')) + $unit_options);
291 if (is_object($variable->getUnit())) {
292 $units->setValue($variable->getUnit()->getId());
295 $precision =
new ilNumberInputGUI($this->
lng->txt(
'precision'),
'precision_' . $variable->getVariable());
297 $precision->setSize(3);
298 $precision->setMinValue(0);
299 $precision->setValue($variable->getPrecision());
300 $precision->setInfo($this->
lng->txt(
'fq_precision_info'));
302 $intprecision =
new ilNumberInputGUI($this->
lng->txt(
'intprecision'),
'intprecision_' . $variable->getVariable());
304 $intprecision->setMinValue(1);
305 $intprecision->setValue($variable->getIntprecision());
306 $intprecision->setInfo($this->
lng->txt(
'intprecision_info'));
308 $form->addItem($variable_header);
309 $form->addItem($range_min);
310 $form->addItem($range_max);
311 $form->addItem($units);
312 $form->addItem($precision);
313 $form->addItem($intprecision);
316 $quest_vars = array();
317 $result_vars = array();
318 $results = $this->
object->getResults();
323 if ($num_r1 > $num_r2) {
325 } elseif ($num_r1 < $num_r2) {
337 $result_header->setTitle(sprintf($this->
lng->txt(
'result_x'), $result->getResult()));
339 $formula =
new ilTextInputGUI($this->
lng->txt(
'formula'),
'formula_' . $result->getResult());
340 $formula->setInfo($this->
lng->txt(
'fq_formula_desc'));
341 $formula->setRequired(
true);
342 $formula->setSize(50);
343 $formula->setValue($result->getFormula());
344 $formula->setSuffix(
' = ' . $result->getResult());
347 $suggest_range_for_result !==
'' &&
348 strcmp($suggest_range_for_result, $result->getResult()) == 0 &&
349 strlen($result->substituteFormula($variables,
$results))
351 $result->suggestRange($variables,
$results);
354 $range_min =
new ilNumberInputGUI($this->
lng->txt(
'range_min'),
'range_min_' . $result->getResult());
356 $range_min->setSize(3);
357 $range_min->setRequired(
true);
358 $range_min->setValue($result->getRangeMin());
360 $range_max =
new ilNumberInputGUI($this->
lng->txt(
'range_max'),
'range_max_' . $result->getResult());
362 $range_max->setSize(3);
363 $range_max->setRequired(
true);
364 $range_max->setValue($result->getRangeMax());
368 $precision =
new ilNumberInputGUI($this->
lng->txt(
'precision'),
'precision_' . $result->getResult());
370 $precision->setSize(3);
371 $precision->setMinValue(0);
372 $precision->setInfo($this->
lng->txt(
'fq_precision_info'));
373 $precision->setValue($result->getPrecision());
375 $tolerance =
new ilNumberInputGUI($this->
lng->txt(
'tolerance'),
'tolerance_' . $result->getResult());
377 $tolerance->setMinValue(0);
378 $tolerance->setMaxValue(100);
379 $tolerance->allowDecimals(
true);
380 $tolerance->setInfo($this->
lng->txt(
'tolerance_info'));
381 $tolerance->setValue($result->getTolerance());
384 $suggest_range_button->setHtml(
'<input type="submit" class="btn btn-default" name="cmd[suggestrange_' . $result->getResult() .
']" value="' . $this->
lng->txt(
"suggest_range") .
'" />');
386 $sel_result_units =
new ilSelectInputGUI($this->
lng->txt(
'unit'),
'unit_' . $result->getResult());
387 $sel_result_units->setOptions(array(0 => $this->
lng->txt(
'no_selection')) + $unit_options);
388 $sel_result_units->setInfo($this->
lng->txt(
'result_unit_info'));
389 if (is_object($result->getUnit())) {
390 $sel_result_units->setValue($result->getUnit()->getId());
395 $mc_result_units->setInfo($this->
lng->txt(
'result_units_info'));
396 $selectedvalues = array();
397 foreach ($unit_options as $unit_id =>
$txt) {
398 if ($this->
hasResultUnit($result, $unit_id, $result_units)) {
399 $selectedvalues[] = $unit_id;
402 $mc_result_units->setValue($selectedvalues);
404 $result_type =
new ilRadioGroupInputGUI($this->
lng->txt(
'result_type_selection'),
'result_type_' . $result->getResult());
408 $no_type->
setInfo($this->
lng->txt(
'fq_no_restriction_info'));
411 $result_dec->
setInfo($this->
lng->txt(
'result_dec_info'));
414 $result_frac->
setInfo($this->
lng->txt(
'result_frac_info'));
417 $result_co_frac->
setInfo($this->
lng->txt(
'result_co_frac_info'));
419 $result_type->addOption($no_type);
420 $result_type->addOption($result_dec);
421 $result_type->addOption($result_frac);
422 $result_type->addOption($result_co_frac);
423 $result_type->setValue(strlen($result->getResultType()) ? $result->getResultType() : 0);
425 $points =
new ilNumberInputGUI($this->
lng->txt(
'points'),
'points_' . $result->getResult());
427 $points->setRequired(
true);
429 $points->setMinValue(0);
430 $points->setValue(strlen($result->getPoints()) ? $result->getPoints() : 1);
432 $rating_type =
new ilCheckboxInputGUI($this->
lng->txt(
'advanced_rating'),
'rating_advanced_' . $result->getResult());
434 $rating_type->setInfo($this->
lng->txt(
'advanced_rating_info'));
438 if (!$advanced_rating) {
439 $rating_type->setDisabled(
true);
440 $rating_type->setChecked(
false);
442 $rating_type->setChecked(strlen($result->getRatingSimple()) && $result->getRatingSimple() ? false :
true);
446 $sign =
new ilNumberInputGUI($this->
lng->txt(
'rating_sign'),
'rating_sign_' . $result->getResult());
449 $sign->setMinValue(0);
450 $sign->setValue($result->getRatingSign());
451 $rating_type->addSubItem($sign);
453 $value =
new ilNumberInputGUI($this->
lng->txt(
'rating_value'),
'rating_value_' . $result->getResult());
456 $value->setMinValue(0);
457 $value->setValue($result->getRatingValue());
458 $rating_type->addSubItem($value);
460 $unit =
new ilNumberInputGUI($this->
lng->txt(
'rating_unit'),
'rating_unit_' . $result->getResult());
463 $unit->setMinValue(0);
464 $unit->setValue($result->getRatingUnit());
465 $rating_type->addSubItem($unit);
470 $form->addItem($result_header);
471 $form->addItem($formula);
472 $form->addItem($range_min);
473 $form->addItem($range_max);
474 $form->addItem($suggest_range_button);
475 $form->addItem($precision);
476 $form->addItem($tolerance);
477 $form->addItem($sel_result_units);
478 $form->addItem($mc_result_units);
479 $form->addItem($result_type);
480 $form->addItem($points);
481 $form->addItem($rating_type);
484 $defined_result_vars = array();
486 $defined_result_res = array();
500 $formula = $tmp_result->getFormula();
502 preg_match_all(
"/([$][v][0-9]*)/", $formula, $form_vars);
503 preg_match_all(
"/([$][r][0-9]*)/", $formula, $form_res);
504 foreach ($form_vars[0] as $res_var) {
505 $defined_result_vars[$res_var] = $res_var;
508 foreach ($form_res[0] as $res_res) {
509 $defined_result_res[$res_res] = $res_res;
514 $result_has_undefined_vars = [];
515 $question_has_unused_vars = [];
516 $result_has_undefined_res = [];
518 if (is_array($quest_vars) && count($quest_vars) > 0) {
519 $result_has_undefined_vars = array_diff($defined_result_vars, $quest_vars);
520 $question_has_unused_vars = array_diff($quest_vars, $defined_result_vars);
523 if (is_array($result_vars) && count($result_vars) > 0) {
524 $result_has_undefined_res = array_diff($defined_result_res, $result_vars);
528 if (count($result_has_undefined_vars) > 0 || count($question_has_unused_vars) > 0) {
529 if (count($result_has_undefined_vars) > 0) {
530 $error_message .= $this->
lng->txt(
"res_contains_undef_var") .
'<br>';
532 if (count($question_has_unused_vars) > 0) {
533 $error_message .= $this->
lng->txt(
"que_contains_unused_var") .
'<br>';
538 $this->tpl->setOnScreenMessage(
'failure', $error_message);
542 if (is_array($result_has_undefined_res) && count($result_has_undefined_res) > 0) {
543 $error_message .= $this->
lng->txt(
"res_contains_undef_res") .
'<br>';
547 if ($save && !$checked) {
548 $this->tpl->setOnScreenMessage(
'failure', $error_message);
551 if ($this->
object->getId()) {
553 $hidden->setValue($this->
object->getId());
554 $form->addItem($hidden);
559 $form->addCommandButton(
'parseQuestion', $this->
lng->txt(
"parseQuestion"));
560 $form->addCommandButton(
'saveReturnFQ', $this->
lng->txt(
"save_return"));
561 $form->addCommandButton(
'saveFQ', $this->
lng->txt(
"save"));
566 $found_vars = array();
567 $found_results = array();
568 foreach ($this->request->getParsedBody() as
$key => $value) {
569 if (preg_match(
"/^unit_(\\\$v\d+)$/", $key, $matches)) {
570 array_push($found_vars, $matches[1]);
572 if (preg_match(
"/^unit_(\\\$r\d+)$/", $key, $matches)) {
573 array_push($found_results, $matches[1]);
578 foreach ($this->request->getParsedBody() as $key => $value) {
579 $item = $form->getItemByPostVar($key);
580 if ($item !== null) {
581 switch (get_class($item)) {
582 case 'ilDurationInputGUI':
583 $item->setHours($value[
'hh']);
584 $item->setMinutes($value[
'mm']);
585 $item->setSeconds($value[
'ss']);
588 $item->setValue($value);
593 $check = array_merge($found_vars, $found_results);
594 foreach ((array) $form->getItems() as $item) {
595 $postvar = $item->getPostVar();
596 if (preg_match(
"/_\\\$[r|v]\d+/", $postvar, $matches)) {
597 $k = substr(array_shift($matches), 1);
598 if (!in_array($k,
$check)) {
599 $form->removeItemByPostVar($postvar);
603 $variables = array_filter($variables, fn ($k, $v) => in_array($v,
$check), ARRAY_FILTER_USE_BOTH);
606 $errors = !$form->checkInput();
608 $custom_errors =
false;
609 if (count($variables)) {
610 foreach ($variables as $variable) {
614 $min_range = $form->getItemByPostVar(
'range_min_' . $variable->getVariable());
615 $max_range = $form->getItemByPostVar(
'range_max_' . $variable->getVariable());
616 if ($min_range->getValue() > $max_range->getValue()) {
617 $min_range->setAlert($this->
lng->txt(
'err_range'));
618 $max_range->setAlert($this->
lng->txt(
'err_range'));
619 $custom_errors =
true;
621 $intPrecision = $form->getItemByPostVar(
'intprecision_' . $variable->getVariable());
622 $decimal_spots = $form->getItemByPostVar(
'precision_' . $variable->getVariable());
623 if ($decimal_spots->getValue() == 0) {
624 if (!$variable->isIntPrecisionValid(
625 $intPrecision->getValue(),
626 $min_range->getValue(),
627 $max_range->getValue()
629 $intPrecision->setAlert($this->
lng->txt(
'err_division'));
630 $custom_errors =
true;
641 $min_range = $form->getItemByPostVar(
'range_min_' . $result->getResult());
642 $max_range = $form->getItemByPostVar(
'range_max_' . $result->getResult());
643 if ($min_range->getValue() > $max_range->getValue()) {
644 $min_range->setAlert($this->
lng->txt(
'err_range'));
645 $max_range->setAlert($this->
lng->txt(
'err_range'));
646 $custom_errors =
true;
650 $formula = $form->getItemByPostVar(
'formula_' . $result->getResult());
651 if (strpos($formula->getValue(), $result->getResult()) !==
false) {
652 $formula->setAlert($this->
lng->txt(
'errRecursionInResult'));
653 $custom_errors =
true;
656 $result_unit = $form->getItemByPostVar(
'unit_' . $result->getResult());
657 $rating_advanced = $form->getItemByPostVar(
'rating_advanced_' . $result->getResult());
658 if (((
int) $result_unit->getValue() <= 0) && $rating_advanced->getChecked()) {
659 unset($_POST[
'rating_advanced_' . $result->getResult()]);
660 $rating_advanced->setDisabled(
true);
661 $rating_advanced->setChecked(
false);
662 $rating_advanced->setAlert($this->
lng->txt(
'err_rating_advanced_not_allowed'));
663 $custom_errors =
true;
664 } elseif ($rating_advanced->getChecked()) {
665 $rating_sign = $form->getItemByPostVar(
'rating_sign_' . $result->getResult());
666 $rating_value = $form->getItemByPostVar(
'rating_value_' . $result->getResult());
667 $rating_unit = $form->getItemByPostVar(
'rating_unit_' . $result->getResult());
669 $percentage = $rating_sign->getValue() + $rating_value->getValue() + $rating_unit->getValue();
670 if ($percentage != 100) {
671 $rating_advanced->setAlert($this->
lng->txt(
'err_wrong_rating_advanced'));
672 $custom_errors =
true;
676 preg_match_all(
"/([$][v][0-9]*)/", $formula->getValue(), $form_vars);
677 $result_has_undefined_vars = array_diff($form_vars[0], $found_vars);
678 if (count($result_has_undefined_vars)) {
680 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'res_contains_undef_var'));
685 if ($custom_errors && !
$errors) {
687 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
689 foreach ($this->request->getParsedBody() as $key => $value) {
690 $item = $form->getItemByPostVar($key);
691 if ($item !== null) {
692 switch (get_class($item)) {
693 case 'ilDurationInputGUI':
694 $item->setHours($value[
'hh']);
695 $item->setMinutes($value[
'mm']);
696 $item->setSeconds($value[
'ss']);
699 $item->setValue($value);
709 $this->tpl->setVariable(
'QUESTION_DATA', $form->getHTML());
716 if (array_key_exists($result->getResult(), $resultunits)) {
717 if (array_key_exists($unit_id, $resultunits[$result->getResult()])) {
733 $resultunit = $result->getUnit();
741 if (is_object($resultunit)) {
752 $this->editQuestion();
759 $old_id = $this->request->getQuestionId();
765 $this->
object->saveToDb();
766 $originalexists =
false;
767 if ($this->
object->getOriginalId() != null && $this->
object->_questionExistsInPool($this->
object->getOriginalId())) {
768 $originalexists =
true;
770 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
771 if (($this->request->raw(
"calling_test") || ($this->request->isset(
'calling_consumer') && (
int) $this->request->raw(
'calling_consumer')))
773 $this->
ctrl->redirect($this,
"originalSyncForm");
774 } elseif ($this->request->raw(
"calling_test")) {
775 require_once
'Modules/Test/classes/class.ilObjTest.php';
776 $test =
new ilObjTest($this->request->raw(
"calling_test"));
777 $q_id = $this->
object->getId();
780 $tree = $DIC[
'tree'];
781 $ilDB = $DIC[
'ilDB'];
784 $test =
new ilObjTest($this->request->raw(
"calling_test"),
true);
788 $test->insertQuestion(
789 $testQuestionSetConfigFactory->getQuestionSetConfig(),
790 $this->
object->
getId(),
794 if ($this->request->isset(
'prev_qid')) {
795 $test->moveQuestionAfter($this->
object->getId(), $this->request->raw(
'prev_qid'));
798 $this->
ctrl->setParameter($this,
'calling_test', $this->request->raw(
"calling_test"));
800 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"msg_obj_modified"),
true);
803 if ($this->
object->getId() != $old_id) {
805 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"msg_obj_modified"),
true);
806 $this->
ctrl->redirectByClass(
"ilobjquestionpoolgui",
"questions");
809 $this->tpl->setOnScreenMessage(
'success',
ilSession::get(
'info') .
"<br />" . $this->
lng->txt(
"msg_obj_modified"),
true);
811 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"msg_obj_modified"),
true);
818 $this->
object->saveToDb();
819 $this->editQuestion();
828 $this->editQuestion();
839 if ((!$_POST[
"title"]) or (!$_POST[
"author"]) or (!$_POST[
"question"])) {
863 $graphicalOutput =
false,
864 $result_output =
false,
865 $show_question_only =
true,
866 $show_feedback =
false,
867 $show_correct_solution =
false,
868 $show_manual_scoring =
false,
869 $show_question_text =
true 872 $user_solution = array();
873 if (($active_id > 0) && (!$show_correct_solution)) {
874 $user_solution[
"active_id"] = $active_id;
875 $user_solution[
"pass"] = $pass;
876 $solutions = $this->
object->getSolutionValues($active_id, $pass);
877 foreach ($solutions as $idx => $solution_value) {
878 if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
879 $user_solution[$matches[1]] = $solution_value[
"value2"];
880 } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
881 if (!array_key_exists($matches[1], $user_solution)) {
882 $user_solution[$matches[1]] = array();
884 $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
885 } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
886 if (!array_key_exists($matches[1], $user_solution)) {
887 $user_solution[$matches[1]] = array();
889 $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
892 } elseif ($active_id) {
893 $user_solution = $this->
object->getBestSolution($this->
object->getSolutionValues($active_id, $pass));
895 $solutionValues = array();
898 if (is_array($participantsSolution)) {
899 foreach ($participantsSolution as $val1 => $val2) {
900 $solutionValues[] = array(
'value1' => $val1,
'value2' => $val2);
904 $user_solution = $this->
object->getBestSolution($solutionValues);
907 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution.html",
true,
true,
'Modules/TestQuestionPool');
908 $correctness_icons = [
912 $questiontext = $this->
object->substituteVariables($user_solution, $graphicalOutput,
true, $result_output, $correctness_icons);
914 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
915 $questionoutput = $template->get();
916 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
918 if (strlen($feedback)) {
924 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
925 $solutiontemplate->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($feedback,
true));
927 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
929 $solutionoutput = $solutiontemplate->get();
930 if (!$show_question_only) {
934 return $solutionoutput;
937 public function getPreview($show_question_only =
false, $showInlineFeedback =
false): string
939 $user_solution = array();
944 foreach ($solutions as $val1 => $val2) {
945 if (preg_match(
"/^(\\\$v\\d+)$/", $val1, $matches)) {
946 $user_solution[$matches[1]] = $val2;
947 } elseif (preg_match(
"/^(\\\$r\\d+)$/", $val1, $matches)) {
948 if (!array_key_exists($matches[1], $user_solution)) {
949 $user_solution[$matches[1]] = array();
951 $user_solution[$matches[1]][
"value"] = $val2;
952 } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $val1, $matches)) {
953 if (!array_key_exists($matches[1], $user_solution)) {
954 $user_solution[$matches[1]] = array();
956 $user_solution[$matches[1]][
"unit"] = $val2;
959 if (preg_match(
"/^(\\\$r\\d+)/", $val1, $matches) && !isset($user_solution[$matches[1]][
"result_type"])) {
965 if (!$this->
object->hasRequiredVariableSolutionValues($user_solution)) {
966 $user_solution = $this->
object->getInitialVariableSolutionValues();
973 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html",
true,
true,
'Modules/TestQuestionPool');
975 $questiontext = $this->
object->substituteVariables($user_solution);
977 $questiontext = $this->
object->substituteVariables(array());
979 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
980 $questionoutput = $template->get();
981 if (!$show_question_only) {
985 return $questionoutput;
989 public function getTestOutput($active_id, $pass, $is_postponed =
false, $use_post_solutions =
false, $show_feedback =
false): string
992 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'enter_valid_values'));
994 $user_solution = array();
996 $solutions = $this->
object->getTestOutputSolutions($active_id, $pass);
998 $actualPassIndex = null;
999 if ($this->
object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
1000 require_once
'Modules/Test/classes/class.ilObjTest.php';
1004 foreach ($solutions as $idx => $solution_value) {
1005 if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
1006 if ($this->
object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
1007 $this->
object->saveCurrentSolution($active_id, $actualPassIndex, $matches[1], $solution_value[
"value2"],
true);
1010 $user_solution[$matches[1]] = $solution_value[
"value2"];
1011 } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
1012 if (!array_key_exists($matches[1], $user_solution)) {
1013 $user_solution[$matches[1]] = array();
1015 $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
1016 } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
1017 if (!array_key_exists($matches[1], $user_solution)) {
1018 $user_solution[$matches[1]] = array();
1020 $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
1022 if (preg_match(
"/^(\\\$r\\d+)/", $solution_value[
"value1"], $matches) && !isset($user_solution[$matches[1]][
"result_type"])) {
1029 $solutions = $this->
object->getSolutionValues($active_id, $pass,
true);
1030 foreach ($solutions as $idx => $solution_value) {
1031 if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
1032 $user_solution[$matches[1]] = $solution_value[
"value2"];
1037 if (!$this->
object->hasRequiredVariableSolutionValues($user_solution)) {
1038 foreach ($this->
object->getInitialVariableSolutionValues() as $val1 => $val2) {
1039 $this->
object->saveCurrentSolution($active_id, $pass, $val1, $val2,
true);
1044 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output.html",
true,
true,
'Modules/TestQuestionPool');
1046 $questiontext = $this->
object->substituteVariables($user_solution);
1048 $template->setVariable(
"QUESTIONTEXT", $this->
object->prepareTextareaOutput($questiontext,
true));
1050 $questionoutput = $template->get();
1051 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
static get(string $a_var)
hasCorrectSolution($activeId, $passIndex)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance($identifier)
generateCorrectnessIconsForCorrectness(int $correctness)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
writePref(string $a_keyword, string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
const CSS_CLASS_FEEDBACK_CORRECT
static _questionExistsInTest(int $question_id, int $test_id)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
const CSS_CLASS_FEEDBACK_WRONG
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
callNewIdListeners(int $a_new_id)
setPref(string $a_keyword, ?string $a_value)
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
addSaveOnEnterOnLoadCode()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
__construct(Container $dic, ilPlugin $plugin)
ilComponentRepository $component_repository
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
addErrorMessage(string $errormessage)
static _isWriteable(int $question_id, int $user_id)
static stripOnlySlashes(string $a_str)
getGenericFeedbackOutput(int $active_id, ?int $pass)