ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTermsOfServiceTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 
11 abstract class ilTermsOfServiceTableGUI extends ilTable2GUI
12 {
16  protected $ctrl;
17 
21  protected $visibleOptionalColumns = array();
22 
26  protected $provider;
27 
31  protected $optionalColumns = array();
32 
36  protected $filter = array();
37 
41  protected $optional_filter = array();
42 
48  {
49  $this->provider = $provider;
50  }
51 
56  public function getProvider()
57  {
58  return $this->provider;
59  }
60 
65  protected function isColumnVisible($column)
66  {
67  if(array_key_exists($column, $this->optionalColumns) && !isset($this->visibleOptionalColumns[$column]))
68  {
69  return false;
70  }
71 
72  return true;
73  }
74 
81  protected function prepareData(array &$data)
82  {
83  }
84 
90  protected function prepareRow(array &$row)
91  {
92  }
93 
100  protected function formatCellValue($column, array $row)
101  {
102  return $row[$column];
103  }
104 
108  final protected function fillRow(array $row)
109  {
110  $this->prepareRow($row);
111 
112  foreach($this->getStaticData() as $column)
113  {
114  $value = $this->formatCellValue($column, $row);
115  $this->tpl->setVariable('VAL_' . strtoupper($column), $value);
116  }
117 
118  foreach($this->optionalColumns as $index => $definition)
119  {
120  if(!$this->isColumnVisible($index))
121  {
122  continue;
123  }
124 
125  $this->tpl->setCurrentBlock('optional_column');
126  $value = $this->formatCellValue($index, $row);
127  if((string)$value === '')
128  {
129  $this->tpl->touchBlock('optional_column');
130  }
131  else
132  {
133  $this->tpl->setVariable('OPTIONAL_COLUMN_VAL', $value);
134  }
135 
136  $this->tpl->parseCurrentBlock();
137  }
138  }
139 
149  abstract protected function getStaticData();
150 
154  public function populate()
155  {
156  if(!$this->getExternalSegmentation() && $this->getExternalSorting())
157  {
158  $this->determineOffsetAndOrder(true);
159  }
160  else if($this->getExternalSegmentation() || $this->getExternalSorting())
161  {
162  $this->determineOffsetAndOrder();
163  }
164 
165  $params = array();
166  if($this->getExternalSegmentation())
167  {
168  $params['limit'] = $this->getLimit();
169  $params['offset'] = $this->getOffset();
170  }
171  if($this->getExternalSorting())
172  {
173  $params['order_field'] = $this->getOrderField();
174  $params['order_direction'] = $this->getOrderDirection();
175  }
176 
177  $this->determineSelectedFilters();
179 
180  foreach($this->optional_filter as $key => $value)
181  {
182  if($this->isFilterSelected($key))
183  {
184  $filter[$key] = $value;
185  }
186  }
187 
188  $data = $this->getProvider()->getList($params, $filter);
189 
190  if(!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation())
191  {
192  $this->resetOffset();
193  $params['limit'] = $this->getLimit();
194  $params['offset'] = $this->getOffset();
195  $data = $this->getProvider()->getList($params, $filter);
196  }
197 
198  $this->prepareData($data);
199 
200  $this->setData($data['items']);
201  if($this->getExternalSegmentation())
202  {
203  $this->setMaxCount($data['cnt']);
204  }
205  }
206 }