ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UserGUIRequest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\User;
22
23use ILIAS\HTTP\Services as RequestServices;
24use ILIAS\Refinery\Factory as Refinery;
26use Psr\Http\Message\RequestInterface;
28
30{
32 private RequestInterface $request;
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 getIds(): array
106 {
107 return $this->intArray('id');
108 }
109
110 public function getChecked(): array
111 {
112 return $this->intArray('chb');
113 }
114
115 public function getFieldType(): int
116 {
117 return $this->int('field_type');
118 }
119
120 public function getFields(): array
121 {
122 return $this->intArray('fields');
123 }
124
125 public function getSelectedAction(): string
126 {
127 return $this->str('selectedAction');
128 }
129
130 public function getFrSearch(): bool
131 {
132 return $this->bool('frsrch');
133 }
134
135 public function getSelect(): array
136 {
137 return $this->strArray('select');
138 }
139
140 public function getDefaultSessionReminder(): ?string
141 {
142 return $this->str('default_session_reminder') ?: (string) \ilSessionReminder::LEAD_TIME_DISABLED;
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 private function int(string $key): int
216 {
217 $source = $this->existsInPostOrQuery($key);
218 if ($source === '') {
219 return 0;
220 }
221
222 $transformation = $this->refinery->kindlyTo()->int();
223 return $this->getFromQueryOrPost($key, $transformation, $source);
224 }
225
226 private function bool(string $key): bool
227 {
228 $source = $this->existsInPostOrQuery($key);
229 if ($source === '') {
230 return false;
231 }
232
233 $transformation = $this->refinery->kindlyTo()->bool();
234 return $this->getFromQueryOrPost($key, $transformation, $source);
235 }
236
237 private function str(string $key): string
238 {
239 $source = $this->existsInPostOrQuery($key);
240 if ($source === '') {
241 return '';
242 }
243
244 $transformation = $this->refinery->kindlyTo()->string();
245 return $this->getFromQueryOrPost($key, $transformation, $source);
246 }
247
248 protected function strArray(string $key): array
249 {
250 $source = $this->existsInPostOrQuery($key);
251 if ($source === '') {
252 return [];
253 }
254
255 $transformation = $this->refinery->custom()->transformation(
256 function ($arr) {
257 return array_column(
258 array_map(
259 static function ($k, $v): array {
260 if (is_array($v)) {
261 $v = '';
262 }
263 return [$k, \ilUtil::stripSlashes((string) $v)];
264 },
265 array_keys($arr),
266 $arr
267 ),
268 1,
269 0
270 );
271 }
272 );
273 return $this->getFromQueryOrPost($key, $transformation, $source);
274 }
275
276 protected function intArray(string $key): array
277 {
278 $source = $this->existsInPostOrQuery($key);
279 if ($source === '') {
280 return [];
281 }
282
283 $transformation = $this->refinery->custom()->transformation(
284 function ($arr) {
285 // keep keys(!), transform all values to int
286 return array_column(
287 array_map(
288 static function ($k, $v): array {
289 return [$k, (int) $v];
290 },
291 array_keys($arr),
292 $arr
293 ),
294 1,
295 0
296 );
297 }
298 );
299 return $this->getFromQueryOrPost($key, $transformation, $source);
300 }
301
302
307 public function getParsedBody(): array
308 {
309 return $this->request->getParsedBody();
310 }
311
312 public function getRequest(): RequestInterface
313 {
314 return $this->request;
315 }
316
317 public function isPost(): bool
318 {
319 return $this->request->getMethod() === 'POST';
320 }
321
326 private function existsInPostOrQuery(string $key): string
327 {
328 if ($this->wrapper->post()->has($key)) {
329 return 'post';
330 }
331
332 if ($this->wrapper->query()->has($key)) {
333 return 'query';
334 }
335
336 return '';
337 }
338
339 private function getFromQueryOrPost(string $key, Transformation $transformation, string $source): mixed
340 {
341 if ($source === 'query') {
342 return $this->wrapper->query()->retrieve($key, $transformation);
343 }
344
345 return $this->wrapper->post()->retrieve($key, $transformation);
346 }
347}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
getMailSalutation(string $gender, string $lang)
getFromQueryOrPost(string $key, Transformation $transformation, string $source)
RequestInterface $request
__construct(RequestServices $request, private Refinery $refinery)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
A transformation is a function from one datatype to another.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: UserEvent.php:21
$lang
Definition: xapiexit.php:25