19 declare(strict_types=1);
47 $this->variables = [];
49 $this->resultunits = [];
56 $this->variables = [];
66 if (array_key_exists($variable, $this->variables)) {
67 return $this->variables[$variable];
74 $this->variables[$variable->
getVariable()] = $variable;
89 if (array_key_exists($result, $this->results)) {
90 return $this->results[$result];
97 $this->results[$result->
getResult()] = $result;
104 $this->resultunits[$result->
getResult()] = [];
105 if ($result ===
null || $unit_ids ===
null) {
108 foreach ($unit_ids as
$id) {
109 if (is_numeric($id) && ($id > 0)) {
119 if ($result ===
null || $unit ===
null) {
124 !is_array($this->resultunits[$result->
getResult()])) {
125 $this->resultunits[$result->
getResult()] = [];
132 if (!isset($this->resultunits[$result->
getResult()])) {
136 $result_units = $this->resultunits[$result->
getResult()];
144 return $result_units;
157 && array_key_exists($unit_id, $this->resultunits[$result->
getResult()])) {
168 if (preg_match_all(
'/(\$v\d+)/im', $this->
getQuestion(), $matches)) {
169 foreach ($matches[1] as $variable) {
175 if (preg_match_all(
'/(\$r\d+)/im', $this->
getQuestion(), $rmatches)) {
176 foreach ($rmatches[1] as $result) {
185 if (preg_match_all(
'/(\$v\d+)/im', $this->
getQuestion(), $matches)) {
186 if ((count(array_unique($matches[1]))) != count($matches[1])) {
195 if (preg_match_all(
'/(\$r\d+)/im', $this->
getQuestion(), $rmatches)) {
196 if ((count(array_unique($rmatches[1]))) != count($rmatches[1])) {
212 if (preg_match_all(
'/(\$r\d+)/im', $questionText, $matches)) {
213 foreach ($matches[1] as $resultKey) {
214 $resObjects[] = $this->
getResult($resultKey);
229 if (preg_match_all(
'/(\$v\d+)/im', $question_text, $matches)) {
230 $var_objects = array_reduce(
232 function (array
$c,
string $v): array {
253 if (!isset($userSolution[$varObj->getVariable()])) {
257 if ($userSolution[$varObj->getVariable()] ===
'') {
269 $question_id = $this->
getId();
270 $values = $this->pass_presented_variables_repo->getFor(
275 if (is_null($values)) {
277 $this->pass_presented_variables_repo->store(
293 $variableSolutionValues = [];
296 $variableSolutionValues[$varObj->getVariable()] = $varObj->getValue();
299 return $variableSolutionValues;
302 public function saveCurrentSolution(
int $active_id,
int $pass, $value1, $value2,
bool $authorized =
true, $tstamp = 0):
int 305 foreach ($init_solution_vars as $val1 => $val2) {
306 $this->db->manipulateF(
307 "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s",
308 [
'integer',
'integer',
'integer',
'text'],
309 [$active_id, $this->
getId(), $pass, $val1]
311 parent::saveCurrentSolution($active_id, $pass, $val1, $val2, $authorized);
313 return parent::saveCurrentSolution($active_id, $pass, $value1, $value2, $authorized, $tstamp);
321 public function substituteVariables(array $userdata,
bool $graphicalOutput =
false,
bool $forsolution =
false,
bool $result_output =
false, array $correctness_icons = [])
323 if ((count($this->results) == 0) && (count($this->variables) == 0)) {
330 if (isset($userdata[$varObj->getVariable()]) && strlen($userdata[$varObj->getVariable()])) {
331 $varObj->setValue($userdata[$varObj->getVariable()]);
334 $unit = (is_object($varObj->getUnit())) ? $varObj->getUnit()->getUnit() :
"";
337 if ($varObj->getValue() !==
null) {
338 $val = (strlen($varObj->getValue()) > 8) ? strtoupper(sprintf(
"%e", $varObj->getValue())) : $varObj->getValue();
341 $text = preg_replace(
'/\$' . substr($varObj->getVariable(), 1) .
'(?![0-9]+)/', $val .
' ' . $unit .
'\1', $text);
346 if (preg_match_all(
'/(\$r\d+)/im', $this->
getQuestion(), $rmatches)) {
347 foreach ($rmatches[1] as $result) {
351 $userdata[$result][
'result_type'] = $resObj->getResultType();
359 if (is_array($userdata) &&
360 isset($userdata[$result]) &&
361 isset($userdata[$result][
'value'])) {
363 } elseif ($forsolution) {
365 if (!is_array($userdata)) {
367 $value = sprintf(
"%." . $resObj->getPrecision() .
"f", $value);
372 if (is_array($value)) {
373 $frac_helper = $value[1];
385 if (count($result_units) > 0) {
387 if (is_array($userdata)) {
388 foreach ($result_units as $unit) {
389 if (isset($userdata[$result][
"unit"]) && $userdata[$result][
"unit"] == $unit->getId()) {
390 $units = $unit->getUnit();
394 if ($resObj->getUnit()) {
395 $units = $resObj->getUnit()->getUnit();
399 $units =
'<select name="result_' . $result .
'_unit">';
400 $units .=
'<option value="-1">' . $this->
lng->txt(
"select_unit") .
'</option>';
401 foreach ($result_units as $unit) {
402 $units .=
'<option value="' . $unit->getId() .
'"';
403 if (array_key_exists($result, $userdata) &&
404 is_array($userdata[$result]) &&
405 array_key_exists(
'unit', $userdata[$result])) {
406 if ($userdata[$result][
"unit"] == $unit->getId()) {
407 $units .=
' selected="selected"';
410 $units .=
'>' . $unit->getUnit() .
'</option>';
412 $units .=
'</select>';
417 switch ($resObj->getResultType()) {
419 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_dec');
422 if ($frac_helper !==
'') {
423 $units .=
' ≈ ' . $frac_helper .
', ';
424 } elseif (is_array($userdata) &&
425 array_key_exists($result, $userdata) &&
426 array_key_exists(
'frac_helper', $userdata[$result]) &&
427 is_string($userdata[$result][
"frac_helper"])) {
428 if (!str_contains($value,
'/')) {
429 $units .=
' ≈ ' . $userdata[$result][
"frac_helper"] .
', ';
432 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_frac');
435 if ($frac_helper !==
'') {
436 $units .=
' ≈ ' . $frac_helper .
', ';
437 } elseif (isset($userdata[$result][
"frac_helper"]) && is_array($userdata) && $userdata[$result][
"frac_helper"] !==
'') {
438 if (!str_contains($value,
'/')) {
439 $units .=
' ≈ ' . $userdata[$result][
"frac_helper"] .
', ';
442 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_co_frac');
448 if ($graphicalOutput) {
451 if (is_array($userdata) && is_array($userdata[$result])) {
452 if (isset($userdata[$result][
"unit"]) && $userdata[$result][
"unit"] > 0) {
456 if (isset($userdata[$result][
"value"])) {
457 $user_value = $userdata[$result][
"value"];
461 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution_image.html",
true,
true,
'components/ILIAS/TestQuestionPool');
463 $correctness_icon = $correctness_icons[
'not_correct'];
464 if ($resObj->isCorrect($this->getVariables(), $this->
getResults(), $user_value, $resunit)) {
465 $correctness_icon = $correctness_icons[
'correct'];
467 $template->setCurrentBlock(
"icon_ok");
468 $template->setVariable(
"ICON_OK", $correctness_icon);
469 $template->parseCurrentBlock();
471 $checkSign = $template->get();
474 if ($result_output) {
475 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution_result.html",
true,
true,
'components/ILIAS/TestQuestionPool');
477 if (is_array($userdata) &&
478 array_key_exists($resObj->getResult(), $userdata) &&
479 array_key_exists(
'value', $userdata[$resObj->getResult()])) {
480 $found = $resObj->getResultInfo(
483 $userdata[$resObj->getResult()][
"value"],
484 $userdata[$resObj->getResult()][
"unit"] ??
null,
488 $found = $resObj->getResultInfo(
492 is_object($resObj->getUnit()) ? $resObj->getUnit()->getId() :
null,
497 if ($resObj->getRatingSimple()) {
499 $resulttext .=
"n/a";
501 $resulttext .= $found[
'points'] .
" " . (($found[
'points'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points'));
504 $resulttext .= $this->
lng->txt(
"rated_sign") .
" " . (($found[
'sign']) ? $found[
'sign'] : 0) .
" " . (($found[
'sign'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points')) .
", ";
505 $resulttext .= $this->
lng->txt(
"rated_value") .
" " . (($found[
'value']) ? $found[
'value'] : 0) .
" " . (($found[
'value'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points')) .
", ";
506 $resulttext .= $this->
lng->txt(
"rated_unit") .
" " . (($found[
'unit']) ? $found[
'unit'] : 0) .
" " . (($found[
'unit'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points'));
510 $template->setVariable(
"RESULT_OUTPUT", $resulttext);
512 $resultOutput = $template->get();
514 $text = preg_replace(
'/\$' . substr($result, 1) .
'(?![0-9]+)/', $input .
' ' . $units .
' ' . $checkSign .
' ' . $resultOutput .
' ' .
'\1', $text);
523 return '<span class="ilc_qinput_TextInput solutionbox">' 527 $input =
'<input class="ilc_qinput_TextInput" type="text"';
528 $input .=
'spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"';
529 $input .=
'name="result_' . $result_key .
'"';
530 $input .=
' value="' . $result_value .
'"/>';
543 $resultunit = $result->getUnit();
545 foreach ($result_units as $unit) {
546 if (is_object($resultunit)) {
547 if ($resultunit->getId() != $unit->getId()) {
548 if ($resultunit->getBaseUnit() && $unit->getBaseUnit()) {
549 if ($resultunit->getBaseUnit() == $unit->getBaseUnit()) {
553 if ($resultunit->getBaseUnit()) {
554 if ($resultunit->getBaseUnit() == $unit->getId()) {
558 if ($unit->getBaseUnit()) {
559 if ($unit->getBaseUnit() == $resultunit->getId()) {
575 if (($this->title) and ($this->author) and ($this->question) and ($this->
getMaximumPoints() > 0)) {
586 $affectedRows = $this->db->manipulateF(
588 DELETE FROM il_qpl_qst_fq_var 589 WHERE question_fi = %s",
594 foreach ($this->variables as $variable) {
595 $next_id = $this->db->nextId(
'il_qpl_qst_fq_var');
599 'variable_id' => [
'integer', $next_id],
600 'question_fi' => [
'integer', $this->
getId()],
601 'variable' => [
'text', $variable->getVariable()],
602 'range_min' => [
'float', $variable->getRangeMin()],
603 'range_max' => [
'float', $variable->getRangeMax()],
604 'unit_fi' => [
'integer', (is_object($variable->getUnit()) ? (
int) $variable->getUnit()->getId() : 0)],
605 'varprecision' => [
'integer', (
int) $variable->getPrecision()],
606 'intprecision' => [
'integer', (
int) $variable->getIntprecision()],
607 'range_min_txt' => [
'text', $variable->getRangeMinTxt()],
608 'range_max_txt' => [
'text', $variable->getRangeMaxTxt()]
613 $affectedRows = $this->db->manipulateF(
614 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
619 foreach ($this->results as $result) {
620 $next_id = $this->db->nextId(
'il_qpl_qst_fq_res');
621 if (is_object($result->getUnit())) {
622 $tmp_result_unit = $result->getUnit()->getId();
624 $tmp_result_unit =
null;
628 if ($result->getFormula() !==
null) {
629 $formula = str_replace(
",",
".", $result->getFormula());
632 $this->db->insert(
"il_qpl_qst_fq_res", [
633 "result_id" => [
'integer', $next_id],
634 "question_fi" => [
'integer', $this->
getId()],
635 "result" => [
"text", $result->getResult()],
636 "range_min" => [
"float", $result->getRangeMin()],
637 "range_max" => [
"float", $result->getRangeMax()],
638 "tolerance" => [
"float", $result->getTolerance()],
639 "unit_fi" => [
'integer', (
int) $tmp_result_unit],
640 "formula" => [
"clob", $formula],
641 "resprecision" => [
'integer', $result->getPrecision()],
642 "rating_simple" => [
'integer', ($result->getRatingSimple()) ? 1 : 0],
643 "rating_sign" => [
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingSign()],
644 "rating_value" => [
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingValue()],
645 "rating_unit" => [
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingUnit()],
646 "points" => [
"float", $result->getPoints()],
647 "result_type" => [
'integer', (
int) $result->getResultType()],
648 "range_min_txt" => [
"text", $result->getRangeMinTxt()],
649 "range_max_txt" => [
"text", $result->getRangeMaxTxt()]
654 $affectedRows = $this->db->manipulateF(
655 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
659 foreach ($this->results as $result) {
661 $next_id = $this->db->nextId(
'il_qpl_qst_fq_res_unit');
662 $affectedRows = $this->db->manipulateF(
663 "INSERT INTO il_qpl_qst_fq_res_unit (result_unit_id, question_fi, result, unit_fi) VALUES (%s, %s, %s, %s)",
664 [
'integer',
'integer',
'text',
'integer'],
668 $result->getResult(),
680 $result = $this->db->queryF(
681 "SELECT qpl_questions.* FROM qpl_questions WHERE question_id = %s",
685 if ($result->numRows() == 1) {
686 $data = $this->db->fetchAssoc($result);
687 $this->
setId($question_id);
689 $this->
setComment((
string) $data[
"description"]);
712 $result = $this->db->queryF(
713 "SELECT * FROM il_qpl_qst_fq_var WHERE question_fi = %s",
717 if ($result->numRows() > 0) {
718 while ($data = $this->db->fetchAssoc($result)) {
721 $data[
'range_min_txt'],
722 $data[
'range_max_txt'],
724 $data[
'varprecision'],
725 $data[
'intprecision']
731 $result = $this->db->queryF(
732 "SELECT * FROM il_qpl_qst_fq_res WHERE question_fi = %s",
736 if ($result->numRows() > 0) {
737 while ($data = $this->db->fetchAssoc($result)) {
740 $data[
'range_min_txt'],
741 $data[
'range_max_txt'],
746 $data[
'resprecision'],
747 $data[
'rating_simple'] === 1,
748 $data[
'rating_sign'],
749 $data[
'rating_value'],
752 $resObj->setResultType($data[
'result_type']);
758 $result = $this->db->queryF(
759 "SELECT * FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
763 if ($result->numRows() > 0) {
764 while ($data = $this->db->fetchAssoc($result)) {
766 $resObj = $this->
getResult($data[
"result"]);
771 parent::loadFromDb($question_id);
777 $this->unitrepository->cloneUnits($this->
getId(), $target->
getId());
788 foreach ($this->results as $result) {
789 $points += $result->getPoints();
797 bool $authorized_solution =
true 799 if ($pass ===
null) {
804 foreach ($solutions as $solution_value) {
805 if (preg_match(
'/^(\$v\d+)$/', $solution_value[
'value1'], $matches)) {
806 $user_solution[$matches[1]] = $solution_value[
'value2'];
807 $var_obj = $this->
getVariable($solution_value[
'value1']);
808 $var_obj->setValue($solution_value[
'value2']);
812 if (preg_match(
'/^(\$r\d+)$/', $solution_value[
'value1'], $matches)) {
813 if (!array_key_exists($matches[1], $user_solution)) {
814 $user_solution[$matches[1]] = [];
816 $user_solution[$matches[1]][
'value'] = $solution_value[
'value2'];
820 if (preg_match(
'/^(\$r\d+)_unit$/', $solution_value[
'value1'], $matches)) {
821 if (!array_key_exists($matches[1], $user_solution)) {
822 $user_solution[$matches[1]] = [];
824 $user_solution[$matches[1]][
'unit'] = $this->unitrepository->getUnit(
825 $this->
refinery->kindlyTo()->int()->transform($solution_value[
'value2']),
832 $points += $result->getReachedPoints(
835 $user_solution[$result->getResult()][
'value'] ??
'',
836 $user_solution[$result->getResult()][
'unit'] ??
null,
837 $this->unitrepository->getUnits()
850 $unit_id = $user_solution[$result->getResult() .
'_unit'] ??
null;
851 $points += $result->getReachedPoints(
854 $user_solution[$result->getResult()] ??
'',
855 $unit_id !== null ? $this->unitrepository->getUnit($unit_id) :
null,
856 $this->unitrepository->getUnits()
864 $submittedValue = str_replace(
',',
'.', $submittedValue);
866 if (is_numeric($submittedValue)) {
870 if (preg_match(
'/^[-+]?\d+\/\d+$/', $submittedValue)) {
880 bool $authorized =
true 882 if (is_null($pass)) {
888 function () use ($answer, $active_id, $pass, $authorized) {
889 foreach ($answer as $key => $value) {
891 if (preg_match(
'/^result_(\$r\d+)$/', $key, $matches) !==
false) {
892 $queryResult =
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " . $this->db->like(
'value1',
'clob', $matches[1]);
895 $queryResult .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
898 $result = $this->db->queryF(
900 [
'integer',
'integer',
'integer',
'integer'],
901 [$active_id, $pass, $this->
getId(), (
int) $authorized]
903 if ($result->numRows()) {
904 while ($row = $this->db->fetchAssoc($result)) {
905 $this->db->manipulateF(
906 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
907 [
'integer',
'integer'],
908 [$row[
'solution_id'], (
int) $authorized]
913 $this->
saveCurrentSolution($active_id, $pass, $matches[1], str_replace(
",",
".", $value), $authorized);
917 if (preg_match(
'/^result_(\$r\d+)_unit$/', $key, $matches) !==
false) {
918 $queryResultUnit =
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " . $this->db->like(
'value1',
'clob', $matches[1] .
"_unit");
921 $queryResultUnit .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
924 $result = $this->db->queryF(
926 [
'integer',
'integer',
'integer',
'integer'],
927 [$active_id, $pass, $this->
getId(), (
int) $authorized]
929 if ($result->numRows()) {
930 while ($row = $this->db->fetchAssoc($result)) {
931 $this->db->manipulateF(
932 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
933 [
'integer',
'integer'],
934 [$row[
'solution_id'], (
int) $authorized]
954 'authorized' =>
false,
955 'intermediate' => false
959 SELECT authorized, COUNT(*) cnt 961 WHERE active_fi = " . $this->db->quote($active_id,
'integer') .
" 962 AND question_fi = " . $this->db->quote($this->
getId(),
'integer') .
" 963 AND pass = " . $this->db->quote($pass,
'integer') .
" 964 AND value1 like '\$r%' 965 AND value2 is not null 970 $query .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
977 $result = $this->db->query($query);
979 while ($row = $this->db->fetchAssoc($result)) {
980 if ($row[
'authorized']) {
981 $return[
'authorized'] = $row[
'cnt'] > 0;
983 $return[
'intermediate'] = $row[
'cnt'] > 0;
992 DELETE FROM tst_solutions 993 WHERE active_fi = " . $this->db->quote($active_id,
'integer') .
" 994 AND question_fi = " . $this->db->quote($this->
getId(),
'integer') .
" 995 AND pass = " . $this->db->quote($pass,
'integer') .
" 996 AND value1 like '\$r%' 1000 $query .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
1003 return $this->db->manipulate($query);
1013 if (preg_match(
'/^result_(\$r\d+)$/', $key, $matches)) {
1014 $userSolution[$matches[1]] = $val;
1015 } elseif (preg_match(
'/^result_(\$r\d+)_unit$/', $key, $matches)) {
1016 $userSolution[$matches[1] .
"_unit"] = $val;
1025 return "assFormulaQuestion";
1040 $affectedRows = $this->db->manipulateF(
1041 "DELETE FROM il_qpl_qst_fq_var WHERE question_fi = %s",
1046 $affectedRows = $this->db->manipulateF(
1047 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
1052 $affectedRows = $this->db->manipulateF(
1053 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
1058 $affectedRows = $this->db->manipulateF(
1059 "DELETE FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
1064 $affectedRows = $this->db->manipulateF(
1065 "DELETE FROM il_qpl_qst_fq_unit WHERE question_fi = %s",
1073 $text = parent::getRTETextWithMediaObjects();
1079 $user_solution = [];
1081 foreach ($solutions as $solution_value) {
1082 if (preg_match(
'/^(\$v\d+)$/', $solution_value[
'value1'], $matches)) {
1083 $user_solution[$matches[1]] = $solution_value[
'value2'];
1085 $varObj->setValue($solution_value[
'value2']);
1086 } elseif (preg_match(
'/^(\$r\d+)$/', $solution_value[
'value1'], $matches)) {
1087 if (!array_key_exists($matches[1], $user_solution)) {
1088 $user_solution[$matches[1]] = [];
1090 $user_solution[$matches[1]][
'value'] = $solution_value[
'value2'];
1091 } elseif (preg_match(
'/^(\$r\d+)_unit$/', $solution_value[
'value1'], $matches)) {
1092 if (!array_key_exists($matches[1], $user_solution)) {
1093 $user_solution[$matches[1]] = [];
1095 $user_solution[$matches[1]][
'unit'] = $solution_value[
'value2'];
1101 if (is_object($result->getUnit())) {
1102 $user_solution[$result->getResult()][
'unit'] = $result->getUnit()->getId();
1103 $user_solution[$result->getResult()][
'value'] = $resVal;
1104 } elseif ($result->getUnit() ===
null) {
1108 $available_units = $result->getAvailableResultUnits(
parent::getId());
1109 $result_name = $result->getResult();
1111 $check_unit =
false;
1112 if (array_key_exists($result_name, $available_units) &&
1113 $available_units[$result_name] !==
null) {
1114 $check_unit = in_array($user_solution[$result_name][
'unit'] ??
null, $available_units[$result_name]);
1117 if ($check_unit ==
true) {
1123 $user_solution[$result->getResult()][
'value'] =
ilMath::_div($resVal, $unit_factor, 55);
1125 $user_solution[$result->getResult()][
'value'] = 0;
1131 if (is_array($value)) {
1132 $user_solution[$result->getResult()][
'value'] = $value[0];
1133 $user_solution[$result->getResult()][
'frac_helper'] = $value[1];
1135 $user_solution[$result->getResult()][
'value'] = $value;
1136 $user_solution[$result->getResult()][
'frac_helper'] =
null;
1139 $user_solution[$result->getResult()][
'value'] = round((
float) $user_solution[$result->getResult()][
'value'], $result->getPrecision());
1142 return $user_solution;
1148 $this->unitrepository->setConsumerId($this->
getId());
1166 $solutionSubmit = [];
1168 $post = $this->dic->http()->wrapper()->post();
1171 $key =
"result_$index";
1172 if (
$post->has($key)) {
1173 $value =
$post->retrieve(
1175 $this->dic->refinery()->kindlyTo()->string()
1178 $solutionSubmit[$key] = $value;
1180 if (
$post->has($key .
"_unit")) {
1181 $value =
$post->retrieve(
1183 $this->dic->refinery()->kindlyTo()->string()
1185 $solutionSubmit[$key .
"_unit"] = $value;
1188 return $solutionSubmit;
1195 $this->tpl->setOnScreenMessage(
1197 $this->
lng->txt(
"err_no_numeric_value"),
1209 return ilOperatorsExpressionMapping::getOperatorsByExpression($expression);
1229 $data = $this->db->queryF(
1230 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1231 [
'integer',
'integer',
'integer',
'integer'],
1232 [$active_id, $pass, $this->
getId(), $maxStep]
1235 $data = $this->db->queryF(
1236 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1237 [
'integer',
'integer',
'integer'],
1238 [$active_id, $pass, $this->
getId()]
1242 while ($row = $this->db->fetchAssoc(
$data)) {
1243 if (strstr($row[
'value1'],
'$r') && $row[
'value2'] !=
null) {
1244 $result->addKeyValue(str_replace(
'$r',
"", $row[
'value1']), $row[
'value2']);
1251 $result->setReachedPercentage((
$points / $max_points) * 100);
1266 if ($index !==
null) {
1267 return $this->
getResult(
'$r' . ($index + 1));
1276 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->
getQuestionType(),
1283 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULTS => $this->
buildResultsForLog(
1287 AdditionalInformationGenerator::KEY_FEEDBACK => [
1288 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1289 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1300 return array_reduce(
1304 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $v->
getRangeMinTxt(),
1305 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $v->
getRangeMaxTxt(),
1306 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $v->
getPrecision(),
1307 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_INTPRECISION => $v->
getIntprecision(),
1308 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $v->
getUnit() ?? $none_tag
1322 return array_reduce(
1326 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULT_TYPE => $r->
getResultType(),
1327 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_FORMULA => $r->
getFormula(),
1328 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => $r->
getPoints(),
1329 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $r->
getRangeMinTxt(),
1330 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $r->
getRangeMaxTxt(),
1331 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_TOLERANCE => $r->
getTolerance(),
1332 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $r->
getPrecision(),
1333 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $r->
getUnit() ?? $none_tag
1343 array $solution_values
1345 return array_reduce(
1347 function (array
$c, array $v) use ($additional_info): array {
1348 if (str_starts_with($v[
'value1'],
'$v')) {
1350 if ($var ===
null) {
1351 $c[$v[
'value1']] = $additional_info->
getNoneTag();
1354 if ($var->getUnit() !==
null) {
1355 $c[$v[
'value1']] = $v[
'value2'] . $var->getUnit()->getUnit();
1360 if (strpos($v[
'value1'],
'_unit')) {
1362 $c[$v[
'value1']] = $unit->getUnit() ?? $additional_info->
getNoneTag();
1366 $c[$v[
'value1']] = $v[
'value2'];
1375 ksort($solution_values);
1376 return array_reduce(
1378 function (array
$c, array $v): array {
1379 if (!str_starts_with($v[
'value1'],
'$r')) {
1382 if (!strpos($v[
'value1'],
'_unit')) {
1383 $c[$v[
'value1']] =
"{$v['value1']} = {$v['value2']}";
1386 $k = substr($v[
'value1'], 0, -5);
1387 if (array_key_exists($k, $c)) {
1388 $c[$k] .= $v[
'value2'];
1400 function (
string $v) use ($best_solution):
string {
1401 $solution =
"{$v} = {$best_solution[$v]['value']}";
1402 if (isset($best_solution[
'unit'])) {
1403 $solution .=
"{$this->unitrepository->getUnit($best_solution['unit'])->getUnit()}";
1407 array_keys($best_solution)
1415 function (
string $v) use ($variables):
string {
1416 $variable =
"{$v} = {$variables[$v]}";
1418 $variable .= $this->
getVariable($v)->getUnit()->getUnit();
1422 array_keys($variables)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
getSolutionValues(int $active_id, ?int $pass=null, bool $authorized=true)
Loads solutions of a given user from the database an returns it.
static getInstance($identifier)
const PercentageResultExpression
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static _div($left_operand, $right_operand, int $scale=50)
ensureNonNegativePoints(float $points)
Class ilUnitConfigurationRepository.
getParticipantsSolution()
setComment(string $comment="")
setParticipantsSolution($participantSolution)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
purifyAndPrepareTextAreaOutput(string $content)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const NumericResultExpression
Stores random-generated parts of questions in order to present the user with a fixed question during ...
saveQuestionDataToDb(?int $original_id=null)
getSolutionMaxPass(int $active_id)
__construct(Container $dic, ilPlugin $plugin)
setOriginalId(?int $original_id)
setTitle(string $title="")
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
setLifecycle(ilAssQuestionLifecycle $lifecycle)
lookupMaxStep(int $active_id, int $pass)
setAuthor(string $author="")
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
static getDraftInstance()
setQuestion(string $question="")
const EmptyAnswerExpression