ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
7 abstract class ilTermsOfServiceTableGUI extends \ilTable2GUI
8 {
10  protected $provider;
11 
13  protected $visibleOptionalColumns = [];
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 
31  $columns = $this->getColumnDefinition();
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)
68  {
69  }
70 
75  protected function prepareRow(array &$row)
76  {
77  }
78 
82  protected function preProcessData(array &$data)
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 = array();
107  foreach ($optionalColumns as $index => $column) {
108  $columns[$column['field']] = $column;
109  }
110 
111  return $columns;
112  }
113 
118  protected function isColumnVisible(int $index)
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()
171  {
172  if ($this->getExternalSegmentation() && $this->getExternalSorting()) {
173  $this->determineOffsetAndOrder();
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 
190  $this->determineSelectedFilters();
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 
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 }
getExternalSorting()
Get external sorting.
resetOffset($a_in_determination=false)
Reset offset.
onBeforeDataFetched(array &$params, array &$filter)
$index
Definition: metadata.php:60
getOrderDirection()
Get order direction.
Interface ilTermsOfServiceTableDataProvider.
Class ilTable2GUI.
getOffset()
Get offset.
getExternalSegmentation()
Get external segmentation.
getSelectedColumns()
Get selected columns.
$row
isFilterSelected($a_col)
Is given filter selected?
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
determineSelectedFilters()
Determine selected filters.
__construct($a_parent_obj, $command='', $a_template_context='')
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.
prepareRow(array &$row)
This method can be used to add some field values dynamically or manipulate existing values of the tab...
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
formatCellValue(string $column, array $row)
Define a final formatting for a cell value.
setProvider(\ilTermsOfServiceTableDataProvider $provider)
if(! $in) $columns
Definition: Utf8Test.php:45
$key
Definition: croninfo.php:18