ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclTableView.php
Go to the documentation of this file.
1<?php
2require_once('./Services/ActiveRecord/class.ActiveRecord.php');
3require_once('./Modules/DataCollection/classes/TableView/class.ilDclTableViewFieldSetting.php');
11
23 protected $id;
33 protected $table_id;
42 protected $title;
50 protected $roles = array();
58 protected $description;
71
72
77 static function returnDbTableName() {
78 return "il_dcl_tableview";
79 }
80
81
85 public function getId() {
86 return $this->id;
87 }
88
89
93 public function setId($id) {
94 $this->id = $id;
95 }
96
97
101 public function getTableId() {
102 return $this->table_id;
103 }
104
105
109 public function setTableId($table_id) {
110 $this->table_id = $table_id;
111 }
112
113
117 public function getTitle() {
118 return $this->title;
119 }
120
121
125 public function setTitle($title) {
126 $this->title = $title;
127 }
128
129
133 public function getOrder() {
135 }
136
137
141 public function setOrder($order) {
142 $this->tableview_order = $order;
143 }
144
145
149 public function getDescription() {
150 return $this->description;
151 }
152
153
157 public function setDescription($description) {
158 $this->description = $description;
159 }
160
161
165 public function getTableviewOrder() {
167 }
168
169
174 $this->tableview_order = $tableview_order;
175 }
176
177
181 public function getRoles() {
182 return (array)$this->roles;
183 }
184
185
189 public function setRoles(array $roles) {
190 $this->roles = $roles;
191 }
192
193
199 public function sleep($field_name) {
200 if ($field_name == 'roles') {
201 return json_encode($this->roles);
202 }
203
204 return null;
205 }
206
207
214 public function wakeUp($field_name, $field_value) {
215 if ($field_name == 'roles') {
216 return json_decode($field_value);
217 }
218
219 return null;
220 }
221
222
226 public function delete() {
227 //Delete settings
228 foreach ($this->getFieldSettings() as $setting) {
229 $setting->delete();
230 }
231 parent::delete();
232 }
233
234
238 public function getTable() {
239 return ilDclCache::getTableCache($this->table_id);
240 }
241
242
249 public function getFilterableFieldSettings() {
251 array(
252 "tableview_id" => $this->id,
253 'in_filter' => 1,
254 'il_dcl_tfield_set.table_id' => $this->getTableId(),
255 )
256 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())
257 ->orderBy('il_dcl_tfield_set.field_order')
258 ->get();
259 }
260
261
267 public function getVisibleFields() {
268 if (!$this->visible_fields_cache) {
270 where(
271 array(
272 "tableview_id" => $this->id,
273 'visible' => true,
274 'il_dcl_tfield_set.table_id' => $this->getTableId(),
275 )
276 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())->orderBy('il_dcl_tfield_set.field_order')->get();
277 $fields = array();
278 foreach ($visible as $field_rec) {
279 $fields[] = $field_rec->getFieldObject();
280 }
281 $this->visible_fields_cache = $fields;
282 }
283
285 }
286
287
288 public function getFieldSettings() {
290 array(
291 'tableview_id' => $this->getId(),
292 'il_dcl_tfield_set.table_id' => $this->getTableId(),
293 )
294 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array('field_order'))->orderBy('field_order')->get();
295 }
296
297
301 public function create($create_default_settings = true) {
302 parent::create();
303 if ($create_default_settings) {
304 $this->createDefaultSettings();
305 }
306 }
307
308
312 public function createDefaultSettings() {
313 $table = ilDclCache::getTableCache($this->table_id);
314
315 foreach ($table->getFieldIds() as $field_id) {
316 $this->createFieldSetting($field_id);
317 }
318
319 //ilDclTable->getFieldIds won't reuturn comments if they are disabled,
320 //still we have to create a fieldsetting for this field
321 if (!$table->getPublicCommentsEnabled()) {
322 $this->createFieldSetting('comments');
323 }
324 }
325
326
332 public function createFieldSetting($field_id) {
334 array(
335 'tableview_id' => $this->id,
336 'field' => $field_id,
337 )
338 )->get()
339 ) {
340 $field_set = new ilDclTableViewFieldSetting();
341 $field_set->setTableviewId($this->id);
342 $field_set->setField($field_id);
343 $field_set->setVisible(!ilDclStandardField::_isStandardField($field_id));
344 $field_set->setFilterChangeable(true);
345 $field_set->create();
346 }
347 }
348
349
354 public function cloneStructure(ilDclTableView $orig, array $new_fields) {
355 //clone structure
356 $this->setTitle($orig->getTitle());
357 $this->setOrder($orig->getOrder());
358 $this->setDescription($orig->getDescription());
359 $this->setRoles($orig->getRoles());
360 $this->create(false); //create default setting, adjust them later
361
362 //clone fieldsettings
363 foreach ($orig->getFieldSettings() as $orig_fieldsetting) {
364 $new_fieldsetting = new ilDclTableViewFieldSetting();
365 $new_fieldsetting->setTableviewId($this->getId());
366 if ($new_fields[$orig_fieldsetting->getField()]) {
367 //normal fields
368 $new_fieldsetting->setField($new_fields[$orig_fieldsetting->getField()]->getId());
369 } else {
370 //standard fields
371 $new_fieldsetting->setField($orig_fieldsetting->getField());
372 }
373 $new_fieldsetting->cloneStructure($orig_fieldsetting);
374 }
375
376 //clone pageobject
378 $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId());
379 $orig_pageobject->copy($this->getId());
380 }
381
382 // mandatory for all cloning functions
384 }
385
386
392 public static function getAllForTableId($table_id) {
393 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->get();
394 }
395
396
402 public static function getCountForTableId($table_id) {
403 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->count();
404 }
405
406
413 public static function createOrGetStandardView($table_id, $create_default_settings = true) {
414 if ($standardview = self::where(array('table_id' => $table_id))->orderBy('tableview_order')->first()) {
415 return $standardview;
416 }
417
418 global $DIC;
419 $rbacreview = $DIC['rbacreview'];
420 $roles = array();
421 foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
422 $roles[] = $role_array['obj_id'];
423 }
424
425 $view = new self();
426
427 if ($_GET['ref_id']) {
428 global $DIC;
429 $rbacreview = $DIC['rbacreview'];
430 $roles = array();
431 foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
432 $roles[] = $role_array['obj_id'];
433 }
434 $view->setRoles(array_merge($roles, $rbacreview->getLocalRoles($_GET['ref_id'])));
435 }
436 $view->setTableId($table_id);
437 // bugfix mantis 0023307
438 $lng = $DIC['lng'];
439 $view->setTitle($lng->txt('dcl_title_standardview'));
440 $view->setTableviewOrder(10);
441 $view->create($create_default_settings);
442
443 return $view;
444 }
445}
$_GET["client_id"]
Class ActiveRecord.
static where($where, $operator=null)
static orderBy($orderBy, $orderDirection='ASC')
An exception for terminatinating execution or to throw for unit testing.
const TYPE_TABLEVIEW
static getTableCache($table_id=0)
static setCloneOf($old, $new, $type)
Class ilDclDetailedViewDefinition.
static _isStandardField($field_id)
Class ilDclTableViewFieldSetting.
Class ilDclTableView.
createDefaultSettings()
create default ilDclTableViewFieldSetting entries
wakeUp($field_name, $field_value)
create($create_default_settings=true)
getVisibleFields()
Returns all field-objects of this tableview which have set their visibility to true,...
static getCountForTableId($table_id)
cloneStructure(ilDclTableView $orig, array $new_fields)
static createOrGetStandardView($table_id, $create_default_settings=true)
static getAllForTableId($table_id)
setTableviewOrder($tableview_order)
setDescription($description)
setRoles(array $roles)
getFilterableFieldSettings()
getFilterableFields Returns all fieldsetting-objects of this tableview which have set their filterabl...
createFieldSetting($field_id)
create ilDclTableViewFieldSetting for this tableview and the given field id
global $lng
Definition: privfeed.php:17
global $DIC