ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilIdentifiedMultiValuesInputGUI.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/Form/classes/class.ilTextInputGUI.php';
5require_once 'Services/Form/interfaces/interface.ilMultiValuesItem.php';
6
14{
15 const ELEMENT_DEFAULT_ADD_CMD = 'addElement';
16 const ELEMENT_DEFAULT_REMOVE_CMD = 'removeElement';
17 const ELEMENT_DEFAULT_MOVE_UP_CMD = 'moveUpElement';
18 const ELEMENT_DEFAULT_MOVE_DOWN_CMD = 'moveDownElement';
19
24
25 protected $identified_multi_values = array();
26
27 protected $formValuesManipulationChain = array();
28
29 public function __construct($a_title = "", $a_postvar = "")
30 {
31 parent::__construct($a_title, $a_postvar);
32
33 require_once 'Services/Form/classes/class.ilFormSubmitRecursiveSlashesStripper.php';
35
36 require_once 'Services/Form/classes/class.ilIdentifiedMultiValuesJsPositionIndexRemover.php';
38
39 //$this->setMulti(true); // this is another planet, do not enable (!)
40 }
41
42 public function getElementAddCmd()
43 {
45 }
46
51 {
52 $this->elementAddCmd = $elementAddCmd;
53 }
54
55 public function getElementRemoveCmd()
56 {
58 }
59
61 {
62 $this->elementRemoveCmd = $elementRemoveCmd;
63 }
64
65 public function getElementMoveUpCommand()
66 {
68 }
69
71 {
72 $this->elementMoveUpCommand = $elementMoveUpCommand;
73 }
74
75 public function getElementMoveDownCommand()
76 {
78 }
79
81 {
82 $this->elementMoveDownCommand = $elementMoveDownCommand;
83 }
84
85 public function setValues($values)
86 {
87 require_once 'Services/Form/exceptions/class.ilFormException.php';
88 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
89 }
90
91 public function getValues()
92 {
93 require_once 'Services/Form/exceptions/class.ilFormException.php';
94 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
95 }
96
97 public function setValue($value)
98 {
99 require_once 'Services/Form/exceptions/class.ilFormException.php';
100 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
101 }
102
103 public function getValue()
104 {
105 require_once 'Services/Form/exceptions/class.ilFormException.php';
106 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
107 }
108
109 public function setMultiValues(array $values)
110 {
111 require_once 'Services/Form/exceptions/class.ilFormException.php';
112 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
113 }
114
115 public function getMultiValues()
116 {
117 require_once 'Services/Form/exceptions/class.ilFormException.php';
118 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
119 }
120
121 final public function setIdentifiedMultiValues($values)
122 {
123 $this->identified_multi_values = $this->prepareMultiValuesInput($values);
124 }
125
126 final public function getIdentifiedMultiValues()
127 {
129 }
130
131 protected function getMultiValueSubFieldId($identifier, $subFieldIndex)
132 {
133 $tempPostVar = $this->getMultiValuePostVarSubField($identifier, $subFieldIndex);
134 $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
135
136 return $multiValueFieldId;
137 }
138
139 protected function getMultiValuePosIndexedFieldId($identifier, $positionIndex)
140 {
141 $tempPostVar = $this->getMultiValuePostVarPosIndexed($identifier, $positionIndex);
142 $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
143
144 return $multiValueFieldId;
145 }
146
147 protected function getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
148 {
149 $tempPostVar = $this->getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex);
150 $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
151
152 return $multiValueFieldId;
153 }
154
155 protected function getFieldIdFromPostVar($tempPostVar)
156 {
157 $basicPostVar = $this->getPostVar();
158 $this->setPostVar($tempPostVar);
159
160 // uses getPostVar() internally, our postvar does not have the counter included
161 $multiValueFieldId = $this->getFieldId();
162 // now ALL brackets ("[", "]") are escaped, even the ones for the counter
163
164 $this->setPostVar($basicPostVar);
165 return $multiValueFieldId;
166 }
167
168 protected function getPostVarSubField($subFieldIndex)
169 {
170 return $this->getSubFieldCompletedPostVar($subFieldIndex, $this->getPostVar());
171 }
172
173 protected function getMultiValuePostVarSubField($identifier, $subFieldIndex)
174 {
175 $elemPostVar = $this->getMultiValuePostVar($identifier);
176 $elemPostVar = $this->getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar);
177
178 return $elemPostVar;
179 }
180
181 protected function getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
182 {
183 $elemPostVar = $this->getMultiValuePostVarPosIndexed($identifier, $positionIndex);
184 $elemPostVar = $this->getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar);
185
186 return $elemPostVar;
187 }
188
189 protected function getMultiValuePostVarPosIndexed($identifier, $positionIndex)
190 {
191 $elemPostVar = $this->getMultiValuePostVar($identifier);
192 $elemPostVar .= "[$positionIndex]";
193
194 return $elemPostVar;
195 }
196
197 protected function getMultiValuePostVar($identifier)
198 {
199 $elemPostVar = $this->getPostVar();
200 $elemPostVar .= "[$identifier]";
201 return $elemPostVar;
202 }
203
204 protected function buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
205 {
206 $elemSubmitVar = "cmd[{$submitCommand}][{$this->getFieldId()}]";
207 $elemSubmitVar .= "[$identifier][$positionIndex]";
208
209 return $elemSubmitVar;
210 }
211
212 final public function setValueByArray($a_values)
213 {
214 if (!is_array($a_values[$this->getPostVar()])) {
215 $a_values[$this->getPostVar()] = array();
216 }
217
218 $a_values[$this->getPostVar()] = $this->prepareMultiValuesSubmit(
219 $a_values[$this->getPostVar()]
220 );
221
222 $this->setIdentifiedMultiValuesByArray($a_values);
223 }
224
225 protected function setIdentifiedMultiValuesByArray($a_values)
226 {
227 $this->identified_multi_values = $a_values[$this->getPostVar()];
228 }
229
230 final public function checkInput()
231 {
232 if (!is_array($_POST[$this->getPostVar()])) {
233 $_POST[$this->getPostVar()] = array();
234 }
235
236 $_POST[$this->getPostVar()] = $this->prepareMultiValuesSubmit(
237 $_POST[$this->getPostVar()]
238 );
239
240 return $this->onCheckInput();
241 }
242
243 abstract public function onCheckInput();
244
245 final protected function prepareMultiValuesInput($values)
246 {
247 foreach ($this->getFormValuesManipulators() as $manipulator) {
248 /* @var ilFormValuesManipulator $manipulator */
249 $values = $manipulator->manipulateFormInputValues($values);
250 }
251
252 return $values;
253 }
254
255 final protected function prepareMultiValuesSubmit($values)
256 {
257 foreach ($this->getFormValuesManipulators() as $manipulator) {
258 /* @var ilFormValuesManipulator $manipulator */
259 $values = $manipulator->manipulateFormSubmitValues($values);
260 }
261
262 return $values;
263 }
264
265 protected function getFormValuesManipulators()
266 {
268 }
269
270 protected function addFormValuesManipulator(ilFormValuesManipulator $manipulator)
271 {
272 $this->formValuesManipulationChain[] = $manipulator;
273 }
274
280 protected function getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar)
281 {
282 $fieldPostVar = "{$this->getPostVar()}[$subFieldIndex]";
283 $elemPostVar = str_replace($this->getPostVar(), $fieldPostVar, $elemPostVar);
284 return $elemPostVar;
285 }
286
287 public function prepareReprintable(assQuestion $question)
288 {
290 }
291}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Abstract basic class which is to be extended by the concrete assessment question type classes.
Class ilFormException.
getPostVar()
Get Post Variable.
getFieldId()
Get Post Variable.
setPostVar($a_postvar)
Set Post Variable.
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
__construct($a_title="", $a_postvar="")
Constructor.
This class represents a text property in a property form.
Interface for multi values support.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc