ILIAS  release_8 Revision v8.24
class.ilDclTableView.php
Go to the documentation of this file.
1<?php
2
20{
31 protected ?int $id;
39 protected int $table_id = 0;
47 protected string $title = "";
54 protected array $roles = array();
61 protected string $description = '';
68 protected int $tableview_order = 0;
75 protected bool $step_vs = false;
82 protected bool $step_c = false;
89 protected bool $step_e = false;
96 protected bool $step_o = false;
103 protected bool $step_s = false;
107 protected array $visible_fields_cache = [];
108
113 public static function returnDbTableName(): string
114 {
115 return "il_dcl_tableview";
116 }
117
118 public function getId(): ?int
119 {
120 return $this->id;
121 }
122
123 public function setId(int $id): void
124 {
125 $this->id = $id;
126 }
127
128 public function getTableId(): int
129 {
130 return $this->table_id;
131 }
132
133 public function setTableId(int $table_id): void
134 {
135 $this->table_id = $table_id;
136 }
137
138 public function getTitle(): string
139 {
140 return $this->title;
141 }
142
143 public function setTitle(string $title): void
144 {
145 $this->title = $title;
146 }
147
148 public function getOrder(): int
149 {
151 }
152
153 public function setOrder(int $order): void
154 {
155 $this->tableview_order = $order;
156 }
157
158 public function getDescription(): string
159 {
160 return $this->description;
161 }
162
163 public function setDescription(string $description): void
164 {
165 $this->description = $description;
166 }
167
168 public function getTableviewOrder(): int
169 {
171 }
172
173 public function setTableviewOrder(int $tableview_order): void
174 {
175 $this->tableview_order = $tableview_order;
176 }
177
178 public function isStepVs(): bool
179 {
180 return $this->step_vs;
181 }
182
183 public function setStepVs(bool $step_vs): void
184 {
185 $this->step_vs = $step_vs;
186 }
187
188 public function isStepC(): bool
189 {
190 return $this->step_c;
191 }
192
193 public function setStepC(bool $step_c): void
194 {
195 $this->step_c = $step_c;
196 }
197
198 public function isStepE(): bool
199 {
200 return $this->step_e;
201 }
202
203 public function setStepE(bool $step_e): void
204 {
205 $this->step_e = $step_e;
206 }
207
208 public function isStepO(): bool
209 {
210 return $this->step_o;
211 }
212
213 public function setStepO(bool $step_o): void
214 {
215 $this->step_o = $step_o;
216 }
217
218 public function isStepS(): bool
219 {
220 return $this->step_s;
221 }
222
223 public function setStepS(bool $step_s): void
224 {
225 $this->step_s = $step_s;
226 }
227
228 public function getRoles(): array
229 {
230 return $this->roles;
231 }
232
233 public function setRoles(array $roles): void
234 {
235 $this->roles = $roles;
236 }
237
241 public function sleep($field_name): ?string
242 {
243 if ($field_name == 'roles') {
244 return json_encode($this->roles);
245 }
246
247 return null;
248 }
249
254 public function wakeUp($field_name, $field_value): ?array
255 {
256 if ($field_name == 'roles') {
257 return json_decode($field_value);
258 }
259
260 return null;
261 }
262
263 public function delete(): void
264 {
265 //Delete settings
266 foreach ($this->getFieldSettings() as $setting) {
267 $setting->delete();
268 }
269 parent::delete();
270 }
271
272 public function getTable(): ilDclTable
273 {
274 return ilDclCache::getTableCache($this->table_id);
275 }
276
280 public static function findOrGetInstance($primary_key, array $add_constructor_args = array()): ActiveRecord
281 {
282 return parent::findOrGetInstance($primary_key, $add_constructor_args);
283 }
284
290 public function getFilterableFieldSettings(): array
291 {
293 array(
294 "tableview_id" => $this->id,
295 'in_filter' => 1,
296 'il_dcl_tfield_set.table_id' => $this->getTableId(),
297 )
298 )->innerjoin('il_dcl_tfield_set', 'field', 'field', array())
299 ->orderBy('il_dcl_tfield_set.field_order')
300 ->get();
301 }
302
307 public function getVisibleFields(): array
308 {
309 if (!$this->visible_fields_cache) {
311 array(
312 "tableview_id" => $this->id,
313 'visible' => true,
314 'il_dcl_tfield_set.table_id' => $this->getTableId(),
315 )
316 )->innerjoin(
317 'il_dcl_tfield_set',
318 'field',
319 'field',
320 array()
321 )->orderBy('il_dcl_tfield_set.field_order')->get();
322 $fields = array();
323 foreach ($visible as $field_rec) {
324 $fields[] = $field_rec->getFieldObject();
325 }
326 $this->visible_fields_cache = $fields;
327 }
328
330 }
331
336 public function getFieldSettings(): array
337 {
339 [
340 'tableview_id' => $this->getId(),
341 'il_dcl_tfield_set.table_id' => $this->getTableId(),
342 ]
343 )
344 ->innerjoin('il_dcl_tfield_set', 'field', 'field', ['field_order'])->orderBy('field_order')
345 ->get();
346
347 $result = [];
348 foreach ($settings as $setting) {
349 $datatype = $setting->getFieldObject()->getDatatypeId();
350 if ($datatype === null || in_array($datatype, array_keys(ilDclDatatype::getAllDatatype()))) {
351 $result[] = $setting;
352 }
353 }
354
355 return $result;
356 }
357
362 public function getFieldSetting($field_id): ActiveRecord
363 {
365 'tableview_id' => $this->getId(),
366 'field' => $field_id
367 ])->first();
368 }
369
370 public function create(bool $create_default_settings = true): void
371 {
372 parent::create();
373 if ($create_default_settings) {
374 $this->createDefaultSettings();
375 }
376 }
377
381 public function createDefaultSettings(): void
382 {
383 $table = ilDclCache::getTableCache($this->table_id);
384
385 foreach ($table->getFieldIds() as $field_id) {
386 $this->createFieldSetting($field_id);
387 }
388
389 //ilDclTable->getFieldIds won't reuturn comments if they are disabled,
390 //still we have to create a fieldsetting for this field
391 if (!$table->getPublicCommentsEnabled()) {
392 $this->createFieldSetting('comments');
393 }
394 }
395
400 public function createFieldSetting($field_id): void
401 {
403 array(
404 'tableview_id' => $this->id,
405 'field' => $field_id,
406 )
407 )->get()
408 ) {
409 $field_set = new ilDclTableViewFieldSetting();
410 $field_set->setTableviewId($this->id);
411 $field_set->setField($field_id);
412 $field_set->setVisible(!ilDclStandardField::_isStandardField($field_id));
413 $field_set->setFilterChangeable(true);
414 $field_set->setLockedCreate(false);
415 $field_set->setLockedEdit(false);
416 $field_set->setRequiredCreate(false);
417 $field_set->setRequiredEdit(false);
418 $field_set->setVisibleCreate(true);
419 $field_set->setVisibleEdit(true);
420 $field_set->create();
421 }
422 }
423
428 public function cloneStructure(ilDclTableView $orig, array $new_fields): void
429 {
430 global $DIC;
431 //clone structure
432 $this->setTitle($orig->getTitle() . ' ' . $DIC->language()->txt('copy_of_suffix'));
433 $this->setOrder($orig->getOrder());
434 $this->setDescription($orig->getDescription());
435 $this->setRoles($orig->getRoles());
436 $this->setStepVs($orig->isStepVs());
437 $this->setStepC($orig->isStepC());
438 $this->setStepE($orig->isStepE());
439 $this->setStepO($orig->isStepO());
440 $this->setStepS($orig->isStepS());
441 $this->create(false); //create default setting, adjust them later
442
443 //clone default values
445
446 //clone fieldsettings
447 foreach ($orig->getFieldSettings() as $orig_fieldsetting) {
448 $new_fieldsetting = new ilDclTableViewFieldSetting();
449 $new_fieldsetting->setTableviewId($this->getId());
450 if ($new_fields[$orig_fieldsetting->getField()] ?? null) {
451 //normal fields
452 $new_fieldsetting->setField($new_fields[$orig_fieldsetting->getField()]->getId());
453 } else {
454 //standard fields
455 $new_fieldsetting->setField($orig_fieldsetting->getField());
456 }
457 $new_field_id = $new_fieldsetting->cloneStructure($orig_fieldsetting);
458
459 //clone default value
460 $datatype = $orig_fieldsetting->getFieldObject()->getDatatypeId();
461 $match = ilDclTableViewBaseDefaultValue::findSingle($datatype, $orig_fieldsetting->getId());
462
463 if (!is_null($match)) {
464 $new_default_value = $f->create($datatype);
465 $new_default_value->setTviewSetId($new_field_id);
466 $new_default_value->setValue($match->getValue());
467 $new_default_value->create();
468 }
469 }
470
471 //clone pageobject
473 $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId());
474 $orig_pageobject->copy($this->getId());
475 }
476
477 // mandatory for all cloning functions
479 }
480
484 public static function getAllForTableId(int $table_id): array
485 {
486 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->get();
487 }
488
489 public static function getCountForTableId(int $table_id): int
490 {
491 return self::where(array('table_id' => $table_id))->orderBy('tableview_order')->count();
492 }
493
499 public static function createOrGetStandardView(int $table_id, bool $create_default_settings = true): ActiveRecord
500 {
501 if ($standardview = self::where(array('table_id' => $table_id))->orderBy('tableview_order')->first()) {
502 return $standardview;
503 }
504
505 global $DIC;
506 $rbacreview = $DIC['rbacreview'];
507 $http = $DIC->http();
508 $refinery = $DIC->refinery();
509
510 $roles = array();
511
512 $ref_id = $http->wrapper()->query()->retrieve('ref_id', $refinery->kindlyTo()->int());
513 foreach ($rbacreview->getParentRoleIds($ref_id) as $role_array) {
514 $roles[] = $role_array['obj_id'];
515 }
516
517 $view = new self();
518
519 $hasRefId = $http->wrapper()->query()->has('ref_id');
520
521 if ($hasRefId) {
522 global $DIC;
523 $rbacreview = $DIC['rbacreview'];
524
525 $ref_id = $http->wrapper()->query()->retrieve('ref_id', $refinery->kindlyTo()->int());
526
527 $roles = array();
528 foreach ($rbacreview->getParentRoleIds($ref_id) as $role_array) {
529 $roles[] = $role_array['obj_id'];
530 }
531 $view->setRoles(array_merge($roles, $rbacreview->getLocalRoles($ref_id)));
532 }
533 $view->setTableId($table_id);
534 // bugfix mantis 0023307
535 $lng = $DIC['lng'];
536 $view->setTitle($lng->txt('dcl_title_standardview'));
537 $view->setTableviewOrder(10);
538 $view->setStepVs(true);
539 $view->setStepC(false);
540 $view->setStepE(false);
541 $view->setStepO(false);
542 $view->setStepS(false);
543 $view->create($create_default_settings);
544
545 return $view;
546 }
547
552 public function validateConfigCompletion(): bool
553 {
554 return $this->step_vs && $this->step_c && $this->step_e && $this->step_o;
555 }
556}
Class ActiveRecord.
static orderBy($orderBy, string $orderDirection='ASC')
static where($where, $operator=null)
const TYPE_TABLEVIEW
static getTableCache(int $table_id=null)
static setCloneOf(int $old, int $new, string $type)
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isStandardField($field_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static findOrGetInstance($primary_key, array $add_constructor_args=array())
createDefaultSettings()
create default ilDclTableViewFieldSetting entries
wakeUp($field_name, $field_value)
getVisibleFields()
Returns all field-objects of this tableview which have set their visibility to true,...
setStepO(bool $step_o)
setTitle(string $title)
setTableId(int $table_id)
setStepVs(bool $step_vs)
setStepE(bool $step_e)
validateConfigCompletion()
Check if the configuration of the view is complete.
static getAllForTableId(int $table_id)
cloneStructure(ilDclTableView $orig, array $new_fields)
setStepC(bool $step_c)
setStepS(bool $step_s)
setDescription(string $description)
setTableviewOrder(int $tableview_order)
create(bool $create_default_settings=true)
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
static createOrGetStandardView(int $table_id, bool $create_default_settings=true)
static getCountForTableId(int $table_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Refinery Factory $refinery
$http
Definition: raiseError.php:7
$lng