ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $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}
$_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
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46