ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  include_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
52  if (is_array($a_value['key'])) {
53  foreach ($a_value['key'] as $idx => $key) {
54  $this->values[] = new assAnswerErrorText($key, $a_value['value'][$idx], (float) str_replace(",", ".", $a_value['points'][$idx]));
55  }
56  }
57  }
58  }
59 
65  public function setKeySize($a_size): void
66  {
67  $this->key_size = $a_size;
68  }
69 
75  public function getKeySize(): int
76  {
77  return $this->key_size;
78  }
79 
85  public function setValueSize($a_size): void
86  {
87  $this->value_size = $a_size;
88  }
89 
95  public function getValueSize(): int
96  {
97  return $this->value_size;
98  }
99 
105  public function setKeyMaxlength($a_maxlength): void
106  {
107  $this->key_maxlength = $a_maxlength;
108  }
109 
115  public function getKeyMaxlength(): int
116  {
117  return $this->key_maxlength;
118  }
119 
125  public function setValueMaxlength($a_maxlength): void
126  {
127  $this->value_maxlength = $a_maxlength;
128  }
129 
135  public function getValueMaxlength(): int
136  {
137  return $this->value_maxlength;
138  }
139 
145  public function setValueName($a_name): void
146  {
147  $this->value_name = $a_name;
148  }
149 
155  public function getValueName(): string
156  {
157  return $this->value_name;
158  }
159 
165  public function setKeyName($a_name): void
166  {
167  $this->key_name = $a_name;
168  }
169 
175  public function getKeyName(): string
176  {
177  return $this->key_name;
178  }
179 
185  public function setValues($a_values): void
186  {
187  $this->values = $a_values;
188  }
189 
195  public function getValues(): array
196  {
197  return $this->values;
198  }
199 
204  public function checkInput(): bool
205  {
206  global $DIC;
207  $lng = $DIC['lng'];
208 
209  if (isset($_POST[$this->getPostVar()]) && is_array($_POST[$this->getPostVar()])) {
210  $foundvalues = ilArrayUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
211  } else {
212  $foundvalues = $_POST[$this->getPostVar()] ?? null;
213  }
214  $max_points = 0;
215 
216  if (is_array($foundvalues) && count($foundvalues) > 0) {
217  // check answers
218  if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
219  foreach ($foundvalues['key'] as $val) {
220  if ($this->getRequired() && (strlen($val)) == 0) {
221  $this->setAlert($lng->txt("msg_input_is_required"));
222  return false;
223  }
224  }
225  foreach ($foundvalues['value'] as $val) {
226  if ($this->getRequired() && (strlen($val)) == 0) {
227  $this->setAlert($lng->txt("msg_input_is_required"));
228  return false;
229  }
230  }
231  foreach ($foundvalues['points'] as $val) {
232  $val_num = str_replace(",", ".", $val);
233  if ($this->getRequired() && (strlen($val)) == 0) {
234  $this->setAlert($lng->txt("msg_input_is_required"));
235  return false;
236  }
237  if (!is_numeric($val_num)) {
238  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
239  return false;
240  }
241  if ($val_num <= 0) {
242  $this->setAlert($lng->txt("positive_numbers_required"));
243  return false;
244  }
245  }
246  } else {
247  if ($this->getRequired()) {
248  $this->setAlert($lng->txt("msg_input_is_required"));
249  return false;
250  }
251  }
252  } else {
253  $this->setAlert($lng->txt('errortext_info'));
254  return false;
255  }
256 
257  return $this->checkSubItemsInput();
258  }
259 
264  public function insert(ilTemplate $a_tpl): void
265  {
266  global $DIC;
267  $lng = $DIC['lng'];
268 
269  $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
270  $i = 0;
271  foreach ($this->values as $value) {
272  if (is_object($value)) {
273  if (strlen($value->getTextWrong())) {
274  $tpl->setCurrentBlock("prop_key_propval");
275  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getTextWrong()));
276  $tpl->parseCurrentBlock();
277  }
278  if (strlen($value->getTextCorrect())) {
279  $tpl->setCurrentBlock("prop_value_propval");
280  $tpl->setVariable(
281  "PROPERTY_VALUE",
282  ilLegacyFormElementsUtil::prepareFormOutput($value->getTextCorrect())
283  );
284  $tpl->parseCurrentBlock();
285  }
286  if (strlen($value->getPoints())) {
287  $tpl->setCurrentBlock("prop_points_propval");
288  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
289  $tpl->parseCurrentBlock();
290  }
291  }
292 
293  $tpl->setCurrentBlock("row");
294  $class = ($i % 2 == 0) ? "even" : "odd";
295  if ($i == 0) {
296  $class .= " first";
297  }
298  if ($i == count($this->values) - 1) {
299  $class .= " last";
300  }
301  $tpl->setVariable("ROW_CLASS", $class);
302  $tpl->setVariable("ROW_NUMBER", $i);
303 
304  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
305  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
306  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
307 
308  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
309  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
310  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
311 
312  $tpl->setVariable("POST_VAR", $this->getPostVar());
313 
314  $tpl->parseCurrentBlock();
315 
316  $i++;
317  }
318  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
319  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
320  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
321  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
322 
323  $a_tpl->setCurrentBlock("prop_generic");
324  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
325  $a_tpl->parseCurrentBlock();
326  }
327 }
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.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
string $key
Consumer key/client ID value.
Definition: System.php:193
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
insert(ilTemplate $a_tpl)
Insert property html.