ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIdentifiedMultiValuesInputGUI.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  public const ELEMENT_DEFAULT_ADD_CMD = 'addElement';
25  public const ELEMENT_DEFAULT_REMOVE_CMD = 'removeElement';
26  public const ELEMENT_DEFAULT_MOVE_UP_CMD = 'moveUpElement';
27  public const ELEMENT_DEFAULT_MOVE_DOWN_CMD = 'moveDownElement';
28 
29  protected $elementAddCmd = self::ELEMENT_DEFAULT_ADD_CMD;
30  protected $elementRemoveCmd = self::ELEMENT_DEFAULT_REMOVE_CMD;
31  protected $elementMoveUpCommand = self::ELEMENT_DEFAULT_MOVE_UP_CMD;
32  protected $elementMoveDownCommand = self::ELEMENT_DEFAULT_MOVE_DOWN_CMD;
33 
34  protected $identified_multi_values = array();
35 
36  protected $formValuesManipulationChain = array();
37 
38  public function __construct($a_title = "", $a_postvar = "")
39  {
40  parent::__construct($a_title, $a_postvar);
41 
43  }
44 
45  public function getElementAddCmd(): string
46  {
47  return $this->elementAddCmd;
48  }
49 
53  public function setElementAddCmd($elementAddCmd): void
54  {
55  $this->elementAddCmd = $elementAddCmd;
56  }
57 
58  public function getElementRemoveCmd(): string
59  {
61  }
62 
63  public function setElementRemoveCmd($elementRemoveCmd): void
64  {
65  $this->elementRemoveCmd = $elementRemoveCmd;
66  }
67 
68  public function getElementMoveUpCommand(): string
69  {
71  }
72 
74  {
75  $this->elementMoveUpCommand = $elementMoveUpCommand;
76  }
77 
78  public function getElementMoveDownCommand(): string
79  {
81  }
82 
84  {
85  $this->elementMoveDownCommand = $elementMoveDownCommand;
86  }
87 
88  public function setValues($values): void
89  {
90  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
91  }
92 
97  public function getValues()
98  {
99  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
100  }
101 
102  public function setValue($value): void
103  {
104  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
105  }
106 
107  public function getValue()
108  {
109  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
110  }
111 
112  public function setMultiValues(array $values): void
113  {
114  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
115  }
116 
117  public function getMultiValues(): array
118  {
119  throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
120  }
121 
122  final public function setIdentifiedMultiValues($values): void
123  {
124  $this->identified_multi_values = $this->prepareMultiValuesInput($values);
125  }
126 
127  final public function getIdentifiedMultiValues(): array
128  {
130  }
131 
132  protected function getMultiValueSubFieldId($identifier, $subFieldIndex): string
133  {
134  $tempPostVar = $this->getMultiValuePostVarSubField($identifier, $subFieldIndex);
135  $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
136 
137  return $multiValueFieldId;
138  }
139 
140  protected function getMultiValuePosIndexedFieldId($identifier, $positionIndex): string
141  {
142  $tempPostVar = $this->getMultiValuePostVarPosIndexed($identifier, $positionIndex);
143  $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
144 
145  return $multiValueFieldId;
146  }
147 
148  protected function getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex): string
149  {
150  $tempPostVar = $this->getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex);
151  $multiValueFieldId = $this->getFieldIdFromPostVar($tempPostVar);
152 
153  return $multiValueFieldId;
154  }
155 
156  protected function getFieldIdFromPostVar($tempPostVar): string
157  {
158  $basicPostVar = $this->getPostVar();
159  $this->setPostVar($tempPostVar);
160 
161  // uses getPostVar() internally, our postvar does not have the counter included
162  $multiValueFieldId = $this->getFieldId();
163  // now ALL brackets ("[", "]") are escaped, even the ones for the counter
164 
165  $this->setPostVar($basicPostVar);
166  return $multiValueFieldId;
167  }
168 
169  protected function getPostVarSubField($subFieldIndex)
170  {
171  return $this->getSubFieldCompletedPostVar($subFieldIndex, $this->getPostVar());
172  }
173 
174  protected function getMultiValuePostVarSubField($identifier, $subFieldIndex)
175  {
176  $elemPostVar = $this->getMultiValuePostVar($identifier);
177  $elemPostVar = $this->getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar);
178 
179  return $elemPostVar;
180  }
181 
182  protected function getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
183  {
184  $elemPostVar = $this->getMultiValuePostVarPosIndexed($identifier, $positionIndex);
185  $elemPostVar = $this->getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar);
186 
187  return $elemPostVar;
188  }
189 
190  protected function getMultiValuePostVarPosIndexed($identifier, $positionIndex): string
191  {
192  $elemPostVar = $this->getMultiValuePostVar($identifier);
193  $elemPostVar .= "[$positionIndex]";
194 
195  return $elemPostVar;
196  }
197 
198  protected function getMultiValuePostVar($identifier): string
199  {
200  $elemPostVar = $this->getPostVar();
201  $elemPostVar .= "[$identifier]";
202  return $elemPostVar;
203  }
204 
205  protected function buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand): string
206  {
207  $elemSubmitVar = "cmd[{$submitCommand}][{$this->getFieldId()}]";
208  $elemSubmitVar .= "[$identifier][$positionIndex]";
209 
210  return $elemSubmitVar;
211  }
212 
213  final public function setValueByArray(array $a_values): void
214  {
215  if (!isset($a_values[$this->getPostVar()]) || !is_array($a_values[$this->getPostVar()])) {
216  $a_values[$this->getPostVar()] = [];
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): void
227  {
228  $this->identified_multi_values = $a_values[$this->getPostVar()];
229  }
230 
234  public function getInput(): array
235  {
236  $values = $this->arrayArray($this->getPostVar());
237 
238  return $this->prepareMultiValuesSubmit($values);
239  }
240 
241  final public function checkInput(): bool
242  {
243  return $this->onCheckInput();
244  }
245 
246  abstract public function onCheckInput();
247 
248  final protected function prepareMultiValuesInput($values)
249  {
250  foreach ($this->getFormValuesManipulators() as $manipulator) {
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  /* @var ilFormValuesManipulator $manipulator */
262  $values = $manipulator->manipulateFormSubmitValues($values);
263  }
264 
265  return $values;
266  }
267 
268  protected function getFormValuesManipulators(): array
269  {
271  }
272 
273  protected function addFormValuesManipulator(ilFormValuesManipulator $manipulator): void
274  {
275  $this->formValuesManipulationChain[] = $manipulator;
276  }
277 
283  protected function getSubFieldCompletedPostVar($subFieldIndex, $elemPostVar)
284  {
285  $fieldPostVar = "{$this->getPostVar()}[$subFieldIndex]";
286  $elemPostVar = str_replace($this->getPostVar(), $fieldPostVar, $elemPostVar);
287  return $elemPostVar;
288  }
289 
290  public function prepareReprintable(assQuestion $question): void
291  {
293  }
294 }
getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
Abstract basic class which is to be extended by the concrete assessment question type classes...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setPostVar(string $a_postvar)
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
addFormValuesManipulator(ilFormValuesManipulator $manipulator)