ILIAS  release_8 Revision v8.24
class.ilBadgeGUIRequest.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\HTTP;
21
23{
25 protected Refinery\Factory $refinery;
26
27 public function __construct(
28 HTTP\Services $http,
29 Refinery\Factory $refinery
30 ) {
31 $this->initRequest(
32 $http,
34 );
35 }
36
37 protected function initRequest(
38 HTTP\Services $http,
39 Refinery\Factory $refinery
40 ): void {
41 $this->http = $http;
42 $this->refinery = $refinery;
43 }
44
45 // get string parameter kindly
46 protected function str(string $key): string
47 {
48 $t = $this->refinery->kindlyTo()->string();
49 return \ilUtil::stripSlashes((string) ($this->get($key, $t) ?? ""));
50 }
51
52 // get integer parameter kindly
53 protected function int(string $key): int
54 {
55 $t = $this->refinery->kindlyTo()->int();
56 return (int) ($this->get($key, $t) ?? 0);
57 }
58
59 // get integer array kindly
60 protected function intArray(string $key): array
61 {
62 if (!$this->isArray($key)) {
63 return [];
64 }
65 $t = $this->refinery->custom()->transformation(
66 static function (array $arr): array {
67 // keep keys(!), transform all values to int
68 return array_column(
69 array_map(
70 static function ($k, $v): array {
71 return [$k, (int) $v];
72 },
73 array_keys($arr),
74 $arr
75 ),
76 1,
77 0
78 );
79 }
80 );
81 return (array) ($this->get($key, $t) ?? []);
82 }
83
84 // get string array kindly
85 protected function strArray($key): array
86 {
87 if (!$this->isArray($key)) {
88 return [];
89 }
90 $t = $this->refinery->custom()->transformation(
91 function ($arr) {
92 // keep keys(!), transform all values to string
93 return array_column(
94 array_map(
95 function ($k, $v) {
96 if (is_array($v)) {
97 $v = "";
98 }
99 return [$k, \ilUtil::stripSlashes((string) $v)];
100 },
101 array_keys($arr),
102 $arr
103 ),
104 1,
105 0
106 );
107 }
108 );
109 return (array) ($this->get($key, $t) ?? []);
110 }
111
115 protected function isArray(string $key): bool
116 {
117 $no_transform = $this->refinery->identity();
118 $w = $this->http->wrapper();
119 if ($w->post()->has($key)) {
120 return is_array($w->post()->retrieve($key, $no_transform));
121 }
122 if ($w->query()->has($key)) {
123 return is_array($w->query()->retrieve($key, $no_transform));
124 }
125 return false;
126 }
127
131 protected function get(string $key, Refinery\Transformation $t)
132 {
133 $w = $this->http->wrapper();
134 if ($w->post()->has($key)) {
135 return $w->post()->retrieve($key, $t);
136 }
137 if ($w->query()->has($key)) {
138 return $w->query()->retrieve($key, $t);
139 }
140 return null;
141 }
142
144 public function getBadgeIds(): array
145 {
146 $badge_ids = $this->intArray("badge_id");
147 if (count($badge_ids) === 0 && $this->int("badge_id") > 0) {
148 $badge_ids = [$this->int("badge_id")];
149 }
150 return $badge_ids;
151 }
152
153 public function getBadgeId(): int
154 {
155 return $this->int("bid");
156 }
157
158 public function getId(): int
159 {
160 return $this->int("id");
161 }
162
164 public function getIds(): array
165 {
166 return $this->strArray("id");
167 }
168
169 public function getType(): string
170 {
171 return $this->str("type");
172 }
173
174 public function getTgt(): string
175 {
176 return $this->str("tgt");
177 }
178
179 public function getTemplateId(): int
180 {
181 return $this->int("tid");
182 }
183
184 public function getParentId(): int
185 {
186 return $this->int("pid");
187 }
188}
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
isArray(string $key)
Check if parameter is an array.
initRequest(HTTP\Services $http, Refinery\Factory $refinery)
Refinery Factory $refinery
__construct(HTTP\Services $http, Refinery\Factory $refinery)
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...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
isArray(string $key)
Check if parameter is an array.