ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilLTIConsumerProviderTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Message\RequestInterface;
33
43{
44 protected ilLanguage $lng;
46 protected \ILIAS\UI\Renderer $ui_renderer;
48 private ServerRequestInterface|RequestInterface $request;
49 protected \ILIAS\Data\Factory $data_factory;
52 protected \ILIAS\Refinery\Factory $refinery;
53 private array $records;
54 public ?object $parent_obj;
55 public ?string $parent_cmd;
56 private bool $acceptProviderAsGlobal = false;
57 private bool $resetProviderToUserScope = false;
58 private bool $selectProviderForm = false;
59
60 public function __construct(?object $a_parent_obj, ?string $a_parent_cmd)
61 {
62 global $DIC;
63
64 $this->lng = $DIC->language();
65 $this->ui_factory = $DIC->ui()->factory();
66 $this->ui_renderer = $DIC->ui()->renderer();
67 $this->ui_service = $DIC->uiService();
68 $this->request = $DIC->http()->request();
69 $this->data_factory = new \ILIAS\Data\Factory();
70 $this->ctrl = $DIC->ctrl();
71 $this->wrapper = $DIC->http()->wrapper();
72 $this->refinery = $DIC->refinery();
73
74 $this->parent_obj = $a_parent_obj;
75 $this->parent_cmd = $a_parent_cmd;
76 }
77
78 public function enableAcceptProviderAsGlobal(): void
79 {
80 $this->acceptProviderAsGlobal = true;
81 }
82
83 public function enableResetProviderToUserScope(): void
84 {
85 $this->resetProviderToUserScope = true;
86 }
87
88 public function enableSelectProviderForm(): void
89 {
90 $this->selectProviderForm = true;
91 }
92
98 public function getRows(
99 DataRowBuilder $row_builder,
100 array $visible_column_ids,
102 Order $order,
103 mixed $additional_viewcontrol_data,
104 mixed $filter_data,
105 mixed $additional_parameters
106 ): Generator {
107 foreach ($this->records as $record) {
108 $record["icon"] = $record["icon"] ?? "lti";
109 $record["icon"] = $this->ui_factory->symbol()->icon()->standard($record["icon"], $record["icon"], IconAlias::SMALL);
110
111 if ($this->selectProviderForm) {
112 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $record['id']);
113 $record["title"] = $this->ui_factory->link()->standard($record['title'], $this->ctrl->getLinkTarget($this->parent_obj, "save"));
114 } else {
115 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $record['id']);
116 $record["title"] = $this->ui_factory->link()->standard($record['title'], $this->ctrl->getLinkTarget($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_SHOW_GLOBAL_PROVIDER_FORM));
117 }
118
119 $record["category"] = $this->getCategoryTranslation($record['category']);
120
121 $record["outcome"] = $this->getHasOutcomeFormatted($record['outcome']);
122 $record["internal"] = $this->getIsInternalFormatted(!$record['external']);
123 $record["with_key"] = $this->getIsWithKeyFormatted(!$record['provider_key_customizable']);
124
125 $record["availability"] = $this->getAvailabilityLabel($record);
126 $record["own_provider"] = $this->getOwnProviderLabel($record);
127 $record["provider_creator"] = $this->getProviderCreatorLabel($record);
128
129 yield $row_builder->buildDataRow((string) $record["id"], $record);
130 }
131 }
132
133 public function getTotalRowCount(
134 mixed $additional_viewcontrol_data,
135 mixed $filter_data,
136 mixed $additional_parameters
137 ): ?int {
138 return count($this->records);
139 }
140
141 public function setData(array $data): void
142 {
143 $this->records = $data;
144 }
145
149 public function getHTML(bool $hasWriteAccess = false): string
150 {
151 $table = $this->ui_factory->table()
152 ->data($this->lng->txt('tbl_provider_header'), $this->getColumns(), $this)
153 ->withOrder(new Order('title', Order::ASC))
154 ->withRequest($this->request);
155
156 if ($hasWriteAccess) {
157 $table = $table->withActions($this->getActions());
158 }
159
160 return $this->ui_renderer->render($table);
161 }
162
163 private function getColumns(): array
164 {
165 return [
166 'icon' => $this->ui_factory->table()->column()->statusIcon($this->lng->txt('icon')),
167 'title' => $this->ui_factory->table()->column()->link($this->lng->txt('title')),
168 'description' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_description')),
169 'category' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_category'))->withIsOptional(true),
170 'keywords' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_keywords')),
171 'outcome' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_outcome'))->withIsOptional(true),
172 'internal' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_internal'))->withIsOptional(true),
173 'with_key' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_with_key')),
174 'availability' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_availability')),
175 'own_provider' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_own_provider'))->withIsOptional(true),
176 'provider_creator' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_provider_creator'))->withIsOptional(true),
177 'usages_untrashed' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_usages_untrashed')),
178 'usages_trashed' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_usages_trashed'))->withIsOptional(true),
179 ];
180 }
181
185 private function getActions(): array
186 {
187 $df = new \ILIAS\Data\Factory();
188 $here_uri = $df->uri($this->request->getUri()->__toString());
189 $url_builder = new URLBuilder($here_uri);
190
191 $query_params_namespace = ['provider', 'table'];
192 list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
193 $query_params_namespace,
194 "provider_id",
195 "action"
196 );
197
198 $query = $this->wrapper->query();
199 if ($query->has($action_token->getName())) {
200 $action = $query->retrieve($action_token->getName(), $this->refinery->to()->string());
201 $ids = $query->retrieve($id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
202
203 switch ($action) {
204 case "edit":
205 $id = $ids[0] ?? null;
206 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
207 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_SHOW_USER_PROVIDER_FORM);
208 break;
209 case "delete_global":
210 if (count($ids) > 1) {
211 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
213 } else {
214 $id = $ids[0] ?? null;
215 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
216 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_DELETE_GLOBAL_PROVIDER);
217 }
218 break;
219 case "delete_user":
220 if (count($ids) > 1) {
221 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
222 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_DELETE_USER_PROVIDER_MULTI);
223 } else {
224 $id = $ids[0] ?? null;
225 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
226 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_DELETE_USER_PROVIDER);
227 }
228 break;
229 case "global":
230 if (count($ids) > 1) {
231 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
233 } else {
234 $id = $ids[0] ?? null;
235 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
236 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_ACCEPT_PROVIDER_AS_GLOBAL);
237 }
238 break;
239 case "reset":
240 if (count($ids) > 1) {
241 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
243 } else {
244 $id = $ids[0] ?? null;
245 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
247 }
248 break;
249 }
250 }
251
252
253 $actions = [
254 "edit" => $this->ui_factory->table()->action()->single(
255 $this->lng->txt('lti_action_edit_provider'),
256 $url_builder->withParameter($action_token, "edit"),
257 $id_token
258 ),
259 ];
260
261 if ($this->acceptProviderAsGlobal) {
262 $actions["global"] = $this->ui_factory->table()->action()->standard(
263 $this->lng->txt('lti_action_accept_provider_as_global'),
264 $url_builder->withParameter($action_token, "global"),
265 $id_token
266 );
267 $actions["delete_user"] = $this->ui_factory->table()->action()->standard(
268 $this->lng->txt('lti_delete_provider'),
269 $url_builder->withParameter($action_token, "delete_user"),
270 $id_token
271 );
272 }
273
274 if ($this->resetProviderToUserScope) {
275 $actions["reset"] = $this->ui_factory->table()->action()->standard(
276 $this->lng->txt('lti_action_reset_provider_to_user_scope'),
277 $url_builder->withParameter($action_token, "reset"),
278 $id_token
279 );
280 $actions["delete_global"] = $this->ui_factory->table()->action()->standard(
281 $this->lng->txt('lti_delete_provider'),
282 $url_builder->withParameter($action_token, "delete_global"),
283 $id_token
284 );
285 }
286
287 return $actions;
288 }
289
290 protected function getHasOutcomeFormatted(bool $hasOutcome): string
291 {
292 global $DIC;
293
294 return $hasOutcome ? $DIC->language()->txt('yes') : '';
295 }
296
297 protected function getIsInternalFormatted(bool $isInternal): string
298 {
299 global $DIC;
300
301 return $isInternal ? $DIC->language()->txt('yes') : '';
302 }
303
304 protected function getIsWithKeyFormatted(bool $isWithKey): string
305 {
306 global $DIC;
307
308 return $isWithKey ? $DIC->language()->txt('yes') : '';
309 }
310
311 protected function getCategoryTranslation(string $category): string
312 {
314 return $categories[$category];
315 }
316
317 protected function getAvailabilityLabel(array $data): string
318 {
319 global $DIC;
320
321 return match ($data['availability']) {
322 ilLTIConsumeProvider::AVAILABILITY_CREATE => $DIC->language()->txt('lti_con_prov_availability_create'),
323 ilLTIConsumeProvider::AVAILABILITY_EXISTING => $DIC->language()->txt('lti_con_prov_availability_existing'),
324 ilLTIConsumeProvider::AVAILABILITY_NONE => $DIC->language()->txt('lti_con_prov_availability_non'),
325 default => '',
326 };
327 }
328
329 protected function getOwnProviderLabel(array $data): string
330 {
331 global $DIC;
332
333 if ($data['creator'] == $DIC->user()->getId()) {
334 return $DIC->language()->txt('yes');
335 }
336
337 return '';
338 }
339
344 protected function getProviderCreatorLabel(array $data): string
345 {
346 global $DIC;
347
348 if ($data['creator']) {
349 /* @var ilObjUser $user */
350 $user = ilObjectFactory::getInstanceByObjId($data['creator'], false);
351
352 if ($user) {
353 return $user->getFullname();
354 }
355
356 return $DIC->language()->txt('deleted_user');
357 }
358
359 return '';
360 }
361
365 public function getFilter(): Filter
366 {
367 $filter_inputs = [
368 'title' => $this->ui_factory->input()->field()->text($this->lng->txt("title")),
369 'keywords' => $this->ui_factory->input()->field()->text($this->lng->txt("tbl_lti_prov_keywords")),
370 'outcome' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_outcome"), [
371 'yes' => $this->lng->txt('yes'),
372 'no' => $this->lng->txt('no'),
373 ]),
374 'internal' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_internal"), [
375 'yes' => $this->lng->txt('yes'),
376 'no' => $this->lng->txt('no'),
377 ]),
378 'with_key' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_with_key"), [
379 'yes' => $this->lng->txt('yes'),
380 'no' => $this->lng->txt('no'),
381 ]),
382 'category' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_category"), ilLTIConsumeProvider::getCategoriesSelectOptions()),
383 ];
384
385 $active = array_fill(0, count($filter_inputs), true);
386
387 return $this->ui_service->filter()->standard(
388 'lti_consumer_provider_table',
389 $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd),
390 $filter_inputs,
391 $active,
392 true
393 );
394 }
395}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
ServerRequestInterface RequestInterface $request
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
__construct(?object $a_parent_obj, ?string $a_parent_cmd)
language handling
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Filter service.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a standard filter.
Definition: Standard.php:27
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26