ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableViewFieldSetting.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
23 {
34  protected ?int $id;
42  protected int $tableview_id;
50  protected string $field = "";
57  protected bool $visible = false;
64  protected bool $in_filter = false;
71  protected $filter_value = "";
78  protected bool $filter_changeable = false;
85  protected bool $required_create = false;
92  protected bool $locked_create = false;
99  protected ?string $default_value = null;
107  protected bool $visible_create = false;
115  protected bool $visible_edit = false;
122  protected bool $required_edit = false;
129  protected bool $locked_edit = false;
130 
135  public static function returnDbTableName(): string
136  {
137  return "il_dcl_tview_set";
138  }
139 
140  public function getTableviewId(): int
141  {
142  return $this->tableview_id;
143  }
144 
145  public function setTableviewId(int $tableview_id): void
146  {
147  $this->tableview_id = $tableview_id;
148  }
149 
150  public function getField(): string
151  {
152  return $this->field;
153  }
154 
158  public function setField(string $field): void
159  {
160  $this->field = $field;
161  }
162 
163  public function isVisibleInList(): bool
164  {
165  return $this->visible;
166  }
167 
168  public function setVisible(bool $visible): void
169  {
170  $this->visible = $visible;
171  }
172 
173  public function isInFilter(): bool
174  {
175  return $this->in_filter;
176  }
177 
178  public function setInFilter(bool $in_filter): void
179  {
180  $this->in_filter = $in_filter;
181  }
182 
183  public function getFilterValue()
184  {
185  return $this->filter_value;
186  }
187 
188  public function setFilterValue($filter_value): void
189  {
190  $this->filter_value = $filter_value;
191  }
192 
193  public function isFilterChangeable(): bool
194  {
196  }
197 
198  public function setFilterChangeable(bool $filter_changeable): void
199  {
200  $this->filter_changeable = $filter_changeable;
201  }
202 
203  public function getId(): int
204  {
205  return $this->id;
206  }
207 
208  public function setId(int $id): void
209  {
210  $this->id = $id;
211  }
212 
213  public function isRequiredCreate(): bool
214  {
215  return $this->required_create;
216  }
217 
218  public function setRequiredCreate(bool $required_create): void
219  {
220  $this->required_create = $required_create;
221  }
222 
223  public function isLockedCreate(): bool
224  {
225  return $this->locked_create;
226  }
227 
228  public function setLockedCreate(bool $locked_create): void
229  {
230  $this->locked_create = $locked_create;
231  }
232 
233  public function isRequiredEdit(): bool
234  {
235  return $this->required_edit;
236  }
237 
238  public function setRequiredEdit(bool $required_edit): void
239  {
240  $this->required_edit = $required_edit;
241  }
242 
243  public function isLockedEdit(): bool
244  {
245  return $this->locked_edit;
246  }
247 
248  public function setLockedEdit(bool $locked_edit): void
249  {
250  $this->locked_edit = $locked_edit;
251  }
252 
253  public function getDefaultValue(): ?string
254  {
255  return $this->default_value;
256  }
257 
258  public function setDefaultValue(?string $default_value): void
259  {
260  $this->default_value = $default_value;
261  }
262 
263  public function isVisibleCreate(): bool
264  {
265  return $this->visible_create;
266  }
267 
268  public function setVisibleCreate(bool $visible_create): void
269  {
270  $this->visible_create = $visible_create;
271  }
272 
273  public function setNotVisibleCreate(bool $not_visible_create): void
274  {
275  $this->visible_create = !$not_visible_create;
276  }
277 
278  public function isNotVisibleCreate(): bool
279  {
280  return !$this->visible_create;
281  }
282 
283  public function isVisibleEdit(): bool
284  {
285  return $this->visible_edit;
286  }
287 
288  public function setVisibleEdit(bool $visible_edit): void
289  {
290  $this->visible_edit = $visible_edit;
291  }
292 
293  public function setNotVisibleEdit(bool $not_visible): void
294  {
295  $this->visible_edit = !$not_visible;
296  }
297 
298  public function isNotVisibleEdit(): bool
299  {
300  return !$this->visible_edit;
301  }
302 
303  public function isVisibleInForm(bool $creation_mode): bool
304  {
305  return $creation_mode ? $this->isVisibleCreate() : $this->isVisibleEdit();
306  }
307 
308  public function isLocked(bool $creation_mode): bool
309  {
310  return $creation_mode ? $this->isLockedCreate() : $this->isLockedEdit();
311  }
312 
313  public function isRequired(bool $creation_mode): bool
314  {
315  return $creation_mode ? $this->isRequiredCreate() : $this->isRequiredEdit();
316  }
317 
318  public function sleep($field_name): ?string
319  {
320  if ($field_name == 'filter_value' && is_array($this->filter_value)) {
321  return json_encode($this->filter_value);
322  }
323 
324  return null;
325  }
326 
327  public function wakeUp($field_name, $field_value): ?array
328  {
329  if ($field_name == 'filter_value') {
330  $return = [];
331  $json = null;
332  if ($field_value) {
333  $json = json_decode($field_value, true);
334  }
335  if (is_array($json)) {
336  foreach ($json as $key => $value) {
337  $return['filter_' . $this->getField() . '_' . $key] = $value;
338  }
339  } else {
340  $return = ['filter_' . $this->getField() => $field_value];
341  }
342 
343  return $return;
344  }
345 
346  return null;
347  }
348 
350  {
351  $this->setFilterChangeable($orig->isFilterChangeable());
352  $this->setInFilter($orig->isInFilter());
353  $this->setVisibleCreate($orig->isVisibleCreate());
354  $this->setVisibleEdit($orig->isVisibleEdit());
355  $this->setLockedCreate($orig->isLockedCreate());
356  $this->setLockedEdit($orig->isLockedEdit());
357  $this->setRequiredCreate($orig->isRequiredCreate());
358  $this->setRequiredEdit($orig->isRequiredEdit());
359  $filter_value = $orig->getFilterValue();
360  $this->setFilterValue($filter_value['filter_' . $orig->getField()] ?? $filter_value);
361  $this->setVisible($orig->isVisibleInList());
362  $this->create();
363  return $this->getId();
364  }
365 
369  public function getFieldObject()
370  {
371  if (is_numeric($this->field)) { //normal field
372  return ilDclCache::getFieldCache((int) $this->field);
373  } else { //standard field
374  global $DIC;
375  $lng = $DIC['lng'];
376  $stdfield = new ilDclStandardField();
377  $stdfield->setId($this->field);
378  $stdfield->setDatatypeId(ilDclStandardField::_getDatatypeForId($this->field));
379  $stdfield->setTitle($lng->txt('dcl_' . $this->field));
380 
381  return $stdfield;
382  }
383  }
384 
388  public static function getTableViewFieldSetting(string $id, int $tableview_id): ActiveRecord
389  {
390  return parent::where(['field' => $id,
391  'tableview_id' => $tableview_id
392  ])->first();
393  }
394 
400  public static function getInstance(int $tableview_id, int $field_id): ActiveRecord
401  {
402  if (!($setting = self::where(['field' => $field_id, 'tableview_id' => $tableview_id])->first())) {
403  $setting = new self();
404  $setting->setField((string) $field_id);
405  $setting->setTableviewId($tableview_id);
406  }
407  return $setting;
408  }
409 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getFieldCache(int $field_id=0)
cloneStructure(ilDclTableViewFieldSetting $orig)
static _getDatatypeForId(string $id)
gives you the datatype id of a specified standard field.
global $DIC
Definition: feed.php:28
static getInstance(int $tableview_id, int $field_id)
static getTableViewFieldSetting(string $id, int $tableview_id)
$lng
string $key
Consumer key/client ID value.
Definition: System.php:193