ILIAS  release_8 Revision v8.24
class.ilAssMultipleChoiceCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
27{
31 protected $qstObject;
32
33 public function setValue($a_value): void
34 {
35 if (is_array($a_value)) {
36 if (is_array($a_value['points']) && is_array($a_value['points_unchecked'])) {
37 foreach ($this->values as $index => $value) {
38 $this->values[$index]->setPoints($a_value['points'][$index]);
39 $this->values[$index]->setPointsUnchecked($a_value['points_unchecked'][$index]);
40 }
41 }
42 }
43 }
44
45 public function checkInput(): bool
46 {
47 global $DIC;
48 $lng = $DIC['lng'];
49
50 $foundvalues = $_POST[$this->getPostVar()];
51 if (is_array($foundvalues)) {
52 // check points
53 $max = 0;
54 if (is_array($foundvalues['points'])) {
55 foreach ($foundvalues['points'] as $points) {
56 $points = str_replace(',', '.', $points);
57 if ($points > $max) {
58 $max = $points;
59 }
60 if (((strlen($points)) == 0) || (!is_numeric($points))) {
61 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
62 return false;
63 }
64 }
65 foreach ($foundvalues['points_unchecked'] as $points) {
66 if ($points > $max) {
67 $max = $points;
68 }
69 if (((strlen($points)) == 0) || (!is_numeric($points))) {
70 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
71 return false;
72 }
73 }
74 }
75 if ($max == 0) {
76 $this->setAlert($lng->txt("enter_enough_positive_points"));
77 return false;
78 }
79 } else {
80 $this->setAlert($lng->txt("msg_input_is_required"));
81 return false;
82 }
83
84 return $this->checkSubItemsInput();
85 }
86
87 public function insert(ilTemplate $a_tpl): void
88 {
89 global $DIC; /* @var ILIAS\DI\Container $DIC */
90 $lng = $DIC->language();
91
92 $tpl = new ilTemplate("tpl.prop_multiplechoicecorrection_input.html", true, true, "Modules/TestQuestionPool");
93
94 $i = 0;
95
96 foreach ($this->values as $value) {
97 if ($this->qstObject->isSingleline()) {
98 if (strlen($value->getImage())) {
99 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
100 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
101 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
102 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
103 }
104 }
105
106 $tpl->setCurrentBlock('image');
107 $tpl->setVariable('SRC_IMAGE', $imagename);
108 $tpl->setVariable('IMAGE_NAME', $value->getImage());
109 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
110 $tpl->parseCurrentBlock();
111 } else {
112 $tpl->setCurrentBlock('image');
113 $tpl->touchBlock('image');
114 $tpl->parseCurrentBlock();
115 }
116 }
117
118 $tpl->setCurrentBlock("answer");
119 $tpl->setVariable("ANSWER", $value->getAnswertext());
120 $tpl->parseCurrentBlock();
121
122 $tpl->setCurrentBlock("row");
123 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
124 $tpl->setVariable("POINTS_ROW_NUMBER", $i);
125 $tpl->setVariable(
126 "PROPERTY_VALUE_CHECKED",
127 ilLegacyFormElementsUtil::prepareFormOutput($value->getPointsChecked())
128 );
129 $tpl->setVariable(
130 "PROPERTY_VALUE_UNCHECKED",
132 );
133 $tpl->parseCurrentBlock();
134
135 $i++;
136 }
137
138 if ($this->qstObject->isSingleline()) {
139 $tpl->setCurrentBlock("image_heading");
140 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
141 $tpl->setVariable("TXT_MAX_SIZE", ilFileUtils::getFileSizeInfo());
142 $tpl->parseCurrentBlock();
143 }
144
145 $tpl->setCurrentBlock("points_heading");
146 $tpl->setVariable("POINTS_CHECKED_TEXT", $lng->txt('points_checked'));
147 $tpl->setVariable("POINTS_UNCHECKED_TEXT", $lng->txt('points_unchecked'));
148 $tpl->parseCurrentBlock();
149
150 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
151 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
152
153 $a_tpl->setCurrentBlock("prop_generic");
154 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
155 $a_tpl->parseCurrentBlock();
156 }
157}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static getFileSizeInfo()
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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)
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41