ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DataRetrieval.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
32 {
33  protected const int MAX_PREVIEW_VALUES = 5;
34 
38 
42  protected array $vocabs;
43 
44  public function __construct(
45  VocabManager $vocab_manager,
46  Presentation $presentation,
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,
57  Range $range,
58  Order $order,
59  ?array $filter_data,
60  ?array $additional_parameters
61  ): \Generator {
62  $checked_icon = $this->ui_factory->symbol()->icon()->custom(
63  'assets/images/standard/icon_checked.svg',
64  $this->presentation->txt('yes'),
65  'small'
66  );
67  $unchecked_icon = $this->ui_factory->symbol()->icon()->custom(
68  'assets/images/standard/icon_unchecked.svg',
69  $this->presentation->txt('yes'),
70  'small'
71  );
72 
73  $infos = $this->vocab_manager->infos();
74  foreach ($this->getVocabs($range) as $vocab) {
75  $record = [];
76 
77  $record['element'] = $this->presentation->makeSlotPresentable($vocab->slot());
78  $record['type'] = $this->presentation->makeTypePresentable($vocab->type());
79  $record['source'] = $vocab->source();
80  $record['preview'] = implode(
81  ', ',
82  $this->presentation->makeValuesPresentable($vocab, self::MAX_PREVIEW_VALUES)
83  );
84  $record['active'] = $vocab->isActive() ? $checked_icon : $unchecked_icon;
85  if ($infos->isCustomInputApplicable($vocab)) {
86  $record['custom_input'] = $vocab->allowsCustomInputs() ? $checked_icon : $unchecked_icon;
87  }
88 
89  yield $row_builder->buildDataRow(
90  $vocab->id(),
91  $record
92  )->withDisabledAction(
93  'delete',
94  !$infos->canBeDeleted($vocab)
95  )->withDisabledAction(
96  'activate',
97  $vocab->isActive()
98  )->withDisabledAction(
99  'deactivate',
100  !$vocab->isActive() ||
101  !$infos->isDeactivatable($vocab)
102  )->withDisabledAction(
103  'allow_custom_input',
104  !$infos->isCustomInputApplicable($vocab) ||
105  $vocab->allowsCustomInputs()
106  )->withDisabledAction(
107  'disallow_custom_input',
108  !$infos->isCustomInputApplicable($vocab) ||
109  !$infos->canDisallowCustomInput($vocab) ||
110  !$vocab->allowsCustomInputs()
111  );
112  };
113  }
114 
115  public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
116  {
117  return count($this->getVocabs());
118  }
119 
120  protected function getVocabs(?Range $range = null): array
121  {
122  if (isset($this->vocabs)) {
123  $vocabs = $this->vocabs;
124  } else {
125  $vocabs = iterator_to_array($this->vocab_manager->getAllVocabularies(), false);
126  }
127 
128  if ($range) {
129  $vocabs = array_slice($vocabs, $range->getStart(), $range->getLength());
130  }
131 
132  return $this->vocabs = $vocabs;
133  }
134 }
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
buildDataRow(string $id, array $record)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$vocab
__construct(VocabManager $vocab_manager, Presentation $presentation, UIFactory $ui_factory)
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...
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28