ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLTIConsumerProviderTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
15{
19 protected $editProviderCmd = '';
20
25
30
35
40
44 protected $selectProviderCmd = '';
45
49 protected $deleteProviderCmd = '';
50
55
59 protected $availabilityColumnEnabled = false;
60
64 protected $ownProviderColumnEnabled = false;
65
70
74 protected $actionsColumnEnabled = false;
75
79 protected $detailedUsagesEnabled = false;
80
81 public function __construct($a_parent_obj, $a_parent_cmd)
82 {
83 global $DIC; /* @var \ILIAS\DI\Container $DIC */
84
85 $this->setId('providers');
86 parent::__construct($a_parent_obj, $a_parent_cmd);
87
88 $this->setFormAction($DIC->ctrl()->getFormAction($a_parent_obj, $a_parent_cmd));
89 $this->setRowTemplate('tpl.lti_consume_provider_table_row.html', 'Modules/LTIConsumer');
90
91 $this->setTitle($DIC->language()->txt('tbl_provider_header'));
92 //$this->setDescription($DIC->language()->txt('tbl_provider_header_info'));
93 }
94
95 public function getTitle()
96 {
97 return $this->title;
98 }
99
103 public function getEditProviderCmd() : string
104 {
106 }
107
111 public function setEditProviderCmd(string $editProviderCmd)
112 {
113 $this->editProviderCmd = $editProviderCmd;
114 }
115
119 public function getAcceptProviderAsGlobalCmd() : string
120 {
122 }
123
128 {
129 $this->acceptProviderAsGlobalCmd = $acceptProviderAsGlobalCmd;
130 }
131
135 public function getAcceptProviderAsGlobalMultiCmd() : string
136 {
138 }
139
144 {
145 $this->acceptProviderAsGlobalMultiCmd = $acceptProviderAsGlobalMultiCmd;
146 }
147
151 public function getResetProviderToUserScopeCmd() : string
152 {
154 }
155
160 {
161 $this->resetProviderToUserScopeCmd = $resetProviderToUserScopeCmd;
162 }
163
167 public function getResetProviderToUserScopeMultiCmd() : string
168 {
170 }
171
176 {
177 $this->resetProviderToUserScopeMultiCmd = $resetProviderToUserScopeMultiCmd;
178 }
179
183 public function getSelectProviderCmd() : string
184 {
186 }
187
192 {
193 $this->selectProviderCmd = $selectProviderCmd;
194 }
195
199 public function getDeleteProviderCmd() : string
200 {
202 }
203
208 {
209 $this->deleteProviderCmd = $deleteProviderCmd;
210 }
211
215 public function getDeleteProviderMultiCmd() : string
216 {
218 }
219
224 {
225 $this->deleteProviderMultiCmd = $deleteProviderMultiCmd;
226 }
227
231 public function isAvailabilityColumnEnabled() : bool
232 {
234 }
235
240 {
241 $this->availabilityColumnEnabled = $availabilityColumnEnabled;
242 }
243
247 public function isOwnProviderColumnEnabled() : bool
248 {
250 }
251
256 {
257 $this->ownProviderColumnEnabled = $ownProviderColumnEnabled;
258 }
259
263 public function isProviderCreatorColumnEnabled() : bool
264 {
266 }
267
272 {
273 $this->providerCreatorColumnEnabled = $providerCreatorColumnEnabled;
274 }
275
279 public function isActionsColumnEnabled() : bool
280 {
282 }
283
288 {
289 $this->actionsColumnEnabled = $actionsColumnEnabled;
290 }
291
295 public function isDetailedUsagesEnabled() : bool
296 {
298 }
299
304 {
305 $this->detailedUsagesEnabled = $detailedUsagesEnabled;
306 }
307
308 public function hasMultiCommands()
309 {
311 return true;
312 }
313
315 return true;
316 }
317
318 return false;
319 }
320
321 public function init()
322 {
323 parent::determineSelectedColumns();
324
325 $this->initColumns();
326 $this->initFilter();
327 $this->initCommands();
328 }
329
330 protected function initCommands()
331 {
332 global $DIC; /* @var \ILIAS\DI\Container $DIC */
333
335 $this->addMultiCommand(
337 $DIC->language()->txt('lti_action_accept_providers_as_global')
338 );
339 }
340
342 $this->addMultiCommand(
344 $DIC->language()->txt('lti_action_reset_providers_to_user_scope')
345 );
346 }
347
348 if ($this->getDeleteProviderMultiCmd()) {
349 $this->addMultiCommand(
351 $DIC->language()->txt('lti_action_delete_providers')
352 );
353 }
354 }
355
356 protected function initColumns()
357 {
358 global $DIC; /* @var \ILIAS\DI\Container $DIC */
359
360 if ($this->hasMultiCommands()) {
361 $this->addColumn('', '', '1%');
362 }
363
364 $this->addColumn($DIC->language()->txt('tbl_lti_prov_icon'), 'icon');
365 $this->addColumn($DIC->language()->txt('tbl_lti_prov_title'), 'title');
366
367 if ($this->isColumnSelected('description')) {
368 $this->addColumn($DIC->language()->txt('tbl_lti_prov_description'), 'description');
369 }
370 if ($this->isColumnSelected('category')) {
371 $this->addColumn($DIC->language()->txt('tbl_lti_prov_category'), 'category');
372 }
373 if ($this->isColumnSelected('keywords')) {
374 $this->addColumn($DIC->language()->txt('tbl_lti_prov_keywords'), 'keywords');
375 }
376 if ($this->isColumnSelected('outcome')) {
377 $this->addColumn($DIC->language()->txt('tbl_lti_prov_outcome'), 'outcome');
378 }
379 if ($this->isColumnSelected('internal')) {
380 $this->addColumn($DIC->language()->txt('tbl_lti_prov_internal'), 'external');
381 }
382 if ($this->isColumnSelected('with_key')) {
383 $this->addColumn($DIC->language()->txt('tbl_lti_prov_with_key'), 'provider_key_customizable');
384 }
385
386 if ($this->isColumnSelected('availability') && $this->isAvailabilityColumnEnabled()) {
387 $this->addColumn($DIC->language()->txt('tbl_lti_prov_availability'), 'availability');
388 }
389
390 if ($this->isColumnSelected('own_provider') && $this->isOwnProviderColumnEnabled()) {
391 $this->addColumn($DIC->language()->txt('tbl_lti_prov_own_provider'), 'own_provider');
392 }
393
394 if ($this->isColumnSelected('provider_creator') && $this->isProviderCreatorColumnEnabled()) {
395 $this->addColumn($DIC->language()->txt('tbl_lti_prov_provider_creator'), 'provider_creator');
396 }
397
398 if ($this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
399 if ($this->isColumnSelected('usages_untrashed')) {
400 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages_untrashed'), 'usages_untrashed');
401 }
402
403 if ($this->isColumnSelected('usages_trashed')) {
404 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages_trashed'), 'usages_trashed');
405 }
406 } elseif ($this->isColumnSelected('usages_untrashed')) {
407 $this->addColumn($DIC->language()->txt('tbl_lti_prov_usages'), 'usages_untrashed');
408 }
409
410 if ($this->isActionsColumnEnabled()) {
411 $this->addColumn('', '', '1%');
412 }
413 }
414
415 public function determineSelectedColumns()
416 {
421 }
422
423 public function getSelectableColumns()
424 {
425 global $DIC; /* @var \ILIAS\DI\Container $DIC */
426
427 $columns = [];
428
429 $columns['description'] = [
430 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_description')
431 ];
432
433 $columns['category'] = [
434 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_category')
435 ];
436
437 $columns['keywords'] = [
438 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_keywords')
439 ];
440
441 $columns['outcome'] = [
442 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_outcome')
443 ];
444
445 $columns['internal'] = [
446 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_internal')
447 ];
448
449 $columns['with_key'] = [
450 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_with_key')
451 ];
452
453 if ($this->isAvailabilityColumnEnabled()) {
454 $columns['availability'] = [
455 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_availability')
456 ];
457 }
458
459 if ($this->isOwnProviderColumnEnabled()) {
460 $columns['own_provider'] = [
461 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_own_provider')
462 ];
463 }
464
465 if ($this->isProviderCreatorColumnEnabled()) {
466 $columns['provider_creator'] = [
467 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_provider_creator')
468 ];
469 }
470
471 $columns['usages_untrashed'] = [
472 'default' => true, 'txt' => $DIC->language()->txt('tbl_lti_prov_usages_untrashed')
473 ];
474
475 if ($this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
476 $columns['usages_trashed'] = [
477 'default' => false, 'txt' => $DIC->language()->txt('tbl_lti_prov_usages_trashed')
478 ];
479 }
480
481 return $columns;
482 }
483
484 public function initFilter()
485 {
486 global $DIC; /* @var \ILIAS\DI\Container $DIC */
487
488 $title = new ilTextInputGUI($DIC->language()->txt('tbl_lti_prov_title'), 'title');
489 $title->setMaxLength(64);
490 $title->setSize(20);
491 $this->addFilterItem($title);
492 $title->readFromSession();
493 $this->filter['title'] = $title->getValue();
494
495 $keyword = new ilTextInputGUI($DIC->language()->txt('tbl_lti_prov_keyword'), 'keyword');
496 $keyword->setMaxLength(64);
497 $keyword->setSize(20);
498 $this->addFilterItem($keyword);
499 $keyword->readFromSession();
500 $this->filter['keyword'] = $keyword->getValue();
501
502 $hasOutcome = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_outcome'), 'outcome');
503 $this->addFilterItem($hasOutcome);
504 $hasOutcome->readFromSession();
505 $this->filter['outcome'] = $hasOutcome->getValue();
506
507 $isInternal = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_internal'), 'internal');
508 $this->addFilterItem($isInternal);
509 $isInternal->readFromSession();
510 $this->filter['internal'] = $isInternal->getValue();
511
512 $isWithKey = new ilCheckboxInputGUI($DIC->language()->txt('tbl_lti_prov_with_key'), 'with_key');
513 $this->addFilterItem($isWithKey);
514 $isWithKey->readFromSession();
515 $this->filter['with_key'] = $isWithKey->getValue();
516
517 $category = new ilSelectInputGUI($DIC->language()->txt('tbl_lti_prov_category'), 'category');
518 $category->setOptions(array_merge(
519 ['' => $DIC->language()->txt('tbl_lti_prov_all_categories')],
521 ));
522 $this->addFilterItem($category);
523 $category->readFromSession();
524 $this->filter['category'] = $category->getValue();
525 }
526
527 protected function fillRow($data)
528 {
529 if ($this->hasMultiCommands()) {
530 $this->tpl->setCurrentBlock('checkbox_col');
531 $this->tpl->setVariable('PROVIDER_ID', $data['id']);
532 $this->tpl->parseCurrentBlock();
533 }
534
535 if ($this->getSelectProviderCmd()) {
536 $this->tpl->setCurrentBlock('title_linked');
537 $this->tpl->setVariable('TITLE', $data['title']);
538 $this->tpl->setVariable('TITLE_HREF', $this->buildProviderLink(
539 $data['id'],
540 $this->getSelectProviderCmd()
541 ));
542 $this->tpl->parseCurrentBlock();
543 } elseif ($this->getEditProviderCmd()) {
544 $this->tpl->setCurrentBlock('title_linked');
545 $this->tpl->setVariable('TITLE', $data['title']);
546 $this->tpl->setVariable('TITLE_HREF', $this->buildProviderLink(
547 $data['id'],
548 $this->getEditProviderCmd()
549 ));
550 $this->tpl->parseCurrentBlock();
551 } else {
552 $this->tpl->setCurrentBlock('title');
553 $this->tpl->setVariable('TITLE', $data['title']);
554 $this->tpl->parseCurrentBlock();
555 }
556
557 if ($data['icon']) {
558 $this->tpl->setVariable('ICON_SRC', $data['icon']);
559 $this->tpl->setVariable('ICON_ALT', basename($data['icon']));
560 } else {
561 $icon = ilObject::_getIcon("", "small", "lti");
562 $this->tpl->setVariable('ICON_SRC', $icon);
563 $this->tpl->setVariable('ICON_ALT', 'lti');
564 }
565
566 if ($this->isColumnSelected('description')) {
567 $this->tpl->setVariable('DESCRIPTION', $data['description']);
568 }
569
570 if ($this->isColumnSelected('category')) {
571 $this->tpl->setVariable('CATEGORY', $this->getCategoryTranslation($data['category']));
572 }
573
574 if ($this->isColumnSelected('keywords')) {
575 $this->tpl->setVariable('KEYWORDS', $this->getKeywordsFormatted($data['keywords']));
576 }
577
578 if ($this->isColumnSelected('outcome')) {
579 $this->tpl->setVariable('OUTCOME', $this->getHasOutcomeFormatted($data['outcome']));
580 }
581
582 if ($this->isColumnSelected('internal')) {
583 $this->tpl->setVariable('INTERNAL', $this->getIsInternalFormatted(!(bool) $data['external']));
584 }
585
586 if ($this->isColumnSelected('with_key')) {
587 $this->tpl->setVariable('WITH_KEY', $this->getIsWithKeyFormatted(!(bool) $data['provider_key_customizable']));
588 }
589
590 if ($this->isColumnSelected('availability') && $this->isAvailabilityColumnEnabled()) {
591 $this->tpl->setVariable('AVAILABILITY', $this->getAvailabilityLabel($data));
592 }
593
594 if ($this->isColumnSelected('own_provider') && $this->isOwnProviderColumnEnabled()) {
595 $this->tpl->setVariable('OWN_PROVIDER', $this->getOwnProviderLabel($data));
596 }
597
598 if ($this->isColumnSelected('provider_creator') && $this->isProviderCreatorColumnEnabled()) {
599 $this->tpl->setVariable('PROVIDER_CREATOR', $this->getProviderCreatorLabel($data));
600 }
601
602 if ($this->isColumnSelected('usages_untrashed')) {
603 $usagesUntrashed = $data['usages_untrashed'] ? $data['usages_untrashed'] : '';
604 $this->tpl->setVariable('USAGES_UNTRASHED', $usagesUntrashed);
605 }
606
607 if ($this->isColumnSelected('usages_trashed') && $this->isDetailedUsagesEnabled() && self::isTrashEnabled()) {
608 $usagesTrashed = $data['usages_trashed'] ? $data['usages_trashed'] : '';
609 $this->tpl->setVariable('USAGES_TRASHED', $usagesTrashed);
610 }
611
612 if ($this->isActionsColumnEnabled()) {
613 $this->tpl->setVariable('ACTIONS', $this->buildActionsListHtml($data));
614 }
615 }
616
617 protected function getHasOutcomeFormatted($hasOutcome)
618 {
619 global $DIC; /* @var \ILIAS\DI\Container $DIC */
620
621 return $hasOutcome ? $DIC->language()->txt('yes') : '';
622 }
623
624 protected function getIsInternalFormatted($isInternal)
625 {
626 global $DIC; /* @var \ILIAS\DI\Container $DIC */
627
628 return $isInternal ? $DIC->language()->txt('yes') : '';
629 }
630
631 protected function getIsWithKeyFormatted($isWithKey)
632 {
633 global $DIC; /* @var \ILIAS\DI\Container $DIC */
634
635 return $isWithKey ? $DIC->language()->txt('yes') : '';
636 }
637
638 protected function getCategoryTranslation($category)
639 {
641 return $categories[$category];
642 }
643
644 protected function getKeywordsFormatted(array $keywords)
645 {
646 return implode('<br />', $keywords);
647 }
648
649 protected function getAvailabilityLabel($data)
650 {
651 global $DIC; /* @var \ILIAS\DI\Container $DIC */
652
653 switch ($data['availability']) {
655
656 return $DIC->language()->txt('lti_con_prov_availability_create');
657
659
660 return $DIC->language()->txt('lti_con_prov_availability_existing');
661
663
664 return $DIC->language()->txt('lti_con_prov_availability_non');
665 }
666 }
667
668 protected function getOwnProviderLabel($data)
669 {
670 global $DIC; /* @var \ILIAS\DI\Container $DIC */
671
672 if ($data['creator'] == $DIC->user()->getId()) {
673 return $DIC->language()->txt('yes');
674 }
675
676 return '';
677 }
678
679 protected function getProviderCreatorLabel($data)
680 {
681 global $DIC; /* @var \ILIAS\DI\Container $DIC */
682
683 if ($data['creator']) {
684 /* @var ilObjUser $user */
685 $user = ilObjectFactory::getInstanceByObjId($data['creator'], false);
686
687 if ($user) {
688 return $user->getFullname();
689 }
690
691 return $DIC->language()->txt('deleted_user');
692 }
693
694 return '';
695 }
696
697 protected function buildActionsListHtml($data)
698 {
699 global $DIC; /* @var \ILIAS\DI\Container $DIC */
700
701 $items = $this->getActionItems($data);
702
703 if (count($items)) {
704 return $DIC->ui()->renderer()->render(
705 $DIC->ui()->factory()->dropdown()->standard($items)->withLabel(
706 $DIC->language()->txt('actions')
707 )
708 );
709 }
710
711 return '';
712 }
713
714 protected function getActionItems($data)
715 {
716 global $DIC; /* @var \ILIAS\DI\Container $DIC */
717
718 $items = array();
719
720 if ($this->getEditProviderCmd()) {
721 $items[] = $DIC->ui()->factory()->button()->shy(
722 $DIC->language()->txt('lti_action_edit_provider'),
723 $this->buildProviderLink($data['id'], $this->getEditProviderCmd())
724 );
725 }
726
727 if ($this->getAcceptProviderAsGlobalCmd()) {
728 $items[] = $DIC->ui()->factory()->button()->shy(
729 $DIC->language()->txt('lti_action_accept_provider_as_global'),
730 $this->buildProviderLink($data['id'], $this->getAcceptProviderAsGlobalCmd())
731 );
732 }
733
735 $items[] = $DIC->ui()->factory()->button()->shy(
736 $DIC->language()->txt('lti_action_reset_provider_to_user_scope'),
737 $this->buildProviderLink($data['id'], $this->getResetProviderToUserScopeCmd())
738 );
739 }
740
741 if ($this->getSelectProviderCmd()) {
742 $items[] = $DIC->ui()->factory()->button()->shy(
743 $DIC->language()->txt('lti_select_provider'),
744 $this->buildProviderLink($data['id'], $this->getSelectProviderCmd())
745 );
746 }
747
748 if ($this->getDeleteProviderCmd() && !$data['usages_untrashed'] && !$data['usages_trashed']) {
749 $items[] = $DIC->ui()->factory()->button()->shy(
750 $DIC->language()->txt('lti_delete_provider'),
751 $this->buildProviderLink($data['id'], $this->getDeleteProviderCmd())
752 );
753 }
754
755 return $items;
756 }
757
758 protected function buildProviderLink(int $providerId, string $command)
759 {
760 global $DIC; /* @var \ILIAS\DI\Container $DIC */
761
762 $DIC->ctrl()->setParameter($this->parent_obj, 'provider_id', $providerId);
763 $link = $DIC->ctrl()->getLinkTarget($this->parent_obj, $command);
764 $DIC->ctrl()->setParameter($this->parent_obj, 'provider_id', 0);
765
766 return $link;
767 }
768
770 {
771 return (bool) $data['creator'] && (bool) $data['accepted_by'];
772 }
773
774 protected static function isTrashEnabled()
775 {
776 global $DIC; /* @var \ILIAS\DI\Container $DIC */
777
778 return (bool) $DIC->settings()->get('enable_trash', 0);
779 }
780}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
setDetailedUsagesEnabled(bool $detailedUsagesEnabled)
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
setDeleteProviderMultiCmd(string $deleteProviderMultiCmd)
setProviderCreatorColumnEnabled(bool $providerCreatorColumnEnabled)
setResetProviderToUserScopeMultiCmd(string $resetProviderToUserScopeMultiCmd)
determineSelectedColumns()
Determine selected columns.
setOwnProviderColumnEnabled(bool $ownProviderColumnEnabled)
fillRow($data)
Standard Version of Fill Row.
setAcceptProviderAsGlobalMultiCmd(string $acceptProviderAsGlobalMultiCmd)
setResetProviderToUserScopeCmd(string $resetProviderToUserScopeCmd)
setAcceptProviderAsGlobalCmd(string $acceptProviderAsGlobalCmd)
setAvailabilityColumnEnabled(bool $availabilityColumnEnabled)
buildProviderLink(int $providerId, string $command)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
This class represents a selection list property in a property form.
Class ilTable2GUI.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
isColumnSelected($a_col)
Is given column selected?
This class represents a text property in a property form.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc