ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
74 protected $step_vs;
82 protected $step_c;
90 protected $step_e;
98 protected $step_o;
106 protected $step_s;
111
112
117 public static function returnDbTableName()
118 {
119 return "il_dcl_tableview";
120 }
121
122
126 public function getId()
127 {
128 return $this->id;
129 }
130
131
135 public function setId($id)
136 {
137 $this->id = $id;
138 }
139
140
144 public function getTableId()
145 {
146 return $this->table_id;
147 }
148
149
153 public function setTableId($table_id)
154 {
155 $this->table_id = $table_id;
156 }
157
158
162 public function getTitle()
163 {
164 return $this->title;
165 }
166
167
171 public function setTitle($title)
172 {
173 $this->title = $title;
174 }
175
176
180 public function getOrder()
181 {
183 }
184
185
189 public function setOrder($order)
190 {
191 $this->tableview_order = $order;
192 }
193
194
198 public function getDescription()
199 {
200 return $this->description;
201 }
202
203
208 {
209 $this->description = $description;
210 }
211
212
216 public function getTableviewOrder()
217 {
219 }
220
221
226 {
227 $this->tableview_order = $tableview_order;
228 }
229
230
234 public function isStepVs()
235 {
236 return $this->step_vs;
237 }
238
239
243 public function setStepVs($step_vs)
244 {
245 $this->step_vs = $step_vs;
246 }
247
248
252 public function isStepC()
253 {
254 return $this->step_c;
255 }
256
257
261 public function setStepC($step_c)
262 {
263 $this->step_c = $step_c;
264 }
265
266
270 public function isStepE()
271 {
272 return $this->step_e;
273 }
274
275
279 public function setStepE($step_e)
280 {
281 $this->step_e = $step_e;
282 }
283
284
288 public function isStepO()
289 {
290 return $this->step_o;
291 }
292
293
297 public function setStepO($step_o)
298 {
299 $this->step_o = $step_o;
300 }
301
302
306 public function isStepS()
307 {
308 return $this->step_s;
309 }
310
311
315 public function setStepS($step_s)
316 {
317 $this->step_s = $step_s;
318 }
319
320
324 public function getRoles()
325 {
326 return (array) $this->roles;
327 }
328
329
333 public function setRoles(array $roles)
334 {
335 $this->roles = $roles;
336 }
337
338
344 public function sleep($field_name)
345 {
346 if ($field_name == 'roles') {
347 return json_encode($this->roles);
348 }
349
350 return null;
351 }
352
353
360 public function wakeUp($field_name, $field_value)
361 {
362 if ($field_name == 'roles') {
363 return json_decode($field_value);
364 }
365
366 return null;
367 }
368
369
373 public function delete()
374 {
375 //Delete settings
376 foreach ($this->getFieldSettings() as $setting) {
377 $setting->delete();
378 }
379 parent::delete();
380 }
381
382
386 public function getTable()
387 {
388 return ilDclCache::getTableCache($this->table_id);
389 }
390
391
399 {
401 array(
402 "tableview_id" => $this->id,
403 'in_filter' => 1,
404 'il_dcl_tfield_set.table_id' => $this->getTableId(),
405 )
406 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())
407 ->orderBy('il_dcl_tfield_set.field_order')
408 ->get();
409 }
410
411
417 public function getVisibleFields()
418 {
419 if (!$this->visible_fields_cache) {
421 where(
422 array(
423 "tableview_id" => $this->id,
424 'visible' => true,
425 'il_dcl_tfield_set.table_id' => $this->getTableId(),
426 )
427 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())->orderBy('il_dcl_tfield_set.field_order')->get();
428 $fields = array();
429 foreach ($visible as $field_rec) {
430 $fields[] = $field_rec->getFieldObject();
431 }
432 $this->visible_fields_cache = $fields;
433 }
434
436 }
437
442 public function getFieldSettings() : array
443 {
445 array(
446 'tableview_id' => $this->getId(),
447 'il_dcl_tfield_set.table_id' => $this->getTableId(),
448 )
449 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array('field_order'))->orderBy('field_order')->get();
450 }
451
456 public function getFieldSetting($field_id) : ilDclTableViewFieldSetting
457 {
459 'tableview_id' => $this->getId(),
460 'field' => $field_id
461 ])->first();
462 }
463
467 public function create($create_default_settings = true)
468 {
469 parent::create();
470 if ($create_default_settings) {
471 $this->createDefaultSettings();
472 }
473 }
474
475
479 public function createDefaultSettings()
480 {
481 $table = ilDclCache::getTableCache($this->table_id);
482
483 foreach ($table->getFieldIds() as $field_id) {
484 $this->createFieldSetting($field_id);
485 }
486
487 //ilDclTable->getFieldIds won't reuturn comments if they are disabled,
488 //still we have to create a fieldsetting for this field
489 if (!$table->getPublicCommentsEnabled()) {
490 $this->createFieldSetting('comments');
491 }
492 }
493
494
500 public function createFieldSetting($field_id)
501 {
503 array(
504 'tableview_id' => $this->id,
505 'field' => $field_id,
506 )
507 )->get()
508 ) {
509 $field_set = new ilDclTableViewFieldSetting();
510 $field_set->setTableviewId($this->id);
511 $field_set->setField($field_id);
512 $field_set->setVisible(!ilDclStandardField::_isStandardField($field_id));
513 $field_set->setFilterChangeable(true);
514 $field_set->setLockedCreate(false);
515 $field_set->setLockedEdit(false);
516 $field_set->setRequiredCreate(false);
517 $field_set->setRequiredEdit(false);
518 $field_set->setVisibleCreate(true);
519 $field_set->setVisibleEdit(true);
520 $field_set->create();
521 }
522 }
523
524
529 public function cloneStructure(ilDclTableView $orig, array $new_fields)
530 {
531 //clone structure
532 $this->setTitle($orig->getTitle());
533 $this->setOrder($orig->getOrder());
534 $this->setDescription($orig->getDescription());
535 $this->setRoles($orig->getRoles());
536 $this->setStepVs($orig->isStepVs());
537 $this->setStepC($orig->isStepC());
538 $this->setStepE($orig->isStepE());
539 $this->setStepO($orig->isStepO());
540 $this->setStepS($orig->isStepS());
541 $this->create(false); //create default setting, adjust them later
542
543 //clone default values
545
546
547 //clone fieldsettings
548 foreach ($orig->getFieldSettings() as $orig_fieldsetting) {
549 $new_fieldsetting = new ilDclTableViewFieldSetting();
550 $new_fieldsetting->setTableviewId($this->getId());
551 if ($new_fields[$orig_fieldsetting->getField()]) {
552 //normal fields
553 $new_fieldsetting->setField($new_fields[$orig_fieldsetting->getField()]->getId());
554 } else {
555 //standard fields
556 $new_fieldsetting->setField($orig_fieldsetting->getField());
557 }
558 $new_field_id = $new_fieldsetting->cloneStructure($orig_fieldsetting);
559
560 //clone default value
561 $datatype = $orig_fieldsetting->getFieldObject()->getDatatypeId();
562 $match = ilDclTableViewBaseDefaultValue::findSingle($datatype, $orig_fieldsetting->getId());
563
564 if (!is_null($match)) {
565 $new_default_value = $f->create($datatype);
566 $new_default_value->setTviewSetId($new_field_id);
567 $new_default_value->setValue($match->getValue());
568 $new_default_value->create();
569 }
570 }
571
572 //clone pageobject
574 $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId());
575 $orig_pageobject->copy($this->getId());
576 }
577
578 // mandatory for all cloning functions
580 }
581
582
588 public static function getAllForTableId($table_id)
589 {
590 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->get();
591 }
592
593
599 public static function getCountForTableId($table_id)
600 {
601 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->count();
602 }
603
604
611 public static function createOrGetStandardView($table_id, $create_default_settings = true)
612 {
613 if ($standardview = self::where(array('table_id' => $table_id))->orderBy('tableview_order')->first()) {
614 return $standardview;
615 }
616
617 global $DIC;
618 $rbacreview = $DIC['rbacreview'];
619 $roles = array();
620 foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
621 $roles[] = $role_array['obj_id'];
622 }
623
624 $view = new self();
625
626 if ($_GET['ref_id']) {
627 global $DIC;
628 $rbacreview = $DIC['rbacreview'];
629 $roles = array();
630 foreach ($rbacreview->getParentRoleIds($_GET['ref_id']) as $role_array) {
631 $roles[] = $role_array['obj_id'];
632 }
633 $view->setRoles(array_merge($roles, $rbacreview->getLocalRoles($_GET['ref_id'])));
634 }
635 $view->setTableId($table_id);
636 // bugfix mantis 0023307
637 $lng = $DIC['lng'];
638 $view->setTitle($lng->txt('dcl_title_standardview'));
639 $view->setTableviewOrder(10);
640 $view->setStepVs(true);
641 $view->setStepC(false);
642 $view->setStepE(false);
643 $view->setStepO(false);
644 $view->setStepS(false);
645 $view->create($create_default_settings);
646
647 return $view;
648 }
649
650
657 public function validateConfigCompletion()
658 {
659 return $this->step_vs && $this->step_c && $this->step_e && $this->step_o;
660 }
661}
$_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)
validateConfigCompletion()
Check if the configuration of the view is complete.
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 $DIC
Definition: goto.php:24
$lng