ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters): Generator
99 {
100 foreach ($this->records as $record) {
101 $record["icon"] = $record["icon"] ?? "lti";
102 $record["icon"] = $this->ui_factory->symbol()->icon()->standard($record["icon"], $record["icon"], IconAlias::SMALL);
103
104 if ($this->selectProviderForm) {
105 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $record['id']);
106 $record["title"] = $this->ui_factory->link()->standard($record['title'], $this->ctrl->getLinkTarget($this->parent_obj, "save"));
107 } else {
108 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $record['id']);
109 $record["title"] = $this->ui_factory->link()->standard($record['title'], $this->ctrl->getLinkTarget($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_SHOW_GLOBAL_PROVIDER_FORM));
110 }
111
112 $record["category"] = $this->getCategoryTranslation($record['category']);
113
114 $record["outcome"] = $this->getHasOutcomeFormatted($record['outcome']);
115 $record["internal"] = $this->getIsInternalFormatted(!$record['external']);
116 $record["with_key"] = $this->getIsWithKeyFormatted(!$record['provider_key_customizable']);
117
118 $record["availability"] = $this->getAvailabilityLabel($record);
119 $record["own_provider"] = $this->getOwnProviderLabel($record);
120 $record["provider_creator"] = $this->getProviderCreatorLabel($record);
121
122 yield $row_builder->buildDataRow((string) $record["id"], $record);
123 }
124 }
125
126 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
127 {
128 return count($this->records);
129 }
130
131 public function setData(array $data): void
132 {
133 $this->records = $data;
134 }
135
139 public function getHTML(bool $hasWriteAccess = false): string
140 {
141 $table = $this->ui_factory->table()
142 ->data($this->lng->txt('tbl_provider_header'), $this->getColumns(), $this)
143 ->withOrder(new Order('title', Order::ASC))
144 ->withRequest($this->request);
145
146 if ($hasWriteAccess) {
147 $table = $table->withActions($this->getActions());
148 }
149
150 return $this->ui_renderer->render($table);
151 }
152
153 private function getColumns(): array
154 {
155 return [
156 'icon' => $this->ui_factory->table()->column()->statusIcon($this->lng->txt('icon')),
157 'title' => $this->ui_factory->table()->column()->link($this->lng->txt('title')),
158 'description' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_description')),
159 'category' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_category'))->withIsOptional(true),
160 'keywords' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_keywords')),
161 'outcome' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_outcome'))->withIsOptional(true),
162 'internal' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_internal'))->withIsOptional(true),
163 'with_key' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_with_key')),
164 'availability' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_availability')),
165 'own_provider' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_own_provider'))->withIsOptional(true),
166 'provider_creator' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_provider_creator'))->withIsOptional(true),
167 'usages_untrashed' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_usages_untrashed')),
168 'usages_trashed' => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_usages_trashed'))->withIsOptional(true),
169 ];
170 }
171
175 private function getActions(): array
176 {
177 $df = new \ILIAS\Data\Factory();
178 $here_uri = $df->uri($this->request->getUri()->__toString());
179 $url_builder = new URLBuilder($here_uri);
180
181 $query_params_namespace = ['provider', 'table'];
182 list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
183 $query_params_namespace,
184 "provider_id",
185 "action"
186 );
187
188 $query = $this->wrapper->query();
189 if ($query->has($action_token->getName())) {
190 $action = $query->retrieve($action_token->getName(), $this->refinery->to()->string());
191 $ids = $query->retrieve($id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
192
193 switch ($action) {
194 case "edit":
195 $id = $ids[0] ?? null;
196 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
197 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_SHOW_USER_PROVIDER_FORM);
198 break;
199 case "delete_global":
200 if (count($ids) > 1) {
201 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
203 } else {
204 $id = $ids[0] ?? null;
205 $this->ctrl->setParameter($this->parent_obj, 'provider_id', $id);
206 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_DELETE_GLOBAL_PROVIDER);
207 }
208 break;
209 case "delete_user":
210 if (count($ids) > 1) {
211 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
212 $this->ctrl->redirect($this->parent_obj, ilLTIConsumerAdministrationGUI::CMD_DELETE_USER_PROVIDER_MULTI);
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_USER_PROVIDER);
217 }
218 break;
219 case "global":
220 if (count($ids) > 1) {
221 $this->ctrl->setParameter($this->parent_obj, 'provider_ids', implode(",", $ids));
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_ACCEPT_PROVIDER_AS_GLOBAL);
227 }
228 break;
229 case "reset":
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);
237 }
238 break;
239 }
240 }
241
242
243 $actions = [
244 "edit" => $this->ui_factory->table()->action()->single(
245 $this->lng->txt('lti_action_edit_provider'),
246 $url_builder->withParameter($action_token, "edit"),
247 $id_token
248 ),
249 ];
250
251 if ($this->acceptProviderAsGlobal) {
252 $actions["global"] = $this->ui_factory->table()->action()->standard(
253 $this->lng->txt('lti_action_accept_provider_as_global'),
254 $url_builder->withParameter($action_token, "global"),
255 $id_token
256 );
257 $actions["delete_user"] = $this->ui_factory->table()->action()->standard(
258 $this->lng->txt('lti_delete_provider'),
259 $url_builder->withParameter($action_token, "delete_user"),
260 $id_token
261 );
262 }
263
264 if ($this->resetProviderToUserScope) {
265 $actions["reset"] = $this->ui_factory->table()->action()->standard(
266 $this->lng->txt('lti_action_reset_provider_to_user_scope'),
267 $url_builder->withParameter($action_token, "reset"),
268 $id_token
269 );
270 $actions["delete_global"] = $this->ui_factory->table()->action()->standard(
271 $this->lng->txt('lti_delete_provider'),
272 $url_builder->withParameter($action_token, "delete_global"),
273 $id_token
274 );
275 }
276
277 return $actions;
278 }
279
280 protected function getHasOutcomeFormatted(bool $hasOutcome): string
281 {
282 global $DIC;
283
284 return $hasOutcome ? $DIC->language()->txt('yes') : '';
285 }
286
287 protected function getIsInternalFormatted(bool $isInternal): string
288 {
289 global $DIC;
290
291 return $isInternal ? $DIC->language()->txt('yes') : '';
292 }
293
294 protected function getIsWithKeyFormatted(bool $isWithKey): string
295 {
296 global $DIC;
297
298 return $isWithKey ? $DIC->language()->txt('yes') : '';
299 }
300
301 protected function getCategoryTranslation(string $category): string
302 {
304 return $categories[$category];
305 }
306
307 protected function getAvailabilityLabel(array $data): string
308 {
309 global $DIC;
310
311 return match ($data['availability']) {
312 ilLTIConsumeProvider::AVAILABILITY_CREATE => $DIC->language()->txt('lti_con_prov_availability_create'),
313 ilLTIConsumeProvider::AVAILABILITY_EXISTING => $DIC->language()->txt('lti_con_prov_availability_existing'),
314 ilLTIConsumeProvider::AVAILABILITY_NONE => $DIC->language()->txt('lti_con_prov_availability_non'),
315 default => '',
316 };
317 }
318
319 protected function getOwnProviderLabel(array $data): string
320 {
321 global $DIC;
322
323 if ($data['creator'] == $DIC->user()->getId()) {
324 return $DIC->language()->txt('yes');
325 }
326
327 return '';
328 }
329
334 protected function getProviderCreatorLabel(array $data): string
335 {
336 global $DIC;
337
338 if ($data['creator']) {
339 /* @var ilObjUser $user */
340 $user = ilObjectFactory::getInstanceByObjId($data['creator'], false);
341
342 if ($user) {
343 return $user->getFullname();
344 }
345
346 return $DIC->language()->txt('deleted_user');
347 }
348
349 return '';
350 }
351
355 public function getFilter(): Filter
356 {
357 $filter_inputs = [
358 'title' => $this->ui_factory->input()->field()->text($this->lng->txt("title")),
359 'keywords' => $this->ui_factory->input()->field()->text($this->lng->txt("tbl_lti_prov_keywords")),
360 'outcome' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_outcome"), [
361 'yes' => $this->lng->txt('yes'),
362 'no' => $this->lng->txt('no'),
363 ]),
364 'internal' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_internal"), [
365 'yes' => $this->lng->txt('yes'),
366 'no' => $this->lng->txt('no'),
367 ]),
368 'with_key' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_with_key"), [
369 'yes' => $this->lng->txt('yes'),
370 'no' => $this->lng->txt('no'),
371 ]),
372 'category' => $this->ui_factory->input()->field()->select($this->lng->txt("tbl_lti_prov_category"), ilLTIConsumeProvider::getCategoriesSelectOptions()),
373 ];
374
375 $active = array_fill(0, count($filter_inputs), true);
376
377 return $this->ui_service->filter()->standard(
378 'lti_consumer_provider_table',
379 $this->ctrl->getLinkTarget($this->parent_obj, $this->parent_cmd),
380 $filter_inputs,
381 $active,
382 true
383 );
384 }
385}
$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
ServerRequestInterface RequestInterface $request
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__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.
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