ILIAS  release_8 Revision v8.24
class.ilAssErrorTextCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 public function setValue($a_value): void
30 {
31 if (is_array($a_value)) {
32 include_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
33 if (is_array($a_value['points'])) {
34 foreach ($this->values as $idx => $key) {
35 $this->values[$idx] = $this->values[$idx]->withPoints(
36 str_replace(",", ".", $a_value['points'][$idx])
37 );
38 }
39 }
40 }
41 }
42
43 public function checkInput(): bool
44 {
45 $foundvalues = $_POST[$this->getPostVar()];
46
47 if (!isset($foundvalues['points'])
48 || !is_array($foundvalues['points'])) {
49 $this->setAlert($this->lng->txt("msg_input_is_required"));
50 return false;
51 }
52
53 foreach ($foundvalues['points'] as $val) {
54 if ($this->getRequired() && (strlen($val)) == 0) {
55 $this->setAlert($this->lng->txt("msg_input_is_required"));
56 return false;
57 }
58 if (!is_numeric(str_replace(",", ".", $val))) {
59 $this->setAlert($this->lng->txt("form_msg_numeric_value_required"));
60 return false;
61 }
62 if ((float) $val <= 0) {
63 $this->setAlert($this->lng->txt("positive_numbers_required"));
64 return false;
65 }
66 }
67
68 return $this->checkSubItemsInput();
69 }
70
71 public function insert(ilTemplate $a_tpl): void
72 {
73 global $DIC;
74 $lng = $DIC['lng'];
75
76 $tpl = new ilTemplate("tpl.prop_errortextcorrection_input.html", true, true, "Modules/TestQuestionPool");
77 $i = 0;
78 foreach ($this->values as $value) {
79 $tpl->setCurrentBlock("prop_points_propval");
80 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
81 $tpl->parseCurrentBlock();
82
83 $tpl->setCurrentBlock("row");
84
85 $tpl->setVariable("TEXT_WRONG", ilLegacyFormElementsUtil::prepareFormOutput($value->getTextWrong()));
86 $tpl->setVariable("TEXT_CORRECT", ilLegacyFormElementsUtil::prepareFormOutput($value->getTextCorrect()));
87
88 $class = ($i % 2 == 0) ? "even" : "odd";
89 if ($i == 0) {
90 $class .= " first";
91 }
92 if ($i == count($this->values) - 1) {
93 $class .= " last";
94 }
95 $tpl->setVariable("ROW_CLASS", $class);
96 $tpl->setVariable("ROW_NUMBER", $i);
97
98 $tpl->setVariable("KEY_SIZE", $this->getKeySize());
99 $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
100 $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
101
102 $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
103 $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
104 $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
105
106 $tpl->setVariable("POST_VAR", $this->getPostVar());
107
108 $tpl->parseCurrentBlock();
109
110 $i++;
111 }
112 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
113 $tpl->setVariable("KEY_TEXT", $this->getKeyName());
114 $tpl->setVariable("VALUE_TEXT", $this->getValueName());
115 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
116
117 $a_tpl->setCurrentBlock("prop_generic");
118 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
119 $a_tpl->parseCurrentBlock();
120 }
121}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
insert(ilTemplate $a_tpl)
Insert property html.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
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
$i
Definition: metadata.php:41
string $key
Consumer key/client ID value.
Definition: System.php:193