ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  function __construct($a_title = "", $a_postvar = "")
31  {
32  parent::__construct($a_title, $a_postvar);
33  }
34 
40  function setValue($a_value)
41  {
42  $this->values = array();
43  if (is_array($a_value))
44  {
45  if (is_array($a_value['key']))
46  {
47  foreach ($a_value['key'] as $idx => $key)
48  {
49  array_push($this->values, array($key, $a_value['value'][$idx]));
50  }
51  }
52  }
53  }
54 
60  function setKeySize($a_size)
61  {
62  $this->key_size = $a_size;
63  }
64 
70  function getKeySize()
71  {
72  return $this->key_size;
73  }
74 
80  function setValueSize($a_size)
81  {
82  $this->value_size = $a_size;
83  }
84 
90  function getValueSize()
91  {
92  return $this->value_size;
93  }
94 
100  function setKeyMaxlength($a_maxlength)
101  {
102  $this->key_maxlength = $a_maxlength;
103  }
104 
110  function getKeyMaxlength()
111  {
112  return $this->key_maxlength;
113  }
114 
120  function setValueMaxlength($a_maxlength)
121  {
122  $this->value_maxlength = $a_maxlength;
123  }
124 
130  function getValueMaxlength()
131  {
132  return $this->value_maxlength;
133  }
134 
140  function setValueName($a_name)
141  {
142  $this->value_name = $a_name;
143  }
144 
150  function getValueName()
151  {
152  return $this->value_name;
153  }
154 
160  function setKeyName($a_name)
161  {
162  $this->key_name = $a_name;
163  }
164 
170  function getKeyName()
171  {
172  return $this->key_name;
173  }
174 
180  function setValues($a_values)
181  {
182  $this->values = $a_values;
183  }
184 
190  function getValues()
191  {
192  return $this->values;
193  }
194 
200  function setAllowMove($a_allow_move)
201  {
202  $this->allowMove = $a_allow_move;
203  }
204 
210  function getAllowMove()
211  {
212  return $this->allowMove;
213  }
214 
220  function checkInput()
221  {
222  global $lng;
223 
224  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
225  $foundvalues = $_POST[$this->getPostVar()];
226  if (is_array($foundvalues))
227  {
228  // check answers
229  if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
230  {
231  foreach ($foundvalues['key'] as $val)
232  {
233  if ($this->getRequired() && (strlen($val)) == 0)
234  {
235  $this->setAlert($lng->txt("msg_input_is_required"));
236  return FALSE;
237  }
238  }
239  foreach ($foundvalues['value'] as $val)
240  {
241  if ($this->getRequired() && (strlen($val)) == 0)
242  {
243  $this->setAlert($lng->txt("msg_input_is_required"));
244  return FALSE;
245  }
246  }
247  }
248  else
249  {
250  if ($this->getRequired())
251  {
252  $this->setAlert($lng->txt("msg_input_is_required"));
253  return FALSE;
254  }
255  }
256  }
257  else
258  {
259  if ($this->getRequired())
260  {
261  $this->setAlert($lng->txt("msg_input_is_required"));
262  return FALSE;
263  }
264  }
265  return $this->checkSubItemsInput();
266  }
267 
273  function insert(&$a_tpl)
274  {
275  global $lng;
276 
277  $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
278  $i = 0;
279  foreach ($this->values as $value)
280  {
281  if (is_array($value))
282  {
283  $tpl->setCurrentBlock("prop_key_propval");
284  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[0]));
285  $tpl->parseCurrentBlock();
286  $tpl->setCurrentBlock("prop_value_propval");
287  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[1]));
288  $tpl->parseCurrentBlock();
289  }
290  if ($this->getAllowMove())
291  {
292  $tpl->setCurrentBlock("move");
293  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
294  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
295  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
296  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
297  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
298  $tpl->parseCurrentBlock();
299  }
300 
301  $tpl->setCurrentBlock("row");
302  $class = ($i % 2 == 0) ? "even" : "odd";
303  if ($i == 0) $class .= " first";
304  if ($i == count($this->values)-1) $class .= " last";
305  $tpl->setVariable("ROW_CLASS", $class);
306  $tpl->setVariable("ROW_NUMBER", $i);
307 
308  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
309  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
310  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
311 
312  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
313  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
314  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
315 
316  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
317  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
318  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
319  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
320  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
321 
322  $tpl->setVariable("POST_VAR", $this->getPostVar());
323 
324  $tpl->parseCurrentBlock();
325 
326  $i++;
327  }
328  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
329  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
330  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
331 
332  $a_tpl->setCurrentBlock("prop_generic");
333  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
334  $a_tpl->parseCurrentBlock();
335 
336  global $tpl;
337  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
338  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
339  }
340 }