ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilErrorTextWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected $values = array();
29  protected $key_size = 20;
30  protected $value_size = 20;
31  protected $key_maxlength = 255;
32  protected $value_maxlength = 150;
33  protected $key_name = "";
34  protected $value_name = "";
35 
42  public function __construct($a_title = "", $a_postvar = "")
43  {
44  parent::__construct($a_title, $a_postvar);
45  }
46 
47  public function setValue($a_value): void
48  {
49  $this->values = array();
50  if (is_array($a_value)) {
51  if (is_array($a_value['key'])) {
52  foreach ($a_value['key'] as $idx => $key) {
53  $this->values[] = new assAnswerErrorText($key, $a_value['value'][$idx], (float) str_replace(",", ".", $a_value['points'][$idx]));
54  }
55  }
56  }
57  }
58 
64  public function setKeySize($a_size): void
65  {
66  $this->key_size = $a_size;
67  }
68 
74  public function getKeySize(): int
75  {
76  return $this->key_size;
77  }
78 
84  public function setValueSize($a_size): void
85  {
86  $this->value_size = $a_size;
87  }
88 
94  public function getValueSize(): int
95  {
96  return $this->value_size;
97  }
98 
104  public function setKeyMaxlength($a_maxlength): void
105  {
106  $this->key_maxlength = $a_maxlength;
107  }
108 
114  public function getKeyMaxlength(): int
115  {
116  return $this->key_maxlength;
117  }
118 
124  public function setValueMaxlength($a_maxlength): void
125  {
126  $this->value_maxlength = $a_maxlength;
127  }
128 
134  public function getValueMaxlength(): int
135  {
136  return $this->value_maxlength;
137  }
138 
144  public function setValueName($a_name): void
145  {
146  $this->value_name = $a_name;
147  }
148 
154  public function getValueName(): string
155  {
156  return $this->value_name;
157  }
158 
164  public function setKeyName($a_name): void
165  {
166  $this->key_name = $a_name;
167  }
168 
174  public function getKeyName(): string
175  {
176  return $this->key_name;
177  }
178 
184  public function setValues($a_values): void
185  {
186  $this->values = $a_values;
187  }
188 
194  public function getValues(): array
195  {
196  return $this->values;
197  }
198 
203  public function checkInput(): bool
204  {
205  global $DIC;
206  $lng = $DIC['lng'];
207 
208  if (isset($_POST[$this->getPostVar()]) && is_array($_POST[$this->getPostVar()])) {
209  $foundvalues = ilArrayUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
210  } else {
211  $foundvalues = $_POST[$this->getPostVar()] ?? null;
212  }
213  $max_points = 0;
214 
215  if (is_array($foundvalues) && count($foundvalues) > 0) {
216  // check answers
217  if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
218  foreach ($foundvalues['key'] as $val) {
219  if ($this->getRequired() && (strlen($val)) == 0) {
220  $this->setAlert($lng->txt("msg_input_is_required"));
221  return false;
222  }
223  }
224  foreach ($foundvalues['value'] as $val) {
225  if ($this->getRequired() && (strlen($val)) == 0) {
226  $this->setAlert($lng->txt("msg_input_is_required"));
227  return false;
228  }
229  }
230  foreach ($foundvalues['points'] as $val) {
231  $val_num = str_replace(",", ".", $val);
232  if ($this->getRequired() && (strlen($val)) == 0) {
233  $this->setAlert($lng->txt("msg_input_is_required"));
234  return false;
235  }
236  if (!is_numeric($val_num)) {
237  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
238  return false;
239  }
240  if ($val_num <= 0) {
241  $this->setAlert($lng->txt("positive_numbers_required"));
242  return false;
243  }
244  }
245  } else {
246  if ($this->getRequired()) {
247  $this->setAlert($lng->txt("msg_input_is_required"));
248  return false;
249  }
250  }
251  } else {
252  $this->setAlert($lng->txt('errortext_info'));
253  return false;
254  }
255 
256  return $this->checkSubItemsInput();
257  }
258 
263  public function insert(ilTemplate $a_tpl): void
264  {
265  global $DIC;
266  $lng = $DIC['lng'];
267 
268  $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
269  $i = 0;
270  foreach ($this->values as $value) {
271  if (is_object($value)) {
272  if (strlen($value->getTextWrong())) {
273  $tpl->setCurrentBlock("prop_key_propval");
274  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getTextWrong()));
275  $tpl->parseCurrentBlock();
276  }
277  if (strlen($value->getTextCorrect())) {
278  $tpl->setCurrentBlock("prop_value_propval");
279  $tpl->setVariable(
280  "PROPERTY_VALUE",
281  ilLegacyFormElementsUtil::prepareFormOutput($value->getTextCorrect())
282  );
283  $tpl->parseCurrentBlock();
284  }
285  if (strlen($value->getPoints())) {
286  $tpl->setCurrentBlock("prop_points_propval");
287  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
288  $tpl->parseCurrentBlock();
289  }
290  }
291 
292  $tpl->setCurrentBlock("row");
293  $class = ($i % 2 == 0) ? "even" : "odd";
294  if ($i == 0) {
295  $class .= " first";
296  }
297  if ($i == count($this->values) - 1) {
298  $class .= " last";
299  }
300  $tpl->setVariable("ROW_CLASS", $class);
301  $tpl->setVariable("ROW_NUMBER", $i);
302 
303  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
304  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
305  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
306 
307  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
308  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
309  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
310 
311  $tpl->setVariable("POST_VAR", $this->getPostVar());
312 
313  $tpl->parseCurrentBlock();
314 
315  $i++;
316  }
317  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
318  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
319  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
320  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
321 
322  $a_tpl->setCurrentBlock("prop_generic");
323  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
324  $a_tpl->parseCurrentBlock();
325  }
326 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
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...
__construct($a_title="", $a_postvar="")
Constructor.
checkInput()
Check input, strip slashes etc.
setKeyMaxlength($a_maxlength)
Set key maxlength.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareFormOutput($a_str, bool $a_strip=false)
global $DIC
Definition: feed.php:28
setValueMaxlength($a_maxlength)
Set value maxlength.
__construct(VocabulariesInterface $vocabularies)
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...
insert(ilTemplate $a_tpl)
Insert property html.