ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
33
36
37 public function __construct($a_title = "", $a_postvar = "")
38 {
39 parent::__construct($a_title, $a_postvar);
40
42 }
43
44 public function getElementAddCmd(): string
45 {
47 }
48
49 public function setElementAddCmd(string $element_add_cmd): void
50 {
51 $this->element_add_cmd = $element_add_cmd;
52 }
53
54 public function getElementRemoveCmd(): string
55 {
57 }
58
59 public function setElementRemoveCmd(string $element_remove_cmd): void
60 {
61 $this->element_remove_cmd = $element_remove_cmd;
62 }
63
64 public function getElementMoveUpCommand(): string
65 {
67 }
68
69 public function setElementMoveUpCommand(string $element_move_up_cmd): void
70 {
71 $this->element_move_up_cmd = $element_move_up_cmd;
72 }
73
74 public function getElementMoveDownCommand(): string
75 {
77 }
78
80 {
81 $this->element_move_down_cmd = $element_move_down_cmd;
82 }
83
84 public function setValues($values): void
85 {
86 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
87 }
88
93 public function getValues()
94 {
95 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
96 }
97
98 public function setValue($value): void
99 {
100 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
101 }
102
103 public function getValue()
104 {
105 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
106 }
107
108 public function setMultiValues(array $values): void
109 {
110 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
111 }
112
113 public function getMultiValues(): array
114 {
115 throw new ilFormException('setter unsupported, use setIdentifiedMultiValues() instead!');
116 }
117
118 final public function setIdentifiedMultiValues($values): void
119 {
120 $this->identified_multi_values = $this->prepareMultiValuesInput($values);
121 }
122
123 final public function getIdentifiedMultiValues(): array
124 {
126 }
127
128 protected function getMultiValueSubFieldId($identifier, $sub_field_index): string
129 {
130 $temp_post_var = $this->getMultiValuePostVarSubField($identifier, $sub_field_index);
131 return $this->getFieldIdFromPostVar($temp_post_var);
132 }
133
134 protected function getMultiValuePosIndexedFieldId($identifier, $position_index): string
135 {
136 $temp_post_var = $this->getMultiValuePostVarPosIndexed($identifier, $position_index);
137 return $this->getFieldIdFromPostVar($temp_post_var);
138 }
139
140 protected function getMultiValuePosIndexedSubFieldId($identifier, $sub_field_index, $position_index): string
141 {
142 $temp_post_var = $this->getMultiValuePostVarSubFieldPosIndexed($identifier, $sub_field_index, $position_index);
143 return $this->getFieldIdFromPostVar($temp_post_var);
144 }
145
146 protected function getFieldIdFromPostVar($temp_post_var): string
147 {
148 $basic_post_var = $this->getPostVar();
149 $this->setPostVar($temp_post_var);
150
151 // uses getPostVar() internally, our postvar does not have the counter included
152 $multi_value_field_id = $this->getFieldId();
153 // now ALL brackets ("[", "]") are escaped, even the ones for the counter
154
155 $this->setPostVar($basic_post_var);
156 return $multi_value_field_id;
157 }
158
159 protected function getPostVarSubField($sub_field_index)
160 {
161 return $this->getSubFieldCompletedPostVar($sub_field_index, $this->getPostVar());
162 }
163
164 protected function getMultiValuePostVarSubField($identifier, $sub_field_index)
165 {
166 $elem_post_var = $this->getMultiValuePostVar($identifier);
167 return $this->getSubFieldCompletedPostVar($sub_field_index, $elem_post_var);
168 }
169
170 protected function getMultiValuePostVarSubFieldPosIndexed($identifier, $sub_field_index, $position_index)
171 {
172 $elem_post_var = $this->getMultiValuePostVarPosIndexed($identifier, $position_index);
173 return $this->getSubFieldCompletedPostVar($sub_field_index, $elem_post_var);
174 }
175
176 protected function getMultiValuePostVarPosIndexed($identifier, $positionIndex): string
177 {
178 $elem_post_var = $this->getMultiValuePostVar($identifier);
179 $elem_post_var .= "[$positionIndex]";
180
181 return $elem_post_var;
182 }
183
184 protected function getMultiValuePostVar($identifier): string
185 {
186 $elem_post_var = $this->getPostVar();
187 $elem_post_var .= "[$identifier]";
188 return $elem_post_var;
189 }
190
191 protected function buildMultiValueSubmitVar($identifier, $position_index, $submit_cmd): string
192 {
193 $elem_submit_var = "cmd[{$submit_cmd}][{$this->getFieldId()}]";
194 $elem_submit_var .= "[$identifier][$position_index]";
195
196 return $elem_submit_var;
197 }
198
199 final public function setValueByArray(array $a_values): void
200 {
201 if (!isset($a_values[$this->getPostVar()]) || !is_array($a_values[$this->getPostVar()])) {
202 $a_values[$this->getPostVar()] = [];
203 }
204
205 $a_values[$this->getPostVar()] = $this->prepareMultiValuesSubmit(
206 $a_values[$this->getPostVar()]
207 );
208
209 $this->setIdentifiedMultiValuesByArray($a_values);
210 }
211
212 protected function setIdentifiedMultiValuesByArray($a_values): void
213 {
214 $this->identified_multi_values = $a_values[$this->getPostVar()];
215 }
216
220 public function getInput(): array
221 {
222 $values = $this->arrayArray($this->getPostVar());
223
224 return $this->prepareMultiValuesSubmit($values);
225 }
226
227 final public function checkInput(): bool
228 {
229 return $this->onCheckInput();
230 }
231
232 abstract public function onCheckInput();
233
234 final protected function prepareMultiValuesInput($values)
235 {
236 foreach ($this->getFormValuesManipulators() as $manipulator) {
237 $values = $manipulator->manipulateFormInputValues($values);
238 }
239
240 return $values;
241 }
242
243 final protected function prepareMultiValuesSubmit($values)
244 {
245 foreach ($this->getFormValuesManipulators() as $manipulator) {
246 /* @var ilFormValuesManipulator $manipulator */
247 $values = $manipulator->manipulateFormSubmitValues($values);
248 }
249
250 return $values;
251 }
252
253 protected function getFormValuesManipulators(): array
254 {
256 }
257
258 protected function addFormValuesManipulator(ilFormValuesManipulator $manipulator): void
259 {
260 $this->formValuesManipulationChain[] = $manipulator;
261 }
262
268 protected function getSubFieldCompletedPostVar($subFieldIndex, $elem_post_var)
269 {
270 $field_post_var = "{$this->getPostVar()}[$subFieldIndex]";
271 return str_replace($this->getPostVar(), $field_post_var, $elem_post_var);
272 }
273
274 public function prepareReprintable(assQuestion $question): void
275 {
277 }
278}
setPostVar(string $a_postvar)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMultiValuePosIndexedFieldId($identifier, $position_index)
getSubFieldCompletedPostVar($subFieldIndex, $elem_post_var)
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
getMultiValuePostVarSubFieldPosIndexed($identifier, $sub_field_index, $position_index)
getMultiValuePostVarSubField($identifier, $sub_field_index)
getMultiValuePosIndexedSubFieldId($identifier, $sub_field_index, $position_index)
setElementMoveDownCommand(string $element_move_down_cmd)
buildMultiValueSubmitVar($identifier, $position_index, $submit_cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
Interface for multi values support.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc