ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.UserGUIRequest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User;
22 
28 
30 {
33 
34  public function __construct(
35  RequestServices $request,
36  private Refinery $refinery
37  ) {
38  $this->wrapper = $request->wrapper();
39  $this->request = $request->request();
40  }
41 
42  public function getRefId(): int
43  {
44  return $this->int('ref_id');
45  }
46 
47  public function getLetter(): string
48  {
49  return $this->str('letter');
50  }
51 
52  public function getBaseClass(): string
53  {
54  return $this->str('baseClass');
55  }
56 
57  public function getSearch(): string
58  {
59  return $this->str('search');
60  }
61 
62  public function getJumpToUser(): int
63  {
64  return $this->int('jmpToUser');
65  }
66 
67  public function getFieldId(): int
68  {
69  return $this->int('field_id');
70  }
71 
72  public function getFetchAll(): bool
73  {
74  return (bool) $this->int('fetchall');
75  }
76 
77  public function getTerm(): string
78  {
79  return $this->str('term');
80  }
81 
82  public function getStartingPointId(): ?int
83  {
84  if (!$this->wrapper->query()->has('spid') &&
85  !$this->wrapper->query()->has('start_point_id')) {
86  return null;
87  }
88 
89  $id = $this->int('spid');
90  if ($id !== 0) {
91  return $id;
92  }
93  return $this->int('start_point_id');
94  }
95 
96  public function getRoleId(): int
97  {
98  $role_id = $this->int('rolid');
99  if ($role_id !== 0) {
100  return $role_id;
101  }
102  return $this->int('role_id');
103  }
104 
105  public function getActionActive(): array
106  {
107  return $this->intArray('active');
108  }
109 
110  public function getIds(): array
111  {
112  return $this->intArray('id');
113  }
114 
115  public function getChecked(): array
116  {
117  return $this->intArray('chb');
118  }
119 
120  public function getFieldType(): int
121  {
122  return $this->int('field_type');
123  }
124 
125  public function getFields(): array
126  {
127  return $this->intArray('fields');
128  }
129 
130  public function getSelectedAction(): string
131  {
132  return $this->str('selectedAction');
133  }
134 
135  public function getFrSearch(): bool
136  {
137  return $this->bool('frsrch');
138  }
139 
140  public function getSelect(): array
141  {
142  return $this->strArray('select');
143  }
144 
145  public function getFiles(): array
146  {
147  return $this->strArray('file');
148  }
149 
150  public function getExportType(): string
151  {
152  return $this->str('export_type');
153  }
154 
155  public function getMailSalutation(string $gender, string $lang): string
156  {
157  return $this->str('sal_' . $gender . '_' . $lang);
158  }
159 
160  public function getMailSubject(string $lang): string
161  {
162  return $this->str('subject_' . $lang);
163  }
164 
165  public function getMailBody(string $lang): string
166  {
167  return $this->str('body_' . $lang);
168  }
169 
170  public function getMailAttDelete(string $lang): bool
171  {
172  return (bool) $this->int('att_' . $lang . '_delete');
173  }
174 
175  public function getSelectAll(): bool
176  {
177  return (bool) $this->int('select_cmd_all');
178  }
179 
180  public function getRoleIds(): array
181  {
182  return $this->intArray('role_id');
183  }
184 
185  public function getPostedRoleIds(): array
186  {
187  return $this->intArray('role_id_ctrl');
188  }
189 
190  public function getFilteredRoles(): int
191  {
192  return $this->int('filter');
193  }
194 
195  public function getSendMail(): string
196  {
197  return $this->str('send_mail');
198  }
199 
200  public function getPassword(): string
201  {
202  return $this->str('passwd');
203  }
204 
205  public function getUDFs(): array
206  {
207  return $this->strArray('udf');
208  }
209 
210  public function getPositions(): array
211  {
212  return $this->intArray('position');
213  }
214 
215  public function getCurrentPassword(): string
216  {
217  return $this->str('current_password');
218  }
219 
220  public function getNewPassword(): string
221  {
222  return $this->str('new_password');
223  }
224 
225  private function int(string $key): int
226  {
227  $source = $this->existsInPostOrQuery($key);
228  if ($source === '') {
229  return 0;
230  }
231 
232  $transformation = $this->refinery->kindlyTo()->int();
233  return $this->getFromQueryOrPost($key, $transformation, $source);
234  }
235 
236  private function bool(string $key): bool
237  {
238  $source = $this->existsInPostOrQuery($key);
239  if ($source === '') {
240  return false;
241  }
242 
243  $transformation = $this->refinery->kindlyTo()->bool();
244  return $this->getFromQueryOrPost($key, $transformation, $source);
245  }
246 
247  private function str(string $key): string
248  {
249  $source = $this->existsInPostOrQuery($key);
250  if ($source === '') {
251  return '';
252  }
253 
254  $transformation = $this->refinery->kindlyTo()->string();
255  return $this->getFromQueryOrPost($key, $transformation, $source);
256  }
257 
258  protected function strArray(string $key): array
259  {
260  $source = $this->existsInPostOrQuery($key);
261  if ($source === '') {
262  return [];
263  }
264 
265  $transformation = $this->refinery->custom()->transformation(
266  function ($arr) {
267  return array_column(
268  array_map(
269  static function ($k, $v): array {
270  if (is_array($v)) {
271  $v = '';
272  }
273  return [$k, \ilUtil::stripSlashes((string) $v)];
274  },
275  array_keys($arr),
276  $arr
277  ),
278  1,
279  0
280  );
281  }
282  );
283  return $this->getFromQueryOrPost($key, $transformation, $source);
284  }
285 
286  protected function intArray(string $key): array
287  {
288  $source = $this->existsInPostOrQuery($key);
289  if ($source === '') {
290  return [];
291  }
292 
293  $transformation = $this->refinery->custom()->transformation(
294  function ($arr) {
295  // keep keys(!), transform all values to int
296  return array_column(
297  array_map(
298  static function ($k, $v): array {
299  return [$k, (int) $v];
300  },
301  array_keys($arr),
302  $arr
303  ),
304  1,
305  0
306  );
307  }
308  );
309  return $this->getFromQueryOrPost($key, $transformation, $source);
310  }
311 
312 
317  public function getParsedBody(): array
318  {
319  return $this->request->getParsedBody();
320  }
321 
322  public function getRequest(): RequestInterface
323  {
324  return $this->request;
325  }
326 
327  public function isPost(): bool
328  {
329  return $this->request->getMethod() === 'POST';
330  }
331 
336  private function existsInPostOrQuery(string $key): string
337  {
338  if ($this->wrapper->post()->has($key)) {
339  return 'post';
340  }
341 
342  if ($this->wrapper->query()->has($key)) {
343  return 'query';
344  }
345 
346  return '';
347  }
348 
349  private function getFromQueryOrPost(string $key, Transformation $transformation, string $source): mixed
350  {
351  if ($source === 'query') {
352  return $this->wrapper->query()->retrieve($key, $transformation);
353  }
354 
355  return $this->wrapper->post()->retrieve($key, $transformation);
356  }
357 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFromQueryOrPost(string $key, Transformation $transformation, string $source)
__construct(RequestServices $request, private Refinery $refinery)
string $key
Consumer key/client ID value.
Definition: System.php:193
$lang
Definition: xapiexit.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
A transformation is a function from one datatype to another.
getMailSalutation(string $gender, string $lang)
Refinery Factory $refinery