ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
DataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Component\Table\DataRetrieval as BaseDataRetrieval;
29use ILIAS\UI\Factory as UIFactory;
30
31class DataRetrieval implements BaseDataRetrieval
32{
33 protected const int MAX_PREVIEW_VALUES = 5;
34
35 protected VocabManager $vocab_manager;
37 protected UIFactory $ui_factory;
38
42 protected array $vocabs;
43
44 public function __construct(
45 VocabManager $vocab_manager,
47 UIFactory $ui_factory
48 ) {
49 $this->vocab_manager = $vocab_manager;
50 $this->presentation = $presentation;
51 $this->ui_factory = $ui_factory;
52 }
53
54 public function getRows(
55 DataRowBuilder $row_builder,
56 array $visible_column_ids,
58 Order $order,
59 mixed $additional_viewcontrol_data,
60 mixed $filter_data,
61 mixed $additional_parameters
62 ): \Generator {
63 $checked_icon = $this->ui_factory->symbol()->icon()->custom(
64 'assets/images/standard/icon_checked.svg',
65 $this->presentation->txt('yes'),
66 'small'
67 );
68 $unchecked_icon = $this->ui_factory->symbol()->icon()->custom(
69 'assets/images/standard/icon_unchecked.svg',
70 $this->presentation->txt('yes'),
71 'small'
72 );
73
74 $infos = $this->vocab_manager->infos();
75 foreach ($this->getVocabs($range) as $vocab) {
76 $record = [];
77
78 $record['element'] = $this->presentation->makeSlotPresentable($vocab->slot());
79 $record['type'] = $this->presentation->makeTypePresentable($vocab->type());
80 $record['source'] = $vocab->source();
81 $record['preview'] = implode(
82 ', ',
83 $this->presentation->makeValuesPresentable($vocab, self::MAX_PREVIEW_VALUES)
84 );
85 $record['active'] = $vocab->isActive() ? $checked_icon : $unchecked_icon;
86 if ($infos->isCustomInputApplicable($vocab)) {
87 $record['custom_input'] = $vocab->allowsCustomInputs() ? $checked_icon : $unchecked_icon;
88 }
89
90 yield $row_builder->buildDataRow(
91 $vocab->id(),
92 $record
93 )->withDisabledAction(
94 'delete',
95 !$infos->canBeDeleted($vocab)
96 )->withDisabledAction(
97 'activate',
98 $vocab->isActive()
99 )->withDisabledAction(
100 'deactivate',
101 !$vocab->isActive() ||
102 !$infos->isDeactivatable($vocab)
103 )->withDisabledAction(
104 'allow_custom_input',
105 !$infos->isCustomInputApplicable($vocab) ||
106 $vocab->allowsCustomInputs()
107 )->withDisabledAction(
108 'disallow_custom_input',
109 !$infos->isCustomInputApplicable($vocab) ||
110 !$infos->canDisallowCustomInput($vocab) ||
111 !$vocab->allowsCustomInputs()
112 );
113 };
114 }
115
116 public function getTotalRowCount(
117 mixed $additional_viewcontrol_data,
118 mixed $filter_data,
119 mixed $additional_parameters
120 ): ?int {
121 return count($this->getVocabs());
122 }
123
124 protected function getVocabs(?Range $range = null): array
125 {
126 if (isset($this->vocabs)) {
127 $vocabs = $this->vocabs;
128 } else {
129 $vocabs = iterator_to_array($this->vocab_manager->getAllVocabularies(), false);
130 }
131
132 if ($range) {
133 $vocabs = array_slice($vocabs, $range->getStart(), $range->getLength());
134 }
135
136 return $this->vocabs = $vocabs;
137 }
138}
$vocab
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...
__construct(VocabManager $vocab_manager, Presentation $presentation, UIFactory $ui_factory)
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)