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'] = $solution_value[
'value2'];
830 $points += $result->getReachedPoints(
833 $user_solution[$result->getResult()][
'value'] ??
'',
834 $user_solution[$result->getResult()][
'unit'] ??
'',
835 $this->unitrepository->getUnits()
848 $v = isset($user_solution[$result->getResult()]) ? $user_solution[$result->getResult()] :
null;
849 $u = isset($user_solution[$result->getResult() .
'_unit']) ? $user_solution[$result->getResult() .
'_unit'] :
null;
851 $points += $result->getReachedPoints(
856 $this->unitrepository->getUnits()
867 $submittedValue = str_replace(
',',
'.', $submittedValue);
869 if (is_numeric($submittedValue)) {
873 if (preg_match(
'/^[-+]?\d+\/\d+$/', $submittedValue)) {
883 bool $authorized =
true 885 if (is_null($pass)) {
891 function () use ($answer, $active_id, $pass, $authorized) {
892 foreach ($answer as $key => $value) {
894 if (preg_match(
'/^result_(\$r\d+)$/', $key, $matches) !==
false) {
895 $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]);
898 $queryResult .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
901 $result = $this->db->queryF(
903 [
'integer',
'integer',
'integer',
'integer'],
904 [$active_id, $pass, $this->
getId(), (
int) $authorized]
906 if ($result->numRows()) {
907 while ($row = $this->db->fetchAssoc($result)) {
908 $this->db->manipulateF(
909 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
910 [
'integer',
'integer'],
911 [$row[
'solution_id'], (
int) $authorized]
916 $this->
saveCurrentSolution($active_id, $pass, $matches[1], str_replace(
",",
".", $value), $authorized);
920 if (preg_match(
'/^result_(\$r\d+)_unit$/', $key, $matches) !==
false) {
921 $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");
924 $queryResultUnit .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
927 $result = $this->db->queryF(
929 [
'integer',
'integer',
'integer',
'integer'],
930 [$active_id, $pass, $this->
getId(), (
int) $authorized]
932 if ($result->numRows()) {
933 while ($row = $this->db->fetchAssoc($result)) {
934 $this->db->manipulateF(
935 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
936 [
'integer',
'integer'],
937 [$row[
'solution_id'], (
int) $authorized]
957 'authorized' =>
false,
958 'intermediate' => false
962 SELECT authorized, COUNT(*) cnt 964 WHERE active_fi = " . $this->db->quote($active_id,
'integer') .
" 965 AND question_fi = " . $this->db->quote($this->
getId(),
'integer') .
" 966 AND pass = " . $this->db->quote($pass,
'integer') .
" 967 AND value1 like '\$r%' 968 AND value2 is not null 973 $query .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
980 $result = $this->db->query($query);
982 while ($row = $this->db->fetchAssoc($result)) {
983 if ($row[
'authorized']) {
984 $return[
'authorized'] = $row[
'cnt'] > 0;
986 $return[
'intermediate'] = $row[
'cnt'] > 0;
995 DELETE FROM tst_solutions 996 WHERE active_fi = " . $this->db->quote($active_id,
'integer') .
" 997 AND question_fi = " . $this->db->quote($this->
getId(),
'integer') .
" 998 AND pass = " . $this->db->quote($pass,
'integer') .
" 999 AND value1 like '\$r%' 1003 $query .=
" AND step = " . $this->db->quote((
int) $this->
getStep(),
'integer') .
" ";
1006 return $this->db->manipulate($query);
1016 if (preg_match(
'/^result_(\$r\d+)$/', $key, $matches)) {
1017 $userSolution[$matches[1]] = $val;
1018 } elseif (preg_match(
'/^result_(\$r\d+)_unit$/', $key, $matches)) {
1019 $userSolution[$matches[1] .
"_unit"] = $val;
1028 return "assFormulaQuestion";
1043 $affectedRows = $this->db->manipulateF(
1044 "DELETE FROM il_qpl_qst_fq_var WHERE question_fi = %s",
1049 $affectedRows = $this->db->manipulateF(
1050 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
1055 $affectedRows = $this->db->manipulateF(
1056 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
1061 $affectedRows = $this->db->manipulateF(
1062 "DELETE FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
1067 $affectedRows = $this->db->manipulateF(
1068 "DELETE FROM il_qpl_qst_fq_unit WHERE question_fi = %s",
1076 $text = parent::getRTETextWithMediaObjects();
1082 $user_solution = [];
1084 foreach ($solutions as $solution_value) {
1085 if (preg_match(
'/^(\$v\d+)$/', $solution_value[
'value1'], $matches)) {
1086 $user_solution[$matches[1]] = $solution_value[
'value2'];
1088 $varObj->setValue($solution_value[
'value2']);
1089 } elseif (preg_match(
'/^(\$r\d+)$/', $solution_value[
'value1'], $matches)) {
1090 if (!array_key_exists($matches[1], $user_solution)) {
1091 $user_solution[$matches[1]] = [];
1093 $user_solution[$matches[1]][
'value'] = $solution_value[
'value2'];
1094 } elseif (preg_match(
'/^(\$r\d+)_unit$/', $solution_value[
'value1'], $matches)) {
1095 if (!array_key_exists($matches[1], $user_solution)) {
1096 $user_solution[$matches[1]] = [];
1098 $user_solution[$matches[1]][
'unit'] = $solution_value[
'value2'];
1104 if (is_object($result->getUnit())) {
1105 $user_solution[$result->getResult()][
'unit'] = $result->getUnit()->getId();
1106 $user_solution[$result->getResult()][
'value'] = $resVal;
1107 } elseif ($result->getUnit() ===
null) {
1111 $available_units = $result->getAvailableResultUnits(
parent::getId());
1112 $result_name = $result->getResult();
1114 $check_unit =
false;
1115 if (array_key_exists($result_name, $available_units) &&
1116 $available_units[$result_name] !==
null) {
1117 $check_unit = in_array($user_solution[$result_name][
'unit'], $available_units[$result_name]);
1120 if ($check_unit ==
true) {
1126 $user_solution[$result->getResult()][
'value'] =
ilMath::_div($resVal, $unit_factor, 55);
1128 $user_solution[$result->getResult()][
'value'] = 0;
1134 if (is_array($value)) {
1135 $user_solution[$result->getResult()][
'value'] = $value[0];
1136 $user_solution[$result->getResult()][
'frac_helper'] = $value[1];
1138 $user_solution[$result->getResult()][
'value'] = $value;
1139 $user_solution[$result->getResult()][
'frac_helper'] =
null;
1142 $user_solution[$result->getResult()][
'value'] = round((
float) $user_solution[$result->getResult()][
'value'], $result->getPrecision());
1145 return $user_solution;
1151 $this->unitrepository->setConsumerId($this->
getId());
1169 $solutionSubmit = [];
1171 $post = $this->dic->http()->wrapper()->post();
1174 $key =
"result_$index";
1175 if (
$post->has($key)) {
1176 $value =
$post->retrieve(
1178 $this->dic->refinery()->kindlyTo()->string()
1181 $solutionSubmit[$key] = $value;
1183 if (
$post->has($key .
"_unit")) {
1184 $value =
$post->retrieve(
1186 $this->dic->refinery()->kindlyTo()->string()
1188 $solutionSubmit[$key .
"_unit"] = $value;
1191 return $solutionSubmit;
1198 $this->tpl->setOnScreenMessage(
1200 $this->
lng->txt(
"err_no_numeric_value"),
1212 return ilOperatorsExpressionMapping::getOperatorsByExpression($expression);
1232 $data = $this->db->queryF(
1233 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1234 [
'integer',
'integer',
'integer',
'integer'],
1235 [$active_id, $pass, $this->
getId(), $maxStep]
1238 $data = $this->db->queryF(
1239 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1240 [
'integer',
'integer',
'integer'],
1241 [$active_id, $pass, $this->
getId()]
1245 while ($row = $this->db->fetchAssoc(
$data)) {
1246 if (strstr($row[
'value1'],
'$r') && $row[
'value2'] !=
null) {
1247 $result->addKeyValue(str_replace(
'$r',
"", $row[
'value1']), $row[
'value2']);
1254 $result->setReachedPercentage((
$points / $max_points) * 100);
1269 if ($index !==
null) {
1270 return $this->
getResult(
'$r' . ($index + 1));
1279 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->
getQuestionType(),
1286 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULTS => $this->
buildResultsForLog(
1290 AdditionalInformationGenerator::KEY_FEEDBACK => [
1291 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1292 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1303 return array_reduce(
1307 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $v->
getRangeMinTxt(),
1308 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $v->
getRangeMaxTxt(),
1309 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $v->
getPrecision(),
1310 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_INTPRECISION => $v->
getIntprecision(),
1311 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $v->
getUnit() ?? $none_tag
1325 return array_reduce(
1329 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_RESULT_TYPE => $r->
getResultType(),
1330 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_FORMULA => $r->
getFormula(),
1331 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => $r->
getPoints(),
1332 AdditionalInformationGenerator::KEY_QUESTION_LOWER_LIMIT => $r->
getRangeMinTxt(),
1333 AdditionalInformationGenerator::KEY_QUESTION_UPPER_LIMIT => $r->
getRangeMaxTxt(),
1334 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_TOLERANCE => $r->
getTolerance(),
1335 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_PRECISION => $r->
getPrecision(),
1336 AdditionalInformationGenerator::KEY_QUESTION_FORMULA_UNIT => $r->
getUnit() ?? $none_tag
1346 array $solution_values
1348 return array_reduce(
1350 function (array
$c, array $v) use ($additional_info): array {
1351 if (str_starts_with($v[
'value1'],
'$v')) {
1353 if ($var ===
null) {
1354 $c[$v[
'value1']] = $additional_info->
getNoneTag();
1357 if ($var->getUnit() !==
null) {
1358 $c[$v[
'value1']] = $v[
'value2'] . $var->getUnit()->getUnit();
1363 if (strpos($v[
'value1'],
'_unit')) {
1365 $c[$v[
'value1']] = $unit->getUnit() ?? $additional_info->
getNoneTag();
1369 $c[$v[
'value1']] = $v[
'value2'];
1378 ksort($solution_values);
1379 return array_reduce(
1381 function (array
$c, array $v): array {
1382 if (!str_starts_with($v[
'value1'],
'$r')) {
1385 if (!strpos($v[
'value1'],
'_unit')) {
1386 $c[$v[
'value1']] =
"{$v['value1']} = {$v['value2']}";
1389 $k = substr($v[
'value1'], 0, -5);
1390 if (array_key_exists($k, $c)) {
1391 $c[$k] .= $v[
'value2'];
1403 function (
string $v) use ($best_solution):
string {
1404 $solution =
"{$v} = {$best_solution[$v]['value']}";
1405 if (isset($best_solution[
'unit'])) {
1406 $solution .=
"{$this->unitrepository->getUnit($best_solution['unit'])->getUnit()}";
1410 array_keys($best_solution)
1418 function (
string $v) use ($variables):
string {
1419 $variable =
"{$v} = {$variables[$v]}";
1421 $variable .= $this->
getVariable($v)->getUnit()->getUnit();
1425 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
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $preview_session, $reached_points)
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