19 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
43 $this->variables = array();
44 $this->results = array();
45 $this->resultunits = array();
51 $this->variables = array();
61 if (array_key_exists($variable, $this->variables)) {
62 return $this->variables[$variable];
69 $this->variables[$variable->getVariable()] = $variable;
74 $this->results = array();
84 if (array_key_exists($result, $this->results)) {
85 return $this->results[$result];
92 $this->results[$result->getResult()] = $result;
97 $this->resultunits[$result->getResult()] = array();
98 if ((!is_object($result)) || (!is_array($unit_ids))) {
101 foreach ($unit_ids as
$id) {
102 if (is_numeric($id) && ($id > 0)) {
110 if (is_object($result) && is_object($unit)) {
112 !is_array($this->resultunits[$result->getResult()])) {
113 $this->resultunits[$result->getResult()] = array();
115 $this->resultunits[$result->getResult()][$unit->getId()] = $unit;
121 if (!isset($this->resultunits[$result->
getResult()])) {
125 $result_units = $this->resultunits[$result->
getResult()];
131 return $result_units;
142 if (array_key_exists($unit_id, $this->resultunits[$result->getResult()])) {
154 if (preg_match_all(
"/(\\\$v\\d+)/ims", $this->
getQuestion(), $matches)) {
155 foreach ($matches[1] as $variable) {
161 if (preg_match_all(
"/(\\\$r\\d+)/ims", $this->
getQuestion(), $rmatches)) {
162 foreach ($rmatches[1] as $result) {
171 if (preg_match_all(
"/(\\\$v\\d+)/ims", $this->
getQuestion(), $matches)) {
172 if ((count(array_unique($matches[1]))) != count($matches[1])) {
181 if (preg_match_all(
"/(\\\$r\\d+)/ims", $this->
getQuestion(), $rmatches)) {
182 if ((count(array_unique($rmatches[1]))) != count($rmatches[1])) {
195 $resObjects = array();
198 if (preg_match_all(
"/(\\\$r\\d+)/ims", $questionText, $matches)) {
199 foreach ($matches[1] as $resultKey) {
200 $resObjects[] = $this->
getResult($resultKey);
213 $varObjects = array();
216 if (preg_match_all(
"/(\\\$v\\d+)/ims", $questionText, $matches)) {
217 foreach ($matches[1] as $variableKey) {
232 if (!isset($userSolution[$varObj->getVariable()])) {
236 if (!strlen($userSolution[$varObj->getVariable()])) {
253 $variableSolutionValues = array();
256 $variableSolutionValues[$varObj->getVariable()] = $varObj->getValue();
259 return $variableSolutionValues;
267 public function substituteVariables(array $userdata,
bool $graphicalOutput =
false,
bool $forsolution =
false,
bool $result_output =
false, array $correctness_icons = [])
269 if ((count($this->results) == 0) && (count($this->variables) == 0)) {
276 if (isset($userdata[$varObj->getVariable()]) && strlen($userdata[$varObj->getVariable()])) {
277 $varObj->setValue($userdata[$varObj->getVariable()]);
280 $unit = (is_object($varObj->getUnit())) ? $varObj->getUnit()->getUnit() :
"";
281 $val = (strlen($varObj->getValue()) > 8) ? strtoupper(sprintf(
"%e", $varObj->getValue())) : $varObj->getValue();
283 $text = preg_replace(
"/\\$" . substr($varObj->getVariable(), 1) .
"(?![0-9]+)/", $val .
" " . $unit .
"\\1", $text);
288 if (preg_match_all(
"/(\\\$r\\d+)/ims", $this->
getQuestion(), $rmatches)) {
289 foreach ($rmatches[1] as $result) {
293 $userdata[$result][
'result_type'] = $resObj->getResultType();
301 if (is_array($userdata) &&
302 isset($userdata[$result]) &&
303 isset($userdata[$result][
"value"])) {
306 } elseif ($forsolution) {
308 if (!is_array($userdata)) {
310 $value = sprintf(
"%." . $resObj->getPrecision() .
"f", $value);
315 if (is_array($value)) {
316 $frac_helper = $value[1];
328 if (count($result_units) > 0) {
330 if (is_array($userdata)) {
331 foreach ($result_units as $unit) {
332 if (isset($userdata[$result][
"unit"]) && $userdata[$result][
"unit"] == $unit->getId()) {
333 $units = $unit->getUnit();
337 if ($resObj->getUnit()) {
338 $units = $resObj->getUnit()->getUnit();
342 $units =
'<select name="result_' . $result .
'_unit">';
343 $units .=
'<option value="-1">' . $this->
lng->txt(
"select_unit") .
'</option>';
344 foreach ($result_units as $unit) {
345 $units .=
'<option value="' . $unit->getId() .
'"';
346 if (array_key_exists($result, $userdata) &&
347 is_array($userdata[$result]) &&
348 array_key_exists(
'unit', $userdata[$result])) {
349 if ($userdata[$result][
"unit"] == $unit->getId()) {
350 $units .=
' selected="selected"';
353 $units .=
'>' . $unit->getUnit() .
'</option>';
355 $units .=
'</select>';
360 switch ($resObj->getResultType()) {
362 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_dec');
365 if ($frac_helper !==
'') {
366 $units .=
' ≈ ' . $frac_helper .
', ';
367 } elseif (is_array($userdata) &&
368 array_key_exists($result, $userdata) &&
369 array_key_exists(
'frac_helper', $userdata[$result]) &&
370 is_string($userdata[$result][
"frac_helper"])) {
371 if (!preg_match(
'-/-', $value)) {
372 $units .=
' ≈ ' . $userdata[$result][
"frac_helper"] .
', ';
375 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_frac');
378 if ($frac_helper !==
'') {
379 $units .=
' ≈ ' . $frac_helper .
', ';
380 } elseif (is_array($userdata) && isset($userdata[$result]) && isset($userdata[$result][
"frac_helper"]) && $userdata[$result][
"frac_helper"] !==
'') {
381 if (!preg_match(
'-/-', $value)) {
382 $units .=
' ≈ ' . $userdata[$result][
"frac_helper"] .
', ';
385 $units .=
' ' . $this->
lng->txt(
'expected_result_type') .
': ' . $this->
lng->txt(
'result_co_frac');
391 if ($graphicalOutput) {
394 if (is_array($userdata) &&
395 array_key_exists($result, $userdata) &&
396 is_array($userdata[$result])) {
397 if (array_key_exists(
'unit', $userdata[$result]) && $userdata[$result][
"unit"] > 0) {
401 if (isset($userdata[$result][
"value"])) {
402 $user_value = $userdata[$result][
"value"];
406 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution_image.html",
true,
true,
'Modules/TestQuestionPool');
408 $correctness_icon = $correctness_icons[
'not_correct'];
409 if ($resObj->isCorrect($this->getVariables(), $this->
getResults(), $user_value, $resunit)) {
410 $correctness_icon = $correctness_icons[
'correct'];
412 $template->setCurrentBlock(
"icon_ok");
413 $template->setVariable(
"ICON_OK", $correctness_icon);
414 $template->parseCurrentBlock();
416 $checkSign = $template->get();
419 if ($result_output) {
420 $template =
new ilTemplate(
"tpl.il_as_qpl_formulaquestion_output_solution_result.html",
true,
true,
'Modules/TestQuestionPool');
422 if (is_array($userdata) &&
423 array_key_exists($resObj->getResult(), $userdata) &&
424 array_key_exists(
'value', $userdata[$resObj->getResult()])) {
425 $found = $resObj->getResultInfo(
428 $userdata[$resObj->getResult()][
"value"],
429 $userdata[$resObj->getResult()][
"unit"] ?? null,
433 $found = $resObj->getResultInfo(
437 is_object($resObj->getUnit()) ? $resObj->getUnit()->getId() : null,
442 if ($resObj->getRatingSimple()) {
444 $resulttext .=
"n/a";
446 $resulttext .= $found[
'points'] .
" " . (($found[
'points'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points'));
449 $resulttext .= $this->
lng->txt(
"rated_sign") .
" " . (($found[
'sign']) ? $found[
'sign'] : 0) .
" " . (($found[
'sign'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points')) .
", ";
450 $resulttext .= $this->
lng->txt(
"rated_value") .
" " . (($found[
'value']) ? $found[
'value'] : 0) .
" " . (($found[
'value'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points')) .
", ";
451 $resulttext .= $this->
lng->txt(
"rated_unit") .
" " . (($found[
'unit']) ? $found[
'unit'] : 0) .
" " . (($found[
'unit'] == 1) ? $this->
lng->txt(
'point') : $this->
lng->txt(
'points'));
455 $template->setVariable(
"RESULT_OUTPUT", $resulttext);
457 $resultOutput = $template->get();
459 $text = preg_replace(
"/\\\$" . substr($result, 1) .
"(?![0-9]+)/", $input .
" " . $units .
" " . $checkSign .
" " . $resultOutput .
" " .
"\\1", $text);
468 return '<span class="ilc_qinput_TextInput solutionbox">' 472 $input =
'<input class="ilc_qinput_TextInput" type="text"';
473 $input .=
'spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"';
474 $input .=
'name="result_' . $result_key .
'"';
475 $input .=
' value="' . $result_value .
'"/>';
488 $resultunit = $result->getUnit();
490 foreach ($result_units as $unit) {
491 if (is_object($resultunit)) {
492 if ($resultunit->getId() != $unit->getId()) {
493 if ($resultunit->getBaseUnit() && $unit->getBaseUnit()) {
494 if ($resultunit->getBaseUnit() == $unit->getBaseUnit()) {
498 if ($resultunit->getBaseUnit()) {
499 if ($resultunit->getBaseUnit() == $unit->getId()) {
503 if ($unit->getBaseUnit()) {
504 if ($unit->getBaseUnit() == $resultunit->getId()) {
520 if (($this->title) and ($this->author) and ($this->question) and ($this->
getMaximumPoints() > 0)) {
534 $ilDB = $DIC[
'ilDB'];
543 $affectedRows =
$ilDB->manipulateF(
545 DELETE FROM il_qpl_qst_fq_var 546 WHERE question_fi = %s",
548 array($this->
getId())
551 foreach ($this->variables as $variable) {
552 $next_id =
$ilDB->nextId(
'il_qpl_qst_fq_var');
556 'variable_id' => array(
'integer', $next_id),
557 'question_fi' => array(
'integer', $this->
getId()),
558 'variable' => array(
'text', $variable->getVariable()),
559 'range_min' => array(
'float', ((strlen($variable->getRangeMin())) ? $variable->getRangeMin() : 0.0)),
560 'range_max' => array(
'float', ((strlen($variable->getRangeMax())) ? $variable->getRangeMax() : 0.0)),
561 'unit_fi' => array(
'integer', (is_object($variable->getUnit()) ? (
int) $variable->getUnit()->getId() : 0)),
562 'varprecision' => array(
'integer', (
int) $variable->getPrecision()),
563 'intprecision' => array(
'integer', (
int) $variable->getIntprecision()),
564 'range_min_txt' => array(
'text', $variable->getRangeMinTxt()),
565 'range_max_txt' => array(
'text', $variable->getRangeMaxTxt())
570 $affectedRows =
$ilDB->manipulateF(
571 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
573 array($this->
getId())
576 foreach ($this->results as $result) {
577 $next_id =
$ilDB->nextId(
'il_qpl_qst_fq_res');
578 if (is_object($result->getUnit())) {
579 $tmp_result_unit = $result->getUnit()->getId();
581 $tmp_result_unit = null;
584 $formula = str_replace(
",",
".", $result->getFormula());
586 $ilDB->insert(
"il_qpl_qst_fq_res", array(
587 "result_id" => array(
"integer", $next_id),
588 "question_fi" => array(
"integer", $this->
getId()),
589 "result" => array(
"text", $result->getResult()),
590 "range_min" => array(
"float", ((strlen($result->getRangeMin())) ? $result->getRangeMin() : 0)),
591 "range_max" => array(
"float", ((strlen($result->getRangeMax())) ? $result->getRangeMax() : 0)),
592 "tolerance" => array(
"float", ((strlen($result->getTolerance())) ? $result->getTolerance() : 0)),
593 "unit_fi" => array(
"integer", (
int) $tmp_result_unit),
594 "formula" => array(
"clob", $formula),
595 "resprecision" => array(
"integer", $result->getPrecision()),
596 "rating_simple" => array(
"integer", ($result->getRatingSimple()) ? 1 : 0),
597 "rating_sign" => array(
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingSign()),
598 "rating_value" => array(
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingValue()),
599 "rating_unit" => array(
"float", ($result->getRatingSimple()) ? 0 : $result->getRatingUnit()),
600 "points" => array(
"float", $result->getPoints()),
601 "result_type" => array(
'integer', (
int) $result->getResultType()),
602 "range_min_txt" => array(
"text", $result->getRangeMinTxt()),
603 "range_max_txt" => array(
"text", $result->getRangeMaxTxt())
608 $affectedRows =
$ilDB->manipulateF(
609 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
611 array($this->
getId())
613 foreach ($this->results as $result) {
615 $next_id =
$ilDB->nextId(
'il_qpl_qst_fq_res_unit');
616 $affectedRows =
$ilDB->manipulateF(
617 "INSERT INTO il_qpl_qst_fq_res_unit (result_unit_id, question_fi, result, unit_fi) VALUES (%s, %s, %s, %s)",
618 array(
'integer',
'integer',
'text',
'integer'),
622 $result->getResult(),
639 $ilDB = $DIC[
'ilDB'];
641 $result =
$ilDB->queryF(
642 "SELECT qpl_questions.* FROM qpl_questions WHERE question_id = %s",
646 if ($result->numRows() == 1) {
648 $this->
setId($question_id);
650 $this->
setComment((
string) $data[
"description"]);
671 include_once(
"./Services/RTE/classes/class.ilRTE.php");
675 $result =
$ilDB->queryF(
676 "SELECT * FROM il_qpl_qst_fq_var WHERE question_fi = %s",
680 if ($result->numRows() > 0) {
681 while ($data =
$ilDB->fetchAssoc($result)) {
683 $varObj->setRangeMinTxt($data[
'range_min_txt']);
684 $varObj->setRangeMaxTxt($data[
'range_max_txt']);
689 $result =
$ilDB->queryF(
690 "SELECT * FROM il_qpl_qst_fq_res WHERE question_fi = %s",
694 if ($result->numRows() > 0) {
695 while ($data =
$ilDB->fetchAssoc($result)) {
696 $resObj =
new assFormulaQuestionResult($data[
"result"], $data[
"range_min"], $data[
"range_max"], $data[
"tolerance"], $this->
getUnitrepository()->getUnit($data[
"unit_fi"]), $data[
"formula"], $data[
"points"], $data[
"resprecision"], $data[
"rating_simple"], $data[
"rating_sign"], $data[
"rating_value"], $data[
"rating_unit"]);
697 $resObj->setResultType($data[
'result_type']);
698 $resObj->setRangeMinTxt($data[
'range_min_txt']);
699 $resObj->setRangeMaxTxt($data[
'range_max_txt']);
705 $result =
$ilDB->queryF(
706 "SELECT * FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
710 if ($result->numRows() > 0) {
711 while ($data =
$ilDB->fetchAssoc($result)) {
713 $resObj = $this->
getResult($data[
"result"]);
718 parent::loadFromDb($question_id);
727 if ($this->
id <= 0) {
732 $this_id = $this->
getId();
736 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
740 if ((
int) $testObjId > 0) {
741 $clone->setObjId($testObjId);
761 $clone->unitrepository->cloneUnits($this_id, $clone->getId());
764 $clone->copyPageOfQuestion($this_id);
766 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
767 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
778 if ($this->
getId() <= 0) {
779 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
783 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
786 $source_questionpool_id = $this->
getObjId();
787 $clone->setObjId($target_questionpool_id);
793 $clone->unitrepository->cloneUnits(
$original_id, $clone->getId());
800 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
807 if ($this->
getId() <= 0) {
808 throw new RuntimeException(
'The question has not been saved. It cannot be duplicated');
811 include_once(
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
814 $sourceParentId = $this->
getObjId();
820 $clone->setObjId($targetParentId);
822 if ($targetQuestionTitle) {
823 $clone->setTitle($targetQuestionTitle);
828 $clone->copyPageOfQuestion($sourceQuestionId);
830 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
832 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
844 foreach ($this->results as $result) {
845 $points += $result->getPoints();
860 if (is_null($pass)) {
864 $user_solution = array();
865 foreach ($solutions as $idx => $solution_value) {
866 if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
867 $user_solution[$matches[1]] = $solution_value[
"value2"];
868 $varObj = $this->
getVariable($solution_value[
"value1"]);
869 $varObj->setValue($solution_value[
"value2"]);
870 } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
871 if (!array_key_exists($matches[1], $user_solution)) {
872 $user_solution[$matches[1]] = array();
874 $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
875 } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
876 if (!array_key_exists($matches[1], $user_solution)) {
877 $user_solution[$matches[1]] = array();
879 $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
886 $points += $result->getReachedPoints(
889 $user_solution[$result->getResult()][
"value"] ??
'',
890 $user_solution[$result->getResult()][
"unit"] ??
'',
891 $this->unitrepository->getUnits()
904 $v = isset($user_solution[$result->getResult()]) ? $user_solution[$result->getResult()] : null;
905 $u = isset($user_solution[$result->getResult() .
'_unit']) ? $user_solution[$result->getResult() .
'_unit'] : null;
907 $points += $result->getReachedPoints(
912 $this->unitrepository->getUnits()
923 $submittedValue = str_replace(
',',
'.', $submittedValue);
925 if (is_numeric($submittedValue)) {
929 if (preg_match(
'/^[-+]{0,1}\d+\/\d+$/', $submittedValue)) {
946 $ilDB = $DIC[
'ilDB'];
948 if (is_null($pass)) {
949 include_once
"./Modules/Test/classes/class.ilObjTest.php";
953 $entered_values =
false;
955 $this->
getProcessLocker()->executeUserSolutionUpdateLockOperation(
function () use (&$entered_values,
$ilDB, $active_id, $pass, $authorized) {
957 foreach ($solutionSubmit as
$key => $value) {
959 if (preg_match(
"/^result_(\\\$r\\d+)$/",
$key, $matches)) {
960 if (strlen($value)) {
961 $entered_values =
true;
964 $queryResult =
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " .
$ilDB->like(
'value1',
'clob', $matches[1]);
966 if ($this->
getStep() !== null) {
967 $queryResult .=
" AND step = " .
$ilDB->quote((
int) $this->
getStep(),
'integer') .
" ";
970 $result =
$ilDB->queryF(
972 array(
'integer',
'integer',
'integer',
'integer'),
973 array($active_id, $pass, $this->
getId(), (
int) $authorized)
975 if ($result->numRows()) {
976 while ($row =
$ilDB->fetchAssoc($result)) {
978 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
979 array(
'integer',
'integer'),
980 array($row[
'solution_id'], (
int) $authorized)
985 $this->
saveCurrentSolution($active_id, $pass, $matches[1], str_replace(
",",
".", $value), $authorized);
986 } elseif (preg_match(
"/^result_(\\\$r\\d+)_unit$/",
$key, $matches)) {
987 $queryResultUnit =
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND authorized = %s AND " .
$ilDB->like(
'value1',
'clob', $matches[1] .
"_unit");
989 if ($this->
getStep() !== null) {
990 $queryResultUnit .=
" AND step = " .
$ilDB->quote((
int) $this->
getStep(),
'integer') .
" ";
993 $result =
$ilDB->queryF(
995 array(
'integer',
'integer',
'integer',
'integer'),
996 array($active_id, $pass, $this->
getId(), (
int) $authorized)
998 if ($result->numRows()) {
999 while ($row =
$ilDB->fetchAssoc($result)) {
1001 "DELETE FROM tst_solutions WHERE solution_id = %s AND authorized = %s",
1002 array(
'integer',
'integer'),
1003 array($row[
'solution_id'], (
int) $authorized)
1008 $this->
saveCurrentSolution($active_id, $pass, $matches[1] .
"_unit", $value, $authorized);
1013 if ($entered_values) {
1014 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1018 "log_user_entered_values",
1020 ), $active_id, $this->
getId());
1023 include_once(
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1027 "log_user_not_entered_values",
1029 ), $active_id, $this->
getId());
1046 $ilDB = $DIC[
'ilDB'];
1049 'authorized' =>
false,
1050 'intermediate' =>
false 1054 SELECT authorized, COUNT(*) cnt 1056 WHERE active_fi = " .
$ilDB->quote($activeId,
'integer') .
" 1057 AND question_fi = " .
$ilDB->quote($this->
getId(),
'integer') .
" 1058 AND pass = " .
$ilDB->quote($pass,
'integer') .
" 1059 AND value1 like '\$r%' 1060 AND value2 is not null 1064 if ($this->
getStep() !== null) {
1074 while ($row =
$ilDB->fetchAssoc($result)) {
1075 if ($row[
'authorized']) {
1076 $return[
'authorized'] = $row[
'cnt'] > 0;
1078 $return[
'intermediate'] = $row[
'cnt'] > 0;
1095 $ilDB = $DIC[
'ilDB'];
1098 DELETE FROM tst_solutions 1099 WHERE active_fi = " .
$ilDB->quote($activeId,
'integer') .
" 1100 AND question_fi = " .
$ilDB->quote($this->
getId(),
'integer') .
" 1101 AND pass = " .
$ilDB->quote($pass,
'integer') .
" 1102 AND value1 like '\$r%' 1105 if ($this->
getStep() !== null) {
1120 if (preg_match(
"/^result_(\\\$r\\d+)$/",
$key, $matches)) {
1121 $userSolution[$matches[1]] = $val;
1122 } elseif (preg_match(
"/^result_(\\\$r\\d+)_unit$/",
$key, $matches)) {
1123 $userSolution[$matches[1] .
"_unit"] = $val;
1136 return "assFormulaQuestion";
1165 $ilDB = $DIC[
'ilDB'];
1167 $affectedRows =
$ilDB->manipulateF(
1168 "DELETE FROM il_qpl_qst_fq_var WHERE question_fi = %s",
1173 $affectedRows =
$ilDB->manipulateF(
1174 "DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s",
1179 $affectedRows =
$ilDB->manipulateF(
1180 "DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s",
1185 $affectedRows =
$ilDB->manipulateF(
1186 "DELETE FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
1191 $affectedRows =
$ilDB->manipulateF(
1192 "DELETE FROM il_qpl_qst_fq_unit WHERE question_fi = %s",
1204 $text = parent::getRTETextWithMediaObjects();
1213 parent::setExportDetailsXLS($worksheet, $startrow, $active_id, $pass);
1218 foreach ($solution as $solutionvalue) {
1219 $worksheet->
setCell($startrow +
$i, 0, $solutionvalue[
"value1"]);
1221 if (strpos($solutionvalue[
"value1"],
"_unit")) {
1223 if (is_object($unit)) {
1224 $worksheet->
setCell($startrow +
$i, 2, $unit->getUnit());
1227 $worksheet->
setCell($startrow +
$i, 2, $solutionvalue[
"value2"]);
1229 if (preg_match(
"/(\\\$v\\d+)/", $solutionvalue[
"value1"], $matches)) {
1230 $var = $this->
getVariable($solutionvalue[
"value1"]);
1231 if (is_object($var) && (is_object($var->getUnit()))) {
1232 $worksheet->
setCell($startrow +
$i, 3, $var->getUnit()->getUnit());
1238 return $startrow +
$i + 1;
1248 $user_solution = array();
1250 foreach ($solutions as $idx => $solution_value) {
1251 if (preg_match(
"/^(\\\$v\\d+)$/", $solution_value[
"value1"], $matches)) {
1252 $user_solution[$matches[1]] = $solution_value[
"value2"];
1254 $varObj->setValue($solution_value[
"value2"]);
1255 } elseif (preg_match(
"/^(\\\$r\\d+)$/", $solution_value[
"value1"], $matches)) {
1256 if (!array_key_exists($matches[1], $user_solution)) {
1257 $user_solution[$matches[1]] = array();
1259 $user_solution[$matches[1]][
"value"] = $solution_value[
"value2"];
1260 } elseif (preg_match(
"/^(\\\$r\\d+)_unit$/", $solution_value[
"value1"], $matches)) {
1261 if (!array_key_exists($matches[1], $user_solution)) {
1262 $user_solution[$matches[1]] = array();
1264 $user_solution[$matches[1]][
"unit"] = $solution_value[
"value2"];
1270 if (is_object($result->getUnit())) {
1271 $user_solution[$result->getResult()][
"unit"] = $result->getUnit()->getId();
1272 $user_solution[$result->getResult()][
"value"] = $resVal;
1273 } elseif ($result->getUnit() == null) {
1277 $available_units = $result->getAvailableResultUnits(
parent::getId());
1278 $result_name = $result->getResult();
1280 $check_unit =
false;
1281 if (array_key_exists($result_name, $available_units) &&
1282 $available_units[$result_name] !== null) {
1283 $check_unit = in_array($user_solution[$result_name][
'unit'], $available_units[$result_name]);
1286 if ($check_unit ==
true) {
1292 $user_solution[$result->getResult()][
"value"] =
ilMath::_div($resVal, $unit_factor, 55);
1294 $user_solution[$result->getResult()][
"value"] = 0;
1300 if (is_array($value)) {
1301 $user_solution[$result->getResult()][
"value"] = $value[0];
1302 $user_solution[$result->getResult()][
"frac_helper"] = $value[1];
1304 $user_solution[$result->getResult()][
"value"] = $value;
1305 $user_solution[$result->getResult()][
"frac_helper"] = null;
1308 $user_solution[$result->getResult()][
"value"] = round($user_solution[$result->getResult()][
"value"], $result->getPrecision());
1318 return $user_solution;
1324 $this->unitrepository->setConsumerId($this->
getId());
1348 $solutionSubmit = [];
1350 $post = $this->dic->http()->wrapper()->post();
1353 $key =
"result_$index";
1355 $value =
$post->retrieve(
1357 $this->dic->refinery()->kindlyTo()->string()
1360 $solutionSubmit[
$key] = $value;
1363 $value =
$post->retrieve(
1365 $this->dic->refinery()->kindlyTo()->string()
1367 $solutionSubmit[
$key .
"_unit"] = $value;
1370 return $solutionSubmit;
1377 $this->tpl->setOnScreenMessage(
1379 $this->
lng->txt(
"err_no_numeric_value"),
1427 $ilDB = $DIC[
'ilDB'];
1432 if ($maxStep !== null) {
1434 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1435 array(
"integer",
"integer",
"integer",
'integer'),
1436 array($active_id, $pass, $this->
getId(), $maxStep)
1440 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1441 array(
"integer",
"integer",
"integer"),
1442 array($active_id, $pass, $this->
getId())
1447 if (strstr($row[
"value1"],
'$r') && $row[
"value2"] != null) {
1448 $result->addKeyValue(str_replace(
'$r',
"", $row[
"value1"]), $row[
"value2"]);
1455 $result->setReachedPercentage((
$points / $max_points) * 100);
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($active_id, $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)
Abstract basic class which is to be extended by the concrete assessment question type classes...
getColumnCoord(int $a_col)
Get column "name" from number.
ensureNonNegativePoints($points)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getOriginalId(int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getParticipantsSolution()
getUserQuestionResult($active_id, $pass)
Get the user solution for a question by active_id and the test pass.
setComment(string $comment="")
float $points
The maximum available points for the question.
setParticipantsSolution($participantSolution)
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
setBold(string $a_coords)
Set cell(s) to bold.
static _enabledAssessmentLogging()
purifyAndPrepareTextAreaOutput(string $content)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static logAction(string $logtext, int $active_id, int $question_id)
const NumericResultExpression
string $question
The question text.
static getOperatorsByExpression($expression)
deductHintPointsFromReachedPoints(ilAssQuestionPreviewSession $previewSession, $reachedPoints)
saveQuestionDataToDb(int $original_id=-1)
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