ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/Form/classes/class.ilTextInputGUI.php';
5 require_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 
20  protected $elementAddCmd = self::ELEMENT_DEFAULT_ADD_CMD;
21  protected $elementRemoveCmd = self::ELEMENT_DEFAULT_REMOVE_CMD;
22  protected $elementMoveUpCommand = self::ELEMENT_DEFAULT_MOVE_UP_CMD;
23  protected $elementMoveDownCommand = self::ELEMENT_DEFAULT_MOVE_DOWN_CMD;
24 
26 
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  {
44  return $this->elementAddCmd;
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  {
216  $a_values[$this->getPostVar()] = array();
217  }
218 
219  $a_values[$this->getPostVar()] = $this->prepareMultiValuesSubmit(
220  $a_values[$this->getPostVar()]
221  );
222 
223  $this->setIdentifiedMultiValuesByArray($a_values);
224  }
225 
226  protected function setIdentifiedMultiValuesByArray($a_values)
227  {
228  $this->identified_multi_values = $a_values[$this->getPostVar()];
229  }
230 
231  final public function checkInput()
232  {
233  if( !is_array($_POST[$this->getPostVar()]) )
234  {
235  $_POST[$this->getPostVar()] = array();
236  }
237 
238  $_POST[$this->getPostVar()] = $this->prepareMultiValuesSubmit(
239  $_POST[$this->getPostVar()]
240  );
241 
242  return $this->onCheckInput();
243  }
244 
245  abstract public function onCheckInput();
246 
247  final protected function prepareMultiValuesInput($values)
248  {
249  foreach($this->getFormValuesManipulators() as $manipulator)
250  {
251  /* @var ilFormValuesManipulator $manipulator */
252  $values = $manipulator->manipulateFormInputValues($values);
253  }
254 
255  return $values;
256  }
257 
258  final protected function prepareMultiValuesSubmit($values)
259  {
260  foreach($this->getFormValuesManipulators() as $manipulator)
261  {
262  /* @var ilFormValuesManipulator $manipulator */
263  $values = $manipulator->manipulateFormSubmitValues($values);
264  }
265 
266  return $values;
267  }
268 
269  protected function getFormValuesManipulators()
270  {
272  }
273 
274  protected function addFormValuesManipulator(ilFormValuesManipulator $manipulator)
275  {
276  $this->formValuesManipulationChain[] = $manipulator;
277  }
278 
284  protected function getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar)
285  {
286  $fieldPostVar = "{$this->getPostVar()}[$subFieldIndex]";
287  $elemPostVar = str_replace($this->getPostVar(), $fieldPostVar, $elemPostVar);
288  return $elemPostVar;
289  }
290 
291  public function prepareReprintable(assQuestion $question)
292  {
294  }
295 }
getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
Abstract basic class which is to be extended by the concrete assessment question type classes...
getPostVar()
Get Post Variable.
setPostVar($a_postvar)
Set Post Variable.
Class ilFormException.
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
getFieldId()
Get Post Variable.
This class represents a text property in a property form.
Create styles array
The data for the language used.
Interface for multi values support.
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
$_POST["username"]