ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceTableGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 protected $provider;
11
14
16 protected $optionalColumns = [];
17
19 protected $filter = [];
20
22 protected $optional_filter = [];
23
27 public function __construct($a_parent_obj, $command = '', $a_template_context = '')
28 {
29 parent::__construct($a_parent_obj, $command, $a_template_context);
30
32 $this->optionalColumns = (array) $this->getSelectableColumns();
33 $this->visibleOptionalColumns = (array) $this->getSelectedColumns();
34
35 foreach ($columns as $index => $column) {
36 if ($this->isColumnVisible($index)) {
37 $this->addColumn(
38 $column['txt'],
39 isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
40 isset($column['width']) ? $column['width'] : '',
41 isset($column['is_checkbox']) ? (bool) $column['is_checkbox'] : false
42 );
43 }
44 }
45 }
46
51 {
52 $this->provider = $provider;
53 }
54
59 {
60 return $this->provider;
61 }
62
67 protected function onBeforeDataFetched(array &$params, array &$filter) : void
68 {
69 }
70
75 protected function prepareRow(array &$row) : void
76 {
77 }
78
82 protected function preProcessData(array &$data) : void
83 {
84 }
85
92 protected function formatCellValue(string $column, array $row) : string
93 {
94 return trim($row[$column]);
95 }
96
100 public function getSelectableColumns()
101 {
102 $optionalColumns = array_filter($this->getColumnDefinition(), function ($column) {
103 return isset($column['optional']) && $column['optional'];
104 });
105
106 $columns = [];
107 foreach ($optionalColumns as $index => $column) {
108 $columns[$column['field']] = $column;
109 }
110
111 return $columns;
112 }
113
118 protected function isColumnVisible(int $index) : bool
119 {
120 $columnDefinition = $this->getColumnDefinition();
121 if (array_key_exists($index, $columnDefinition)) {
122 $column = $columnDefinition[$index];
123 if (isset($column['optional']) && !$column['optional']) {
124 return true;
125 }
126
127 if (
128 is_array($this->visibleOptionalColumns) &&
129 array_key_exists($column['field'], $this->visibleOptionalColumns)
130 ) {
131 return true;
132 }
133 }
134
135 return false;
136 }
137
141 final protected function fillRow($row)
142 {
143 $this->prepareRow($row);
144
145 foreach ($this->getColumnDefinition() as $index => $column) {
146 if (!$this->isColumnVisible($index)) {
147 continue;
148 }
149
150 $this->tpl->setCurrentBlock('column');
151 $value = $this->formatCellValue($column['field'], $row);
152 if ((string) $value === '') {
153 $this->tpl->touchBlock('column');
154 } else {
155 $this->tpl->setVariable('COLUMN_VALUE', $value);
156 }
157
158 $this->tpl->parseCurrentBlock();
159 }
160 }
161
165 abstract protected function getColumnDefinition() : array;
166
170 public function populate() : void
171 {
172 if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
174 } else {
175 if (!$this->getExternalSegmentation() && $this->getExternalSorting()) {
176 $this->determineOffsetAndOrder(true);
177 }
178 }
179
180 $params = [];
181 if ($this->getExternalSegmentation()) {
182 $params['limit'] = $this->getLimit();
183 $params['offset'] = $this->getOffset();
184 }
185 if ($this->getExternalSorting()) {
186 $params['order_field'] = $this->getOrderField();
187 $params['order_direction'] = $this->getOrderDirection();
188 }
189
191 $filter = (array) $this->filter;
192
193 foreach ($this->optional_filter as $key => $value) {
194 if ($this->isFilterSelected($key)) {
195 $filter[$key] = $value;
196 }
197 }
198
199 $this->onBeforeDataFetched($params, $filter);
200 $data = $this->getProvider()->getList($params, $filter);
201
202 if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) {
203 $this->resetOffset();
204 if ($this->getExternalSegmentation()) {
205 $params['limit'] = $this->getLimit();
206 $params['offset'] = $this->getOffset();
207 }
208 $data = $this->provider->getList($params, $filter);
209 }
210
211 $this->preProcessData($data);
212
213 $this->setData($data['items']);
214 if ($this->getExternalSegmentation()) {
215 $this->setMaxCount($data['cnt']);
216 }
217 }
218}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setData($a_data)
set table data @access public
getExternalSorting()
Get external sorting.
getLimit()
Get limit.
resetOffset($a_in_determination=false)
Reset offset.
getExternalSegmentation()
Get external segmentation.
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.
getOffset()
Get offset.
isFilterSelected($a_col)
Is given filter selected?
determineSelectedFilters()
Determine selected filters.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
formatCellValue(string $column, array $row)
Define a final formatting for a cell value.
__construct($a_parent_obj, $command='', $a_template_context='')
ilTable2GUI constructor.
onBeforeDataFetched(array &$params, array &$filter)
prepareRow(array &$row)
This method can be used to add some field values dynamically or manipulate existing values of the tab...
setProvider(ilTermsOfServiceTableDataProvider $provider)
filter()
Definition: filter.php:2
Interface ilTermsOfServiceTableDataProvider.
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc