ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilAssMultipleChoiceCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
2
28{
32 protected $qstObject;
33
34 public function setValue($a_value): void
35 {
36 $points = $this->forms_helper->transformPoints($a_value, 'points');
37 $points_unchecked = $this->forms_helper->transformPoints($a_value, 'points_unchecked');
38
39 foreach ($this->values as $index => $value) {
40 if ($value === null) {
41 return;
42 }
43
44 $this->values[$index]->setPoints($points[$index] ?? 0.0);
45 $this->values[$index]->setPointsUnchecked($points_unchecked[$index] ?? 0.0);
46 }
47 }
48
49 public function checkInput(): bool
50 {
51 $data = $this->raw($this->getPostVar());
52
53 $result = $this->forms_helper->checkPointsInputEnoughPositive($data, $this->getRequired(), 'points');
54 if (!is_array($result)) {
55 $this->setAlert($this->lng->txt($result));
56 return false;
57 }
58
59 $result = $this->forms_helper->checkPointsInput($data, $this->getRequired(), 'points_unchecked');
60 if (!is_array($result)) {
61 $this->setAlert($this->lng->txt($result));
62 return false;
63 }
64
65 return $this->checkSubItemsInput();
66 }
67
68 public function insert(ilTemplate $a_tpl): void
69 {
70 $tpl = new ilTemplate("tpl.prop_multiplechoicecorrection_input.html", true, true, "components/ILIAS/TestQuestionPool");
71
72 $i = 0;
73 foreach ($this->values as $value) {
74 if ($this->qstObject->isSingleline()) {
75 if ($value->hasImage()) {
76 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
77 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
78 if (file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
79 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
80 }
81 }
82
83 $tpl->setCurrentBlock('image');
84 $tpl->setVariable('SRC_IMAGE', $imagename);
85 $tpl->setVariable('IMAGE_NAME', $value->getImage());
86 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
87 $tpl->parseCurrentBlock();
88 } else {
89 $tpl->setCurrentBlock('image');
90 $tpl->touchBlock('image');
91 $tpl->parseCurrentBlock();
92 }
93 }
94
95 $tpl->setCurrentBlock("answer");
96 $tpl->setVariable("ANSWER", $value->getAnswertext());
97 $tpl->parseCurrentBlock();
98
99 $tpl->setCurrentBlock("row");
100 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
101 $tpl->setVariable("POINTS_ROW_NUMBER", $i);
102 $tpl->setVariable(
103 "PROPERTY_VALUE_CHECKED",
105 );
106 $tpl->setVariable(
107 "PROPERTY_VALUE_UNCHECKED",
109 );
110 $tpl->parseCurrentBlock();
111
112 $i++;
113 }
114
115 if ($this->qstObject->isSingleline()) {
116 $tpl->setCurrentBlock("image_heading");
117 $tpl->setVariable("ANSWER_IMAGE", $this->lng->txt('answer_image'));
118 $tpl->setVariable("TXT_MAX_SIZE", ilFileUtils::getFileSizeInfo());
119 $tpl->parseCurrentBlock();
120 }
121
122 $tpl->setCurrentBlock("points_heading");
123 $tpl->setVariable("POINTS_CHECKED_TEXT", $this->lng->txt('points_checked'));
124 $tpl->setVariable("POINTS_UNCHECKED_TEXT", $this->lng->txt('points_unchecked'));
125 $tpl->parseCurrentBlock();
126
127 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
128 $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer_text'));
129
130 $a_tpl->setCurrentBlock("prop_generic");
131 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
132 $a_tpl->parseCurrentBlock();
133 }
134}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
static getFileSizeInfo()
static prepareFormOutput($a_str, bool $a_strip=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)