ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilErrorTextWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
30 {
31  protected $values = [];
32  protected $key_size = 20;
33  protected $value_size = 20;
34  protected $key_maxlength = 255;
35  protected $value_maxlength = 150;
36  protected $key_name = "";
37  protected $value_name = "";
38 
40 
47  public function __construct($a_title = "", $a_postvar = "")
48  {
49  parent::__construct($a_title, $a_postvar);
50  $this->forms_helper = new ilTestLegacyFormsHelper();
51  }
52 
53  public function setValue($a_value): void
54  {
55  $keys = $this->forms_helper->transformArray($a_value, 'key', $this->refinery->kindlyTo()->string());
56  $points = $this->forms_helper->transformPoints($a_value);
57 
58  $this->values = [];
59  foreach ($keys as $index => $key) {
60  $this->values[] = new assAnswerErrorText(
61  $key,
62  $a_value['value'][$index] ?? '',
63  $points[$index] ?? 0.0
64  );
65  }
66  }
67 
73  public function setKeySize($a_size): void
74  {
75  $this->key_size = $a_size;
76  }
77 
83  public function getKeySize(): int
84  {
85  return $this->key_size;
86  }
87 
93  public function setValueSize($a_size): void
94  {
95  $this->value_size = $a_size;
96  }
97 
103  public function getValueSize(): int
104  {
105  return $this->value_size;
106  }
107 
113  public function setKeyMaxlength($a_maxlength): void
114  {
115  $this->key_maxlength = $a_maxlength;
116  }
117 
123  public function getKeyMaxlength(): int
124  {
125  return $this->key_maxlength;
126  }
127 
133  public function setValueMaxlength($a_maxlength): void
134  {
135  $this->value_maxlength = $a_maxlength;
136  }
137 
143  public function getValueMaxlength(): int
144  {
145  return $this->value_maxlength;
146  }
147 
153  public function setValueName($a_name): void
154  {
155  $this->value_name = $a_name;
156  }
157 
163  public function getValueName(): string
164  {
165  return $this->value_name;
166  }
167 
173  public function setKeyName($a_name): void
174  {
175  $this->key_name = $a_name;
176  }
177 
183  public function getKeyName(): string
184  {
185  return $this->key_name;
186  }
187 
193  public function setValues($a_values): void
194  {
195  $this->values = $a_values;
196  }
197 
203  public function getValues(): array
204  {
205  return $this->values;
206  }
207 
212  public function checkInput(): bool
213  {
214  $kindlyTo = $this->refinery->kindlyTo();
215  $data = $this->raw($this->getPostVar());
216 
217  if (!is_array($data)) {
218  $this->setAlert($this->lng->txt('errortext_info'));
219  return false;
220  }
221 
222  // check points
223  $points = $this->forms_helper->checkPointsInput($data, $this->getRequired());
224  if (!is_array($points)) {
225  $this->setAlert($this->lng->txt($points));
226  return false;
227  }
228  foreach ($points as $point) {
229  if ($point <= 0) {
230  $this->setAlert($this->lng->txt('positive_numbers_required'));
231  return false;
232  }
233  }
234 
235  // check answers
236  $keys = $this->forms_helper->transformArray($data, 'key', $kindlyTo->string());
237  $values = $this->forms_helper->transformArray($data, 'value', $kindlyTo->string());
238  if (empty($keys) || empty($values)) {
239  $this->setAlert($this->lng->txt('msg_input_is_required'));
240  return false;
241  }
242  foreach ([$keys, $values] as $array) {
243  foreach ($array as $item) {
244  if ($item === '' && $this->getRequired()) {
245  $this->setAlert($this->lng->txt('msg_input_is_required'));
246  return false;
247  }
248  }
249  }
250 
251  return $this->checkSubItemsInput();
252  }
253 
258  public function insert(ilTemplate $a_tpl): void
259  {
260  global $DIC;
261  $lng = $DIC['lng'];
262 
263  $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "components/ILIAS/TestQuestionPool");
264  $i = 0;
265  foreach ($this->values as $value) {
266  if (is_object($value)) {
267  if (strlen($value->getTextWrong())) {
268  $tpl->setCurrentBlock("prop_key_propval");
269  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getTextWrong()));
270  $tpl->parseCurrentBlock();
271  }
272  if (strlen($value->getTextCorrect())) {
273  $tpl->setCurrentBlock("prop_value_propval");
274  $tpl->setVariable(
275  "PROPERTY_VALUE",
276  ilLegacyFormElementsUtil::prepareFormOutput($value->getTextCorrect())
277  );
278  $tpl->parseCurrentBlock();
279  }
280  if (strlen($value->getPoints())) {
281  $tpl->setCurrentBlock("prop_points_propval");
282  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getPoints()));
283  $tpl->parseCurrentBlock();
284  }
285  }
286 
287  $tpl->setCurrentBlock("row");
288  $class = ($i % 2 == 0) ? "even" : "odd";
289  if ($i == 0) {
290  $class .= " first";
291  }
292  if ($i == count($this->values) - 1) {
293  $class .= " last";
294  }
295  $tpl->setVariable("ROW_CLASS", $class);
296  $tpl->setVariable("ROW_NUMBER", $i);
297 
298  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
299  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
300  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
301 
302  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
303  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
304  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
305 
306  $tpl->setVariable("POST_VAR", $this->getPostVar());
307 
308  $tpl->parseCurrentBlock();
309 
310  $i++;
311  }
312  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
313  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
314  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
315  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
316 
317  $a_tpl->setCurrentBlock("prop_generic");
318  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
319  $a_tpl->parseCurrentBlock();
320  }
321 }
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...
__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)
setValueMaxlength($a_maxlength)
Set value maxlength.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
This class represents a key value pair wizard property in a property form.
insert(ilTemplate $a_tpl)
Insert property html.