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