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