ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilDclTableView.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
33 protected ?int $id;
41 protected int $table_id = 0;
49 protected string $title = "";
56 protected array $roles = [];
63 protected bool $role_limitation = false;
70 protected string $description = '';
74 protected array $visible_fields_cache = [];
75
80 public static function returnDbTableName(): string
81 {
82 return "il_dcl_tableview";
83 }
84
85 public function getId(): ?int
86 {
87 return $this->id;
88 }
89
90 public function setId(int $id): void
91 {
92 $this->id = $id;
93 }
94
95 public function getTableId(): int
96 {
97 return $this->table_id;
98 }
99
100 public function setTableId(int $table_id): void
101 {
102 $this->table_id = $table_id;
103 }
104
105 public function getTitle(): string
106 {
107 return $this->title;
108 }
109
110 public function setTitle(string $title): void
111 {
112 $this->title = $title;
113 }
114
115 public function getDescription(): string
116 {
117 return $this->description;
118 }
119
120 public function setDescription(string $description): void
121 {
122 $this->description = $description;
123 }
124
125 public function getRoles(): array
126 {
127 return $this->roles;
128 }
129
130 public function setRoles(array $roles): void
131 {
132 $this->roles = $roles;
133 }
134
135 public function getRoleLimitation(): bool
136 {
138 }
139
140 public function setRoleLimitation(bool $role_limitation): void
141 {
142 $this->role_limitation = $role_limitation;
143 }
144
148 public function sleep($field_name): ?string
149 {
150 if ($field_name == 'roles') {
151 return json_encode($this->roles);
152 }
153
154 return null;
155 }
156
161 public function wakeUp($field_name, $field_value): ?array
162 {
163 if ($field_name == 'roles') {
164 return json_decode($field_value);
165 }
166
167 return null;
168 }
169
170 public function delete(): void
171 {
172 //Delete settings
173 foreach ($this->getFieldSettings() as $setting) {
174 $setting->delete();
175 }
176 parent::delete();
177 }
178
179 public function getTable(): ilDclTable
180 {
181 return ilDclCache::getTableCache($this->table_id);
182 }
183
187 public static function findOrGetInstance($primary_key, array $add_constructor_args = []): ActiveRecord
188 {
189 return parent::findOrGetInstance($primary_key, $add_constructor_args);
190 }
191
197 public function getFilterableFieldSettings(): array
198 {
200 [
201 "tableview_id" => $this->id,
202 'in_filter' => 1,
203 'il_dcl_tfield_set.table_id' => $this->getTableId(),
204 ]
205 )->innerjoin('il_dcl_tfield_set', 'field', 'field', [])
206 ->orderBy('il_dcl_tfield_set.field_order')
207 ->get();
208 }
209
214 public function getVisibleFields(): array
215 {
216 if (!$this->visible_fields_cache) {
218 [
219 "tableview_id" => $this->id,
220 'visible' => true,
221 'il_dcl_tfield_set.table_id' => $this->getTableId(),
222 ]
223 )->innerjoin(
224 'il_dcl_tfield_set',
225 'field',
226 'field',
227 []
228 )->orderBy('il_dcl_tfield_set.field_order')->get();
229 $fields = [];
230 foreach ($visible as $field_rec) {
231 $fields[] = $field_rec->getFieldObject();
232 }
233 $this->visible_fields_cache = $fields;
234 }
235
237 }
238
243 public function getFieldSettings(): array
244 {
246 [
247 'tableview_id' => $this->getId(),
248 'il_dcl_tfield_set.table_id' => $this->getTableId(),
249 ]
250 )->innerjoin('il_dcl_tfield_set', 'field', 'field', [])->orderBy('il_dcl_tfield_set.field_order')->get();
251
252 $result = [];
253 foreach ($settings as $setting) {
254 $datatype = $setting->getFieldObject()->getDatatypeId();
255 if ($datatype === null || in_array($datatype, array_keys(ilDclDatatype::getAllDatatype()))) {
256 $result[] = $setting;
257 }
258 }
259
260 return $result;
261 }
262
267 public function getFieldSetting($field_id): ActiveRecord
268 {
270 'tableview_id' => $this->getId(),
271 'field' => $field_id
272 ])->first();
273 }
274
275 public function create(bool $create_default_settings = true): void
276 {
277 parent::create();
278 if ($create_default_settings) {
279 $this->createDefaultSettings();
280 }
281 }
282
286 public function createDefaultSettings(): void
287 {
288 $table = ilDclCache::getTableCache($this->table_id);
289
290 foreach ($table->getFieldIds() as $field_id) {
291 $this->createFieldSetting($field_id);
292 }
293
294 //ilDclTable->getFieldIds won't reuturn comments if they are disabled,
295 //still we have to create a fieldsetting for this field
296 if (!$table->getPublicCommentsEnabled()) {
297 $this->createFieldSetting('comments');
298 }
299 }
300
305 public function createFieldSetting($field_id): void
306 {
308 [
309 'tableview_id' => $this->id,
310 'field' => $field_id,
311 ]
312 )->get()
313 ) {
314 $field_set = new ilDclTableViewFieldSetting();
315 $field_set->setTableviewId($this->id);
316 $field_set->setField($field_id);
317 $field_set->setVisible(!ilDclStandardField::_isStandardField($field_id));
318 $field_set->setFilterChangeable(true);
319 $field_set->setLockedCreate(false);
320 $field_set->setLockedEdit(false);
321 $field_set->setRequiredCreate(false);
322 $field_set->setRequiredEdit(false);
323 $field_set->setVisibleCreate(true);
324 $field_set->setVisibleEdit(true);
325 $field_set->create();
326 }
327 }
328
333 public function cloneStructure(ilDclTableView $orig, array $new_fields): void
334 {
335 global $DIC;
336 //clone structure
337 $this->setTitle($orig->getTitle() . ' ' . $DIC->language()->txt('copy_of_suffix'));
338 $this->setDescription($orig->getDescription());
339 $this->setRoles($orig->getRoles());
340 $this->setRoleLimitation($orig->getRoleLimitation());
341 $this->create(false); //create default setting, adjust them later
342
343 //clone default values
345
346 //clone fieldsettings
347 foreach ($orig->getFieldSettings() as $orig_fieldsetting) {
348 $new_fieldsetting = new ilDclTableViewFieldSetting();
349 $new_fieldsetting->setTableviewId($this->getId());
350 if ($new_fields[$orig_fieldsetting->getField()] ?? null) {
351 //normal fields
352 $new_fieldsetting->setField($new_fields[$orig_fieldsetting->getField()]->getId());
353 } else {
354 //standard fields
355 $new_fieldsetting->setField($orig_fieldsetting->getField());
356 }
357 $new_field_id = $new_fieldsetting->cloneStructure($orig_fieldsetting);
358
359 //clone default value
360 $datatype = $orig_fieldsetting->getFieldObject()->getDatatypeId();
361 $match = ilDclTableViewBaseDefaultValue::findSingle($datatype, $orig_fieldsetting->getId());
362
363 if (!is_null($match)) {
364 $new_default_value = $f->create($datatype);
365 $new_default_value->setTviewSetId($new_field_id);
366 $new_default_value->setValue($match->getValue());
367 $new_default_value->create();
368 }
369 }
370 $this->createFieldSetting('comments');
371
372 //clone pageobject
374 $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId());
375 $orig_pageobject->copy($this->getId());
376 }
377
378 // mandatory for all cloning functions
380 }
381
385 public static function getAllForTableId(int $table_id): array
386 {
387 return self::where(['table_id' => $table_id])->orderBy('title')->get();
388 }
389
394 public static function createOrGetStandardView(int $table_id): ActiveRecord
395 {
396 if ($standardview = self::where(['table_id' => $table_id])->first()) {
397 return $standardview;
398 }
399
400 global $DIC;
401 $rbacreview = $DIC['rbacreview'];
402 $http = $DIC->http();
403 $refinery = $DIC->refinery();
404
405 $roles = [];
406
407 $ref_id = $http->wrapper()->query()->retrieve('ref_id', $refinery->kindlyTo()->int());
408 foreach ($rbacreview->getParentRoleIds($ref_id) as $role_array) {
409 $roles[] = $role_array['obj_id'];
410 }
411
412 $view = new self();
413
414 $hasRefId = $http->wrapper()->query()->has('ref_id');
415
416 if ($hasRefId) {
417 global $DIC;
418 $rbacreview = $DIC['rbacreview'];
419
420 $ref_id = $http->wrapper()->query()->retrieve('ref_id', $refinery->kindlyTo()->int());
421
422 $roles = [];
423 foreach ($rbacreview->getParentRoleIds($ref_id) as $role_array) {
424 $roles[] = $role_array['obj_id'];
425 }
426 $view->setRoles(array_merge($roles, $rbacreview->getLocalRoles($ref_id)));
427 }
428 $view->setTableId($table_id);
429 // bugfix mantis 0023307
430 $lng = $DIC['lng'];
431 $view->setTitle($lng->txt('dcl_title_standardview'));
432 $view->create();
433
434 return $view;
435 }
436}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
static _isStandardField($field_id)
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,...
setTitle(string $title)
setRoleLimitation(bool $role_limitation)
setTableId(int $table_id)
static createOrGetStandardView(int $table_id)
static getAllForTableId(int $table_id)
cloneStructure(ilDclTableView $orig, array $new_fields)
setDescription(string $description)
static findOrGetInstance($primary_key, array $add_constructor_args=[])
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
$http
Definition: deliver.php:30
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26