ILIAS  release_8 Revision v8.24
class.ilAssSingleChoiceCorrectionsInputGUI.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'])) {
37 foreach ($a_value['points'] as $index => $value) {
38 $this->values[$index]->setPoints($value);
39 }
40 }
41 }
42 }
43
44 public function checkInput(): bool
45 {
46 global $DIC;
47 $lng = $DIC['lng'];
48
49 $foundvalues = $_POST[$this->getPostVar()];
50 if (is_array($foundvalues)) {
51 // check points
52 $max = 0;
53 if (is_array($foundvalues['points'])) {
54 foreach ($foundvalues['points'] as $points) {
55 $points = str_replace(',', '.', $points);
56 if ($points > $max) {
57 $max = $points;
58 }
59 if (((strlen($points)) == 0) || (!is_numeric($points))) {
60 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
61 return false;
62 }
63 }
64 }
65 if ($max == 0) {
66 $this->setAlert($lng->txt("enter_enough_positive_points"));
67 return false;
68 }
69 } else {
70 $this->setAlert($lng->txt("msg_input_is_required"));
71 return false;
72 }
73
74 return $this->checkSubItemsInput();
75 }
76
77 public function insert(ilTemplate $a_tpl): void
78 {
79 global $DIC; /* @var ILIAS\DI\Container $DIC */
80 $lng = $DIC->language();
81
82 $tpl = new ilTemplate("tpl.prop_singlechoicecorrection_input.html", true, true, "Modules/TestQuestionPool");
83
84 $i = 0;
85
86 if ($this->values === null) {
87 $this->values = $this->value;
88 }
89
90 foreach ($this->values as $value) {
91 if ($this->qstObject->isSingleline()) {
92 if (strlen($value->getImage())) {
93 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
94 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
95 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
96 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
97 }
98 }
99
100 $tpl->setCurrentBlock('image');
101 $tpl->setVariable('SRC_IMAGE', $imagename);
102 $tpl->setVariable('IMAGE_NAME', $value->getImage());
103 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
104 $tpl->parseCurrentBlock();
105 } else {
106 $tpl->setCurrentBlock('image');
107 $tpl->touchBlock('image');
108 $tpl->parseCurrentBlock();
109 }
110 }
111
112 $tpl->setCurrentBlock("answer");
113 $tpl->setVariable("ANSWER", $value->getAnswertext());
114 $tpl->parseCurrentBlock();
115
116 $tpl->setCurrentBlock("prop_points_propval");
117 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
118 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
119 $tpl->parseCurrentBlock();
120
121 $tpl->setCurrentBlock("row");
122 $tpl->parseCurrentBlock();
123 }
124
125 if ($this->qstObject->isSingleline()) {
126 $tpl->setCurrentBlock("image_heading");
127 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
128 $tpl->setVariable("TXT_MAX_SIZE", ilFileUtils::getFileSizeInfo());
129 $tpl->parseCurrentBlock();
130 }
131
132 $tpl->setCurrentBlock("points_heading");
133 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
134 $tpl->parseCurrentBlock();
135
136 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
137 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
138
139 $a_tpl->setCurrentBlock("prop_generic");
140 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
141 $a_tpl->parseCurrentBlock();
142 }
143}
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