ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilKVPWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected $values = array();
29  protected $allowMove = false;
30  protected $key_size = 20;
31  protected $value_size = 20;
32  protected $key_maxlength = 255;
33  protected $value_maxlength = 255;
34  protected $key_name = "";
35  protected $value_name = "";
36 
43  public function __construct($a_title = "", $a_postvar = "")
44  {
45  parent::__construct($a_title, $a_postvar);
46  }
47 
48  public function setValue($a_value): void
49  {
50  $this->values = array();
51  if (is_array($a_value)) {
52  if (is_array($a_value['key'])) {
53  foreach ($a_value['key'] as $idx => $key) {
54  array_push($this->values, array($key, $a_value['value'][$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 
205  public function setAllowMove($a_allow_move): void
206  {
207  $this->allowMove = $a_allow_move;
208  }
209 
215  public function getAllowMove(): bool
216  {
217  return $this->allowMove;
218  }
219 
224  public function checkInput(): bool
225  {
226  global $DIC;
227  $lng = $DIC['lng'];
228 
229  if (is_array($_POST[$this->getPostVar()])) {
230  $_POST[$this->getPostVar()] = ilArrayUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
231  }
232  $foundvalues = $_POST[$this->getPostVar()];
233  if (is_array($foundvalues)) {
234  // check answers
235  if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
236  foreach ($foundvalues['key'] as $val) {
237  if ($this->getRequired() && (strlen($val)) == 0) {
238  $this->setAlert($lng->txt("msg_input_is_required"));
239  return false;
240  }
241  }
242  foreach ($foundvalues['value'] as $val) {
243  if ($this->getRequired() && (strlen($val)) == 0) {
244  $this->setAlert($lng->txt("msg_input_is_required"));
245  return false;
246  }
247  }
248  } else {
249  if ($this->getRequired()) {
250  $this->setAlert($lng->txt("msg_input_is_required"));
251  return false;
252  }
253  }
254  } else {
255  if ($this->getRequired()) {
256  $this->setAlert($lng->txt("msg_input_is_required"));
257  return false;
258  }
259  }
260  return $this->checkSubItemsInput();
261  }
262 
267  public function insert(ilTemplate $a_tpl): void
268  {
269  global $DIC;
270  $lng = $DIC['lng'];
271 
272  $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
273  $i = 0;
274  foreach ($this->values as $value) {
275  if (is_array($value)) {
276  $tpl->setCurrentBlock("prop_key_propval");
277  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value[0]));
278  $tpl->parseCurrentBlock();
279  $tpl->setCurrentBlock("prop_value_propval");
280  $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value[1]));
281  $tpl->parseCurrentBlock();
282  }
283  if ($this->getAllowMove()) {
284  $tpl->setCurrentBlock("move");
285  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
286  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
287  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
288  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
289  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
290  $tpl->parseCurrentBlock();
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("ID", $this->getPostVar() . "[$i]");
313  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
314  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
315  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
316  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
317 
318  $tpl->setVariable("POST_VAR", $this->getPostVar());
319 
320  $tpl->parseCurrentBlock();
321 
322  $i++;
323  }
324  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
325  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
326  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
327 
328  $a_tpl->setCurrentBlock("prop_generic");
329  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
330  $a_tpl->parseCurrentBlock();
331 
332  global $DIC;
333  $tpl = $DIC['tpl'];
334  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
335  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
336  }
337 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setValueName($a_name)
Set value name.
setValueSize($a_size)
Set value size.
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...
static get(string $a_glyph, string $a_text="")
getKeyMaxlength()
Get key maxlength.
setValueMaxlength($a_maxlength)
Set value maxlength.
setKeyMaxlength($a_maxlength)
Set key maxlength.
setValues($a_values)
Set Values.
static prepareFormOutput($a_str, bool $a_strip=false)
global $DIC
Definition: feed.php:28
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
string $key
Consumer key/client ID value.
Definition: System.php:193
getValueMaxlength()
Get value maxlength.
insert(ilTemplate $a_tpl)
Insert property html.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
setKeySize($a_size)
Set key size.
__construct($a_title="", $a_postvar="")
Constructor.
setKeyName($a_name)
Set key name.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
checkInput()
Check input, strip slashes etc.
$i
Definition: metadata.php:41
setAllowMove($a_allow_move)
Set allow move.