ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDclTableView.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
23  protected $id;
33  protected $table_id;
42  protected $title;
50  protected $roles = array();
58  protected $description;
66  protected $tableview_order;
71 
72 
77  public static function returnDbTableName()
78  {
79  return "il_dcl_tableview";
80  }
81 
82 
86  public function getId()
87  {
88  return $this->id;
89  }
90 
91 
95  public function setId($id)
96  {
97  $this->id = $id;
98  }
99 
100 
104  public function getTableId()
105  {
106  return $this->table_id;
107  }
108 
109 
113  public function setTableId($table_id)
114  {
115  $this->table_id = $table_id;
116  }
117 
118 
122  public function getTitle()
123  {
124  return $this->title;
125  }
126 
127 
131  public function setTitle($title)
132  {
133  $this->title = $title;
134  }
135 
136 
140  public function getOrder()
141  {
142  return $this->tableview_order;
143  }
144 
145 
149  public function setOrder($order)
150  {
151  $this->tableview_order = $order;
152  }
153 
154 
158  public function getDescription()
159  {
160  return $this->description;
161  }
162 
163 
167  public function setDescription($description)
168  {
169  $this->description = $description;
170  }
171 
172 
176  public function getTableviewOrder()
177  {
178  return $this->tableview_order;
179  }
180 
181 
186  {
187  $this->tableview_order = $tableview_order;
188  }
189 
190 
194  public function getRoles()
195  {
196  return (array) $this->roles;
197  }
198 
199 
203  public function setRoles(array $roles)
204  {
205  $this->roles = $roles;
206  }
207 
208 
214  public function sleep($field_name)
215  {
216  if ($field_name == 'roles') {
217  return json_encode($this->roles);
218  }
219 
220  return null;
221  }
222 
223 
230  public function wakeUp($field_name, $field_value)
231  {
232  if ($field_name == 'roles') {
233  return json_decode($field_value);
234  }
235 
236  return null;
237  }
238 
239 
243  public function delete()
244  {
245  //Delete settings
246  foreach ($this->getFieldSettings() as $setting) {
247  $setting->delete();
248  }
249  parent::delete();
250  }
251 
252 
256  public function getTable()
257  {
258  return ilDclCache::getTableCache($this->table_id);
259  }
260 
261 
268  public function getFilterableFieldSettings()
269  {
271  array(
272  "tableview_id" => $this->id,
273  'in_filter' => 1,
274  'il_dcl_tfield_set.table_id' => $this->getTableId(),
275  )
276  )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())
277  ->orderBy('il_dcl_tfield_set.field_order')
278  ->get();
279  }
280 
281 
287  public function getVisibleFields()
288  {
289  if (!$this->visible_fields_cache) {
291  where(
292  array(
293  "tableview_id" => $this->id,
294  'visible' => true,
295  'il_dcl_tfield_set.table_id' => $this->getTableId(),
296  )
297  )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())->orderBy('il_dcl_tfield_set.field_order')->get();
298  $fields = array();
299  foreach ($visible as $field_rec) {
300  $fields[] = $field_rec->getFieldObject();
301  }
302  $this->visible_fields_cache = $fields;
303  }
304 
306  }
307 
308 
309  public function getFieldSettings()
310  {
312  array(
313  'tableview_id' => $this->getId(),
314  'il_dcl_tfield_set.table_id' => $this->getTableId(),
315  )
316  )->innerjoin('il_dcl_tfield_set', 'field', 'field', array('field_order'))->orderBy('field_order')->get();
317  }
318 
319 
323  public function create($create_default_settings = true)
324  {
325  parent::create();
326  if ($create_default_settings) {
327  $this->createDefaultSettings();
328  }
329  }
330 
331 
335  public function createDefaultSettings()
336  {
337  $table = ilDclCache::getTableCache($this->table_id);
338 
339  foreach ($table->getFieldIds() as $field_id) {
340  $this->createFieldSetting($field_id);
341  }
342 
343  //ilDclTable->getFieldIds won't reuturn comments if they are disabled,
344  //still we have to create a fieldsetting for this field
345  if (!$table->getPublicCommentsEnabled()) {
346  $this->createFieldSetting('comments');
347  }
348  }
349 
350 
356  public function createFieldSetting($field_id)
357  {
359  array(
360  'tableview_id' => $this->id,
361  'field' => $field_id,
362  )
363  )->get()
364  ) {
365  $field_set = new ilDclTableViewFieldSetting();
366  $field_set->setTableviewId($this->id);
367  $field_set->setField($field_id);
368  $field_set->setVisible(!ilDclStandardField::_isStandardField($field_id));
369  $field_set->setFilterChangeable(true);
370  $field_set->create();
371  }
372  }
373 
374 
379  public function cloneStructure(ilDclTableView $orig, array $new_fields)
380  {
381  //clone structure
382  $this->setTitle($orig->getTitle());
383  $this->setOrder($orig->getOrder());
384  $this->setDescription($orig->getDescription());
385  $this->setRoles($orig->getRoles());
386  $this->create(false); //create default setting, adjust them later
387 
388  //clone fieldsettings
389  foreach ($orig->getFieldSettings() as $orig_fieldsetting) {
390  $new_fieldsetting = new ilDclTableViewFieldSetting();
391  $new_fieldsetting->setTableviewId($this->getId());
392  if ($new_fields[$orig_fieldsetting->getField()]) {
393  //normal fields
394  $new_fieldsetting->setField($new_fields[$orig_fieldsetting->getField()]->getId());
395  } else {
396  //standard fields
397  $new_fieldsetting->setField($orig_fieldsetting->getField());
398  }
399  $new_fieldsetting->cloneStructure($orig_fieldsetting);
400  }
401 
402  //clone pageobject
404  $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId());
405  $orig_pageobject->copy($this->getId());
406  }
407 
408  // mandatory for all cloning functions
410  }
411 
412 
418  public static function getAllForTableId($table_id)
419  {
420  return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->get();
421  }
422 
423 
429  public static function getCountForTableId($table_id)
430  {
431  return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->count();
432  }
433 
434 
441  public static function createOrGetStandardView($table_id, $create_default_settings = true)
442  {
443  if ($standardview = self::where(array('table_id' => $table_id))->orderBy('tableview_order')->first()) {
444  return $standardview;
445  }
446 
447  global $DIC;
448  $rbacreview = $DIC['rbacreview'];
449  $roles = array();
450  foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
451  $roles[] = $role_array['obj_id'];
452  }
453 
454  $view = new self();
455 
456  if ($_GET['ref_id']) {
457  global $DIC;
458  $rbacreview = $DIC['rbacreview'];
459  $roles = array();
460  foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
461  $roles[] = $role_array['obj_id'];
462  }
463  $view->setRoles(array_merge($roles, $rbacreview->getLocalRoles($_GET['ref_id'])));
464  }
465  $view->setTableId($table_id);
466  // bugfix mantis 0023307
467  $lng = $DIC['lng'];
468  $view->setTitle($lng->txt('dcl_title_standardview'));
469  $view->setTableviewOrder(10);
470  $view->create($create_default_settings);
471 
472  return $view;
473  }
474 }
static setCloneOf($old, $new, $type)
cloneStructure(ilDclTableView $orig, array $new_fields)
createFieldSetting($field_id)
create ilDclTableViewFieldSetting for this tableview and the given field id
wakeUp($field_name, $field_value)
Class ActiveRecord.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
getFilterableFieldSettings()
getFilterableFields Returns all fieldsetting-objects of this tableview which have set their filterabl...
static getAllForTableId($table_id)
const TYPE_TABLEVIEW
static getCountForTableId($table_id)
static getTableCache($table_id=0)
static where($where, $operator=null)
Class ilDclTableViewFieldSetting.
setTableviewOrder($tableview_order)
$lng
create($create_default_settings=true)
createDefaultSettings()
create default ilDclTableViewFieldSetting entries
Class ilDclTableView.
static _isStandardField($field_id)
static createOrGetStandardView($table_id, $create_default_settings=true)
setRoles(array $roles)
setDescription($description)
getVisibleFields()
Returns all field-objects of this tableview which have set their visibility to true, including standard fields.
if(empty($password)) $table
Definition: pwgen.php:24
static orderBy($orderBy, $orderDirection='ASC')
copy($a_id, $a_parent_type="", $a_parent_id=0, $a_clone_mobs=false)
Copy page.
Class ilDclDetailedViewDefinition.