ILIAS  release_8 Revision v8.24
class.ilLTIConsumerProviderTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
30{
34 protected string $editProviderCmd = '';
35
39 protected string $acceptProviderAsGlobalCmd = '';
40
44 protected string $acceptProviderAsGlobalMultiCmd = '';
45
49 protected string $resetProviderToUserScopeCmd = '';
50
54 protected string $resetProviderToUserScopeMultiCmd = '';
55
59 protected string $selectProviderCmd = '';
60
64 protected string $deleteProviderCmd = '';
65
69 protected string $deleteProviderMultiCmd = '';
70
74 protected bool $availabilityColumnEnabled = false;
75
79 protected bool $ownProviderColumnEnabled = false;
80
84 protected bool $providerCreatorColumnEnabled = false;
85
89 protected bool $actionsColumnEnabled = false;
90
94 protected bool $detailedUsagesEnabled = false;
95
96 protected array $filter;
97
98 public function __construct(?object $a_parent_obj, string $a_parent_cmd)
99 {
100 global $DIC; /* @var \ILIAS\DI\Container $DIC */
101
102 $this->setId('providers');
103 parent::__construct($a_parent_obj, $a_parent_cmd);
104
105 $this->setFormAction($DIC->ctrl()->getFormAction($a_parent_obj, $a_parent_cmd));
106 $this->setRowTemplate('tpl.lti_consume_provider_table_row.html', 'Modules/LTIConsumer');
107
108 $this->setTitle($DIC->language()->txt('tbl_provider_header'));
109 //$this->setDescription($DIC->language()->txt('tbl_provider_header_info'));
110 }
111
112 public function getTitle(): string
113 {
114 return $this->title;
115 }
116
117 public function getEditProviderCmd(): string
118 {
120 }
121
122 public function setEditProviderCmd(string $editProviderCmd): void
123 {
124 $this->editProviderCmd = $editProviderCmd;
125 }
126
127 public function getAcceptProviderAsGlobalCmd(): string
128 {
130 }
131
133 {
134 $this->acceptProviderAsGlobalCmd = $acceptProviderAsGlobalCmd;
135 }
136
137 public function getAcceptProviderAsGlobalMultiCmd(): string
138 {
140 }
141
143 {
144 $this->acceptProviderAsGlobalMultiCmd = $acceptProviderAsGlobalMultiCmd;
145 }
146
147 public function getResetProviderToUserScopeCmd(): string
148 {
150 }
151
153 {
154 $this->resetProviderToUserScopeCmd = $resetProviderToUserScopeCmd;
155 }
156
157 public function getResetProviderToUserScopeMultiCmd(): string
158 {
160 }
161
163 {
164 $this->resetProviderToUserScopeMultiCmd = $resetProviderToUserScopeMultiCmd;
165 }
166
167 public function getSelectProviderCmd(): string
168 {
170 }
171
172 public function setSelectProviderCmd(string $selectProviderCmd): void
173 {
174 $this->selectProviderCmd = $selectProviderCmd;
175 }
176
177 public function getDeleteProviderCmd(): string
178 {
180 }
181
182 public function setDeleteProviderCmd(string $deleteProviderCmd): void
183 {
184 $this->deleteProviderCmd = $deleteProviderCmd;
185 }
186
187 public function getDeleteProviderMultiCmd(): string
188 {
190 }
191
193 {
194 $this->deleteProviderMultiCmd = $deleteProviderMultiCmd;
195 }
196
197 public function isAvailabilityColumnEnabled(): bool
198 {
200 }
201
203 {
204 $this->availabilityColumnEnabled = $availabilityColumnEnabled;
205 }
206
207 public function isOwnProviderColumnEnabled(): bool
208 {
210 }
211
213 {
214 $this->ownProviderColumnEnabled = $ownProviderColumnEnabled;
215 }
216
217 public function isProviderCreatorColumnEnabled(): bool
218 {
220 }
221
223 {
224 $this->providerCreatorColumnEnabled = $providerCreatorColumnEnabled;
225 }
226
227 public function isActionsColumnEnabled(): bool
228 {
230 }
231
233 {
234 $this->actionsColumnEnabled = $actionsColumnEnabled;
235 }
236
237 public function isDetailedUsagesEnabled(): bool
238 {
240 }
241
243 {
244 $this->detailedUsagesEnabled = $detailedUsagesEnabled;
245 }
246
247 public function hasMultiCommands(): bool
248 {
250 return true;
251 }
252
254 return true;
255 }
256
257 return false;
258 }
259
260 public function init(): void
261 {
262 parent::determineSelectedColumns();
263
264 $this->initColumns();
265 $this->initFilter();
266 $this->initCommands();
267 }
268
269 protected function initCommands(): void
270 {
271 global $DIC; /* @var \ILIAS\DI\Container $DIC */
272
274 $this->addMultiCommand(
276 $DIC->language()->txt('lti_action_accept_providers_as_global')
277 );
278 }
279
281 $this->addMultiCommand(
283 $DIC->language()->txt('lti_action_reset_providers_to_user_scope')
284 );
285 }
286
287 if ($this->getDeleteProviderMultiCmd()) {
288 $this->addMultiCommand(
290 $DIC->language()->txt('lti_action_delete_providers')
291 );
292 }
293 }
294
295 protected function initColumns(): void
296 {
297 global $DIC; /* @var \ILIAS\DI\Container $DIC */
298
299 if ($this->hasMultiCommands()) {
300 $this->addColumn('', '', '1%');
301 }
302
303 $this->addColumn($DIC->language()->txt('tbl_lti_prov_icon'), 'icon');
304 $this->addColumn($DIC->language()->txt('tbl_lti_prov_title'), 'title');
305
306 if ($this->isColumnSelected('description')) {
307 $this->addColumn($DIC->language()->txt('tbl_lti_prov_description'), 'description');
308 }
309 if ($this->isColumnSelected('category')) {
310 $this->addColumn($DIC->language()->txt('tbl_lti_prov_category'), 'category');
311 }
312 if ($this->isColumnSelected('keywords')) {
313 $this->addColumn($DIC->language()->txt('tbl_lti_prov_keywords'), 'keywords');
314 }
315 if ($this->isColumnSelected('outcome')) {
316 $this->addColumn($DIC->language()->txt('tbl_lti_prov_outcome'), 'outcome');
317 }
318 if ($this->isColumnSelected('internal')) {
319 $this->addColumn($DIC->language()->txt('tbl_lti_prov_internal'), 'external');
320 }
321 if ($this->isColumnSelected('with_key')) {
322 $this->addColumn($DIC->language()->txt('tbl_lti_prov_with_key'), 'provider_key_customizable');
323 }
324
325 if ($this->isColumnSelected('availability') && $this->isAvailabilityColumnEnabled()) {
326 $this->addColumn($DIC->language()->txt('tbl_lti_prov_availability'), 'availability');
327 }
328
329 if ($this->isColumnSelected('own_provider') && $this->isOwnProviderColumnEnabled()) {
330 $this->addColumn($DIC->language()->txt('tbl_lti_prov_own_provider'), 'own_provider');
331 }
332
333 if ($this->isColumnSelected('provider_creator') && $this->isProviderCreatorColumnEnabled()) {
334 $this->addColumn($DIC->language()->txt('tbl_lti_prov_provider_creator'), 'provider_creator');
335 }
336
337 if ($this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
338 if ($this->isColumnSelected('usages_untrashed')) {
339 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages_untrashed'), 'usages_untrashed');
340 }
341
342 if ($this->isColumnSelected('usages_trashed')) {
343 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages_trashed'), 'usages_trashed');
344 }
345 } elseif ($this->isColumnSelected('usages_untrashed')) {
346 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages'), 'usages_untrashed');
347 }
348
349 if ($this->isActionsColumnEnabled()) {
350 $this->addColumn('', '', '1%');
351 }
352 }
353
354 public function determineSelectedColumns(): void
355 {
360 }
361
365 public function getSelectableColumns(): array
366 {
367 global $DIC; /* @var \ILIAS\DI\Container $DIC */
368
369 $columns = [];
370
371 $columns['description'] = [
372 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_description')
373 ];
374
375 $columns['category'] = [
376 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_category')
377 ];
378
379 $columns['keywords'] = [
380 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_keywords')
381 ];
382
383 $columns['outcome'] = [
384 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_outcome')
385 ];
386
387 $columns['internal'] = [
388 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_internal')
389 ];
390
391 $columns['with_key'] = [
392 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_with_key')
393 ];
394
395 if ($this->isAvailabilityColumnEnabled()) {
396 $columns['availability'] = [
397 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_availability')
398 ];
399 }
400
401 if ($this->isOwnProviderColumnEnabled()) {
402 $columns['own_provider'] = [
403 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_own_provider')
404 ];
405 }
406
407 if ($this->isProviderCreatorColumnEnabled()) {
408 $columns['provider_creator'] = [
409 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_provider_creator')
410 ];
411 }
412
413 $columns['usages_untrashed'] = [
414 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_usages_untrashed')
415 ];
416
417 if ($this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
418 $columns['usages_trashed'] = [
419 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_usages_trashed')
420 ];
421 }
422
423 return $columns;
424 }
425
426 public function initFilter(): void
427 {
428 global $DIC; /* @var \ILIAS\DI\Container $DIC */
429
430 $title = new ilTextInputGUI($DIC->language()->txt('tbl_lti_prov_title'), 'title');
431 $title->setMaxLength(64);
432 $title->setSize(20);
433 $this->addFilterItem($title);
434 $title->readFromSession();
435 $this->filter['title'] = $title->getValue();
436
437 $keyword = new ilTextInputGUI($DIC->language()->txt('tbl_lti_prov_keyword'), 'keyword');
438 $keyword->setMaxLength(64);
439 $keyword->setSize(20);
440 $this->addFilterItem($keyword);
441 $keyword->readFromSession();
442 $this->filter['keyword'] = $keyword->getValue();
443
444 $hasOutcome = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_outcome'), 'outcome');
445 $this->addFilterItem($hasOutcome);
446 $hasOutcome->readFromSession();
447 $this->filter['outcome'] = $hasOutcome->getValue();
448
449 $isInternal = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_internal'), 'internal');
450 $this->addFilterItem($isInternal);
451 $isInternal->readFromSession();
452 $this->filter['internal'] = $isInternal->getValue();
453
454 $isWithKey = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_with_key'), 'with_key');
455 $this->addFilterItem($isWithKey);
456 $isWithKey->readFromSession();
457 $this->filter['with_key'] = $isWithKey->getValue();
458
459 $category = new ilSelectInputGUI($DIC->language()->txt('tbl_lti_prov_category'), 'category');
460 $category->setOptions(array_merge(
461 ['' => $DIC->language()->txt('tbl_lti_prov_all_categories')],
463 ));
464 $this->addFilterItem($category);
465 $category->readFromSession();
466 $this->filter['category'] = $category->getValue();
467 }
468
469 protected function fillRow(array $a_set): void
470 {
471 if ($this->hasMultiCommands()) {
472 $this->tpl->setCurrentBlock('checkbox_col');
473 $this->tpl->setVariable('PROVIDER_ID', $a_set['id']);
474 $this->tpl->parseCurrentBlock();
475 }
476
477 if ($this->getSelectProviderCmd()) {
478 $this->tpl->setCurrentBlock('title_linked');
479 $this->tpl->setVariable('TITLE', $a_set['title']);
480 $this->tpl->setVariable('TITLE_HREF', $this->buildProviderLink(
481 $a_set['id'],
482 $this->getSelectProviderCmd()
483 ));
484 $this->tpl->parseCurrentBlock();
485 } elseif ($this->getEditProviderCmd()) {
486 $this->tpl->setCurrentBlock('title_linked');
487 $this->tpl->setVariable('TITLE', $a_set['title']);
488 $this->tpl->setVariable('TITLE_HREF', $this->buildProviderLink(
489 $a_set['id'],
490 $this->getEditProviderCmd()
491 ));
492 $this->tpl->parseCurrentBlock();
493 } else {
494 $this->tpl->setCurrentBlock('title');
495 $this->tpl->setVariable('TITLE', $a_set['title']);
496 $this->tpl->parseCurrentBlock();
497 }
498
499 if (isset($a_set['icon'])) {
500 $this->tpl->setVariable('ICON_SRC', $a_set['icon']);
501 $this->tpl->setVariable('ICON_ALT', basename($a_set['icon']));
502 } else {
503 $icon = ilObject::_getIcon(0, "small", "lti");
504 $this->tpl->setVariable('ICON_SRC', $icon);
505 $this->tpl->setVariable('ICON_ALT', 'lti');
506 }
507
508 if ($this->isColumnSelected('description')) {
509 $this->tpl->setVariable('DESCRIPTION', $a_set['description']);
510 }
511
512 if ($this->isColumnSelected('category')) {
513 $this->tpl->setVariable('CATEGORY', $this->getCategoryTranslation($a_set['category']));
514 }
515
516 if ($this->isColumnSelected('keywords')) {
517 $this->tpl->setVariable('KEYWORDS', $a_set['keywords']);
518 }
519
520 if ($this->isColumnSelected('outcome')) {
521 $this->tpl->setVariable('OUTCOME', $this->getHasOutcomeFormatted($a_set['outcome']));
522 }
523
524 if ($this->isColumnSelected('internal')) {
525 $this->tpl->setVariable('INTERNAL', $this->getIsInternalFormatted(!(bool) $a_set['external']));
526 }
527
528 if ($this->isColumnSelected('with_key')) {
529 $this->tpl->setVariable('WITH_KEY', $this->getIsWithKeyFormatted(!(bool) $a_set['provider_key_customizable']));
530 }
531
532 if ($this->isColumnSelected('availability') && $this->isAvailabilityColumnEnabled()) {
533 $this->tpl->setVariable('AVAILABILITY', $this->getAvailabilityLabel($a_set));
534 }
535
536 if ($this->isColumnSelected('own_provider') && $this->isOwnProviderColumnEnabled()) {
537 $this->tpl->setVariable('OWN_PROVIDER', $this->getOwnProviderLabel($a_set));
538 }
539
540 if ($this->isColumnSelected('provider_creator') && $this->isProviderCreatorColumnEnabled()) {
541 $this->tpl->setVariable('PROVIDER_CREATOR', $this->getProviderCreatorLabel($a_set));
542 }
543
544 if ($this->isColumnSelected('usages_untrashed')) {
545 $usagesUntrashed = $a_set['usages_untrashed'] ? $a_set['usages_untrashed'] : '';
546 $this->tpl->setVariable('USAGES_UNTRASHED', $usagesUntrashed);
547 }
548
549 if ($this->isColumnSelected('usages_trashed') && $this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
550 $usagesTrashed = $a_set['usages_trashed'] ? $a_set['usages_trashed'] : '';
551 $this->tpl->setVariable('USAGES_TRASHED', $usagesTrashed);
552 }
553
554 if ($this->isActionsColumnEnabled()) {
555 $this->tpl->setVariable('ACTIONS', $this->buildActionsListHtml($a_set));
556 }
557 }
558
559 protected function getHasOutcomeFormatted(bool $hasOutcome): string
560 {
561 global $DIC; /* @var \ILIAS\DI\Container $DIC */
562
563 return $hasOutcome ? $DIC->language()->txt('yes') : '';
564 }
565
566 protected function getIsInternalFormatted(bool $isInternal): string
567 {
568 global $DIC; /* @var \ILIAS\DI\Container $DIC */
569
570 return $isInternal ? $DIC->language()->txt('yes') : '';
571 }
572
573 protected function getIsWithKeyFormatted(bool $isWithKey): string
574 {
575 global $DIC; /* @var \ILIAS\DI\Container $DIC */
576
577 return $isWithKey ? $DIC->language()->txt('yes') : '';
578 }
579
580 protected function getCategoryTranslation(string $category): string
581 {
583 return $categories[$category];
584 }
585
586 protected function getAvailabilityLabel(array $data): string
587 {
588 global $DIC; /* @var \ILIAS\DI\Container $DIC */
589
590 switch ($data['availability']) {
592
593 return $DIC->language()->txt('lti_con_prov_availability_create');
594
596
597 return $DIC->language()->txt('lti_con_prov_availability_existing');
598
600
601 return $DIC->language()->txt('lti_con_prov_availability_non');
602 }
603 return '';
604 }
605
606 protected function getOwnProviderLabel(array $data): string
607 {
608 global $DIC; /* @var \ILIAS\DI\Container $DIC */
609
610 if ($data['creator'] == $DIC->user()->getId()) {
611 return $DIC->language()->txt('yes');
612 }
613
614 return '';
615 }
616
617 protected function getProviderCreatorLabel(array $data): string
618 {
619 global $DIC; /* @var \ILIAS\DI\Container $DIC */
620
621 if ($data['creator']) {
622 /* @var ilObjUser $user */
623 $user = ilObjectFactory::getInstanceByObjId($data['creator'], false);
624
625 if ($user) {
626 return $user->getFullname();
627 }
628
629 return $DIC->language()->txt('deleted_user');
630 }
631
632 return '';
633 }
634
635 protected function buildActionsListHtml(array $data): string
636 {
637 global $DIC; /* @var \ILIAS\DI\Container $DIC */
638
639 $items = $this->getActionItems($data);
640
641 if ($items !== []) {
642 return $DIC->ui()->renderer()->render(
643 $DIC->ui()->factory()->dropdown()->standard($items)->withLabel(
644 $DIC->language()->txt('actions')
645 )
646 );
647 }
648
649 return '';
650 }
651
655 protected function getActionItems(array $data): array
656 {
657 global $DIC; /* @var \ILIAS\DI\Container $DIC */
658
659 $items = array();
660
661 if ($this->getEditProviderCmd()) {
662 $items[] = $DIC->ui()->factory()->button()->shy(
663 $DIC->language()->txt('lti_action_edit_provider'),
664 $this->buildProviderLink($data['id'], $this->getEditProviderCmd())
665 );
666 }
667
668 if ($this->getAcceptProviderAsGlobalCmd()) {
669 $items[] = $DIC->ui()->factory()->button()->shy(
670 $DIC->language()->txt('lti_action_accept_provider_as_global'),
671 $this->buildProviderLink($data['id'], $this->getAcceptProviderAsGlobalCmd())
672 );
673 }
674
676 $items[] = $DIC->ui()->factory()->button()->shy(
677 $DIC->language()->txt('lti_action_reset_provider_to_user_scope'),
678 $this->buildProviderLink($data['id'], $this->getResetProviderToUserScopeCmd())
679 );
680 }
681
682 if ($this->getSelectProviderCmd()) {
683 $items[] = $DIC->ui()->factory()->button()->shy(
684 $DIC->language()->txt('lti_select_provider'),
685 $this->buildProviderLink($data['id'], $this->getSelectProviderCmd())
686 );
687 }
688
689 if ($this->getDeleteProviderCmd() && !$data['usages_untrashed'] && !$data['usages_trashed']) {
690 $items[] = $DIC->ui()->factory()->button()->shy(
691 $DIC->language()->txt('lti_delete_provider'),
692 $this->buildProviderLink($data['id'], $this->getDeleteProviderCmd())
693 );
694 }
695
696 return $items;
697 }
698
699 protected function buildProviderLink(int $providerId, string $command): string
700 {
701 global $DIC; /* @var \ILIAS\DI\Container $DIC */
702
703 $DIC->ctrl()->setParameter($this->parent_obj, 'provider_id', $providerId);
704 $link = $DIC->ctrl()->getLinkTarget($this->parent_obj, $command);
705 $DIC->ctrl()->setParameter($this->parent_obj, 'provider_id', 0);
706
707 return $link;
708 }
709
710 protected function isUserCreatedProviderResettableToUserScope(array $data): bool
711 {
712 return (bool) $data['creator'] && (bool) $data['accepted_by'];
713 }
714
715 protected static function isTrashEnabled(): bool
716 {
717 global $DIC; /* @var \ILIAS\DI\Container $DIC */
718
719 return (bool) $DIC->settings()->get('enable_trash', "0");
720 }
721}
This class represents a checkbox property in a property form.
setDetailedUsagesEnabled(bool $detailedUsagesEnabled)
setDeleteProviderMultiCmd(string $deleteProviderMultiCmd)
fillRow(array $a_set)
Standard Version of Fill Row.
setProviderCreatorColumnEnabled(bool $providerCreatorColumnEnabled)
setResetProviderToUserScopeMultiCmd(string $resetProviderToUserScopeMultiCmd)
setOwnProviderColumnEnabled(bool $ownProviderColumnEnabled)
setAcceptProviderAsGlobalMultiCmd(string $acceptProviderAsGlobalMultiCmd)
setResetProviderToUserScopeCmd(string $resetProviderToUserScopeCmd)
setAcceptProviderAsGlobalCmd(string $acceptProviderAsGlobalCmd)
setAvailabilityColumnEnabled(bool $availabilityColumnEnabled)
__construct(?object $a_parent_obj, string $a_parent_cmd)
buildProviderLink(int $providerId, string $command)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isColumnSelected(string $col)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
This class represents a text property in a property form.
global $DIC
Definition: feed.php:28
if(empty($clientId)) $providerId
Definition: ltitoken.php:82
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc