ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityTableGUI.php
Go to the documentation of this file.
1<?php
2
23{
25 protected array $visibleOptionalColumns = [];
26 protected array $optionalColumns = [];
27 protected array $filter = [];
28 protected array $optional_filter = [];
29
30 public function __construct(
31 object $a_parent_obj,
32 string $command = '',
33 string $a_template_context = ''
34 ) {
35 parent::__construct($a_parent_obj, $command, $a_template_context);
36
37 $columns = $this->getColumnDefinition();
38 $this->optionalColumns = (array) $this->getSelectableColumns();
39 $this->visibleOptionalColumns = (array) $this->getSelectedColumns();
40
41 foreach ($columns as $index => $column) {
42 if ($this->isColumnVisible($index)) {
43 $this->addColumn(
44 $column['txt'],
45 isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
46 $column['width'] ?? '',
47 isset($column['is_checkbox']) && (bool) $column['is_checkbox']
48 );
49 }
50 }
51 }
52
54 {
55 $this->provider = $provider;
56 }
57
59 {
60 return $this->provider;
61 }
62
63 protected function onBeforeDataFetched(array &$params, array &$filter): void
64 {
65 }
66
70 protected function prepareRow(array &$row): void
71 {
72 }
73
74 protected function preProcessData(array &$data): void
75 {
76 }
77
81 protected function formatCellValue(string $column, array $row): string
82 {
83 return trim($row[$column]);
84 }
85
86 public function getSelectableColumns(): array
87 {
88 $optionalColumns = array_filter($this->getColumnDefinition(), function ($column) {
89 return isset($column['optional']) && $column['optional'];
90 });
91
92 $columns = [];
93 foreach ($optionalColumns as $index => $column) {
94 $columns[$column['field']] = $column;
95 }
96
97 return $columns;
98 }
99
100 protected function isColumnVisible(int $index): bool
101 {
102 $columnDefinition = $this->getColumnDefinition();
103 if (array_key_exists($index, $columnDefinition)) {
104 $column = $columnDefinition[$index];
105 if (isset($column['optional']) && !$column['optional']) {
106 return true;
107 }
108
109 if (
110 is_array($this->visibleOptionalColumns) &&
111 array_key_exists($column['field'], $this->visibleOptionalColumns)
112 ) {
113 return true;
114 }
115 }
116
117 return false;
118 }
119
120 final protected function fillRow(array $row): void
121 {
122 $this->prepareRow($row);
123
124 foreach ($this->getColumnDefinition() as $index => $column) {
125 if (!$this->isColumnVisible($index)) {
126 continue;
127 }
128
129 $this->tpl->setCurrentBlock('column');
130 $value = $this->formatCellValue($column['field'], $row);
131 if ((string) $value === '') {
132 $this->tpl->touchBlock('column');
133 } else {
134 $this->tpl->setVariable('COLUMN_VALUE', $value);
135 }
136
137 $this->tpl->parseCurrentBlock();
138 }
139 }
140
141 abstract protected function getColumnDefinition(): array;
142
143 public function populate(): void
144 {
145 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
147 } else {
148 if (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
149 $this->determineOffsetAndOrder(true);
150 }
151 }
152
153 $params = [];
154 if ($this->getExternalSegmentation()) {
155 $params['limit'] = $this->getLimit();
156 $params['offset'] = $this->getOffset();
157 }
158 if ($this->getExternalSorting()) {
159 $params['order_field'] = $this->getOrderField();
160 $params['order_direction'] = $this->getOrderDirection();
161 }
162
164 $filter = (array) $this->filter;
165
166 foreach ($this->optional_filter as $key => $value) {
167 if ($this->isFilterSelected($key)) {
168 $filter[$key] = $value;
169 }
170 }
171
172 $this->onBeforeDataFetched($params, $filter);
173 $data = $this->getProvider()->getList($params, $filter);
174
175 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
176 $this->resetOffset();
177 if ($this->getExternalSegmentation()) {
178 $params['limit'] = $this->getLimit();
179 $params['offset'] = $this->getOffset();
180 }
181 $data = $this->provider->getList($params, $filter);
182 }
183
184 $this->preProcessData($data);
185
186 $this->setData($data['items']);
187 if ($this->getExternalSegmentation()) {
188 $this->setMaxCount($data['cnt']);
189 }
190 }
191}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
formatCellValue(string $column, array $row)
Define a final formatting for a cell value.
prepareRow(array &$row)
This method can be used to add some field values dynamically or manipulate existing values of the tab...
fillRow(array $row)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $command='', string $a_template_context='')
getSelectableColumns()
Get selectable columns.
onBeforeDataFetched(array &$params, array &$filter)
ilAccessibilityTableDataProvider $provider
setProvider(ilAccessibilityTableDataProvider $provider)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isFilterSelected(string $a_col)
Is given filter selected?
determineOffsetAndOrder(bool $a_omit_offset=false)
resetOffset(bool $a_in_determination=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)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)