ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_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 {
110 }
111
117 public function setValueMaxlength($a_maxlength)
118 {
119 $this->value_maxlength = $a_maxlength;
120 }
121
127 public function getValueMaxlength()
128 {
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 $lng;
220
221 if (is_array($_POST[$this->getPostVar()])) {
223 }
224 $foundvalues = $_POST[$this->getPostVar()];
225 if (is_array($foundvalues)) {
226 // check answers
227 if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
228 foreach ($foundvalues['key'] as $val) {
229 if ($this->getRequired() && (strlen($val)) == 0) {
230 $this->setAlert($lng->txt("msg_input_is_required"));
231 return false;
232 }
233 }
234 foreach ($foundvalues['value'] as $val) {
235 if ($this->getRequired() && (strlen($val)) == 0) {
236 $this->setAlert($lng->txt("msg_input_is_required"));
237 return false;
238 }
239 }
240 } else {
241 if ($this->getRequired()) {
242 $this->setAlert($lng->txt("msg_input_is_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 return $this->checkSubItemsInput();
253 }
254
260 public function insert($a_tpl)
261 {
262 global $lng;
263
264 $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
265 $i = 0;
266 foreach ($this->values as $value) {
267 if (is_array($value)) {
268 $tpl->setCurrentBlock("prop_key_propval");
269 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[0]));
270 $tpl->parseCurrentBlock();
271 $tpl->setCurrentBlock("prop_value_propval");
272 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[1]));
273 $tpl->parseCurrentBlock();
274 }
275 if ($this->getAllowMove()) {
276 $tpl->setCurrentBlock("move");
277 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
278 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
279 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
280 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
281 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
282 $tpl->parseCurrentBlock();
283 }
284
285 $tpl->setCurrentBlock("row");
286 $class = ($i % 2 == 0) ? "even" : "odd";
287 if ($i == 0) {
288 $class .= " first";
289 }
290 if ($i == count($this->values)-1) {
291 $class .= " last";
292 }
293 $tpl->setVariable("ROW_CLASS", $class);
294 $tpl->setVariable("ROW_NUMBER", $i);
295
296 $tpl->setVariable("KEY_SIZE", $this->getKeySize());
297 $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
298 $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
299
300 $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
301 $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
302 $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
303
304 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
305 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
306 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
307 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
308 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
309
310 $tpl->setVariable("POST_VAR", $this->getPostVar());
311
312 $tpl->parseCurrentBlock();
313
314 $i++;
315 }
316 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
317 $tpl->setVariable("KEY_TEXT", $this->getKeyName());
318 $tpl->setVariable("VALUE_TEXT", $this->getValueName());
319
320 $a_tpl->setCurrentBlock("prop_generic");
321 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
322 $a_tpl->parseCurrentBlock();
323
324 global $tpl;
325 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
326 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
327 }
328}
$tpl
Definition: ilias.php:10
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a key value pair wizard property in a property form.
setValueMaxlength($a_maxlength)
Set value maxlength.
setAllowMove($a_allow_move)
Set allow move.
setKeyName($a_name)
Set key name.
setValueSize($a_size)
Set value size.
setValueName($a_name)
Set value name.
setValue($a_value)
Set Value.
getValueMaxlength()
Get value maxlength.
setKeySize($a_size)
Set key size.
getKeyMaxlength()
Get key maxlength.
__construct($a_title="", $a_postvar="")
Constructor.
insert($a_tpl)
Insert property html.
setValues($a_values)
Set Values.
checkInput()
Check input, strip slashes etc.
setKeyMaxlength($a_maxlength)
Set key maxlength.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19