ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilKVPWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5 
14 {
15  protected $values = array();
16  protected $allowMove = false;
17  protected $key_size = 20;
18  protected $value_size = 20;
19  protected $key_maxlength = 255;
20  protected $value_maxlength = 255;
21  protected $key_name = "";
22  protected $value_name = "";
23 
30  public function __construct($a_title = "", $a_postvar = "")
31  {
32  parent::__construct($a_title, $a_postvar);
33  }
34 
40  public function setValue($a_value)
41  {
42  $this->values = array();
43  if (is_array($a_value)) {
44  if (is_array($a_value['key'])) {
45  foreach ($a_value['key'] as $idx => $key) {
46  array_push($this->values, array($key, $a_value['value'][$idx]));
47  }
48  }
49  }
50  }
51 
57  public function setKeySize($a_size)
58  {
59  $this->key_size = $a_size;
60  }
61 
67  public function getKeySize()
68  {
69  return $this->key_size;
70  }
71 
77  public function setValueSize($a_size)
78  {
79  $this->value_size = $a_size;
80  }
81 
87  public function getValueSize()
88  {
89  return $this->value_size;
90  }
91 
97  public function setKeyMaxlength($a_maxlength)
98  {
99  $this->key_maxlength = $a_maxlength;
100  }
101 
107  public function getKeyMaxlength()
108  {
109  return $this->key_maxlength;
110  }
111 
117  public function setValueMaxlength($a_maxlength)
118  {
119  $this->value_maxlength = $a_maxlength;
120  }
121 
127  public function getValueMaxlength()
128  {
129  return $this->value_maxlength;
130  }
131 
137  public function setValueName($a_name)
138  {
139  $this->value_name = $a_name;
140  }
141 
147  public function getValueName()
148  {
149  return $this->value_name;
150  }
151 
157  public function setKeyName($a_name)
158  {
159  $this->key_name = $a_name;
160  }
161 
167  public function getKeyName()
168  {
169  return $this->key_name;
170  }
171 
177  public function setValues($a_values)
178  {
179  $this->values = $a_values;
180  }
181 
187  public function getValues()
188  {
189  return $this->values;
190  }
191 
197  public function setAllowMove($a_allow_move)
198  {
199  $this->allowMove = $a_allow_move;
200  }
201 
207  public function getAllowMove()
208  {
209  return $this->allowMove;
210  }
211 
217  public function checkInput()
218  {
219  global $DIC;
220  $lng = $DIC['lng'];
221 
222  if (is_array($_POST[$this->getPostVar()])) {
224  }
225  $foundvalues = $_POST[$this->getPostVar()];
226  if (is_array($foundvalues)) {
227  // check answers
228  if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
229  foreach ($foundvalues['key'] as $val) {
230  if ($this->getRequired() && (strlen($val)) == 0) {
231  $this->setAlert($lng->txt("msg_input_is_required"));
232  return false;
233  }
234  }
235  foreach ($foundvalues['value'] as $val) {
236  if ($this->getRequired() && (strlen($val)) == 0) {
237  $this->setAlert($lng->txt("msg_input_is_required"));
238  return false;
239  }
240  }
241  } else {
242  if ($this->getRequired()) {
243  $this->setAlert($lng->txt("msg_input_is_required"));
244  return false;
245  }
246  }
247  } else {
248  if ($this->getRequired()) {
249  $this->setAlert($lng->txt("msg_input_is_required"));
250  return false;
251  }
252  }
253  return $this->checkSubItemsInput();
254  }
255 
261  public function insert($a_tpl)
262  {
263  global $DIC;
264  $lng = $DIC['lng'];
265 
266  $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
267  $i = 0;
268  foreach ($this->values as $value) {
269  if (is_array($value)) {
270  $tpl->setCurrentBlock("prop_key_propval");
271  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[0]));
272  $tpl->parseCurrentBlock();
273  $tpl->setCurrentBlock("prop_value_propval");
274  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[1]));
275  $tpl->parseCurrentBlock();
276  }
277  if ($this->getAllowMove()) {
278  $tpl->setCurrentBlock("move");
279  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
280  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
281  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
282  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
283  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
284  $tpl->parseCurrentBlock();
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("ID", $this->getPostVar() . "[$i]");
307  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
308  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
309  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
310  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
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 
322  $a_tpl->setCurrentBlock("prop_generic");
323  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
324  $a_tpl->parseCurrentBlock();
325 
326  global $DIC;
327  $tpl = $DIC['tpl'];
328  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
329  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
330  }
331 }
setValueName($a_name)
Set value name.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
setValueSize($a_size)
Set value size.
getKeyMaxlength()
Get key maxlength.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setValueMaxlength($a_maxlength)
Set value maxlength.
static get($a_glyph, $a_text="")
Get glyph html.
setKeyMaxlength($a_maxlength)
Set key maxlength.
setValues($a_values)
Set Values.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
This class represents a text property in a property form.
getValueMaxlength()
Get value maxlength.
setValue($a_value)
Set Value.
insert($a_tpl)
Insert property html.
This class represents a key value pair wizard property in a property form.
setKeySize($a_size)
Set key size.
$i
Definition: disco.tpl.php:19
__construct($a_title="", $a_postvar="")
Constructor.
setKeyName($a_name)
Set key name.
checkInput()
Check input, strip slashes etc.
$key
Definition: croninfo.php:18
$_POST["username"]
setAllowMove($a_allow_move)
Set allow move.