ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAssErrorTextCorrectionsInputGUI.php
Go to the documentation of this file.
1 <?php
2 
28 {
29  public function setValue($a_value): void
30  {
31  foreach ($this->forms_helper->transformPoints($a_value) as $index => $points) {
32  $this->values[$index] = $this->values[$index]->withPoints($points);
33  }
34  }
35 
36  public function checkInput(): bool
37  {
38  $data = $this->raw($this->getPostVar());
39  $result = $this->forms_helper->checkPointsInput($data, $this->getRequired());
40 
41  if (!is_array($result)) {
42  $this->setAlert($this->lng->txt($result));
43  return false;
44  }
45 
46  foreach ($result as $points) {
47  if ($points < 0) {
48  $this->setAlert($this->lng->txt('positive_numbers_required'));
49  return false;
50  }
51  }
52 
53  return $this->checkSubItemsInput();
54  }
55 
56  public function insert(ilTemplate $a_tpl): void
57  {
58  global $DIC;
59  $lng = $DIC['lng'];
60 
61  $tpl = new ilTemplate('tpl.prop_errortextcorrection_input.html', true, true, 'components/ILIAS/TestQuestionPool');
62  $i = 0;
63  foreach ($this->values as $value) {
64  $tpl->setCurrentBlock('prop_points_propval');
65  $tpl->setVariable('PROPERTY_VALUE', ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
66  $tpl->parseCurrentBlock();
67 
68  $tpl->setCurrentBlock('row');
69 
70  $tpl->setVariable('TEXT_WRONG', ilLegacyFormElementsUtil::prepareFormOutput($value->getTextWrong()));
71  $tpl->setVariable('TEXT_CORRECT', ilLegacyFormElementsUtil::prepareFormOutput($value->getTextCorrect()));
72 
73  $class = ($i % 2 === 0) ? 'even' : 'odd';
74  if ($i === 0) {
75  $class .= ' first';
76  }
77  if ($i === count($this->values) - 1) {
78  $class .= ' last';
79  }
80  $tpl->setVariable('ROW_CLASS', $class);
81  $tpl->setVariable('ROW_NUMBER', $i);
82 
83  $tpl->setVariable('KEY_SIZE', $this->getKeySize());
84  $tpl->setVariable('KEY_ID', $this->getPostVar() . "[key][$i]");
85  $tpl->setVariable('KEY_MAXLENGTH', $this->getKeyMaxlength());
86 
87  $tpl->setVariable('VALUE_SIZE', $this->getValueSize());
88  $tpl->setVariable('VALUE_ID', $this->getPostVar() . "[value][$i]");
89  $tpl->setVariable('VALUE_MAXLENGTH', $this->getValueMaxlength());
90 
91  $tpl->setVariable('POST_VAR', $this->getPostVar());
92 
93  $tpl->parseCurrentBlock();
94 
95  $i++;
96  }
97  $tpl->setVariable('ELEMENT_ID', $this->getPostVar());
98  $tpl->setVariable('KEY_TEXT', $this->getKeyName());
99  $tpl->setVariable('VALUE_TEXT', $this->getValueName());
100  $tpl->setVariable('POINTS_TEXT', $lng->txt('points'));
101 
102  $a_tpl->setCurrentBlock('prop_generic');
103  $a_tpl->setVariable('PROP_GENERIC', $tpl->get());
104  $a_tpl->parseCurrentBlock();
105  }
106 }
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)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a key value pair wizard property in a property form.