ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilDclSelectionFieldModel.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public const SELECTION_TYPE_SINGLE = 'selection_type_single';
24  public const SELECTION_TYPE_MULTI = 'selection_type_multi';
25  public const SELECTION_TYPE_COMBOBOX = 'selection_type_combobox';
26  public const PROP_SELECTION_TYPE = '';
27  public const PROP_SELECTION_OPTIONS = '';
28 
29  public function getValidFieldProperties(): array
30  {
31  return [$this::PROP_SELECTION_OPTIONS, $this::PROP_SELECTION_TYPE];
32  }
33 
34  public function getRecordQueryFilterObject(
35  $filter_value = "",
36  ?ilDclBaseFieldModel $sort_field = null
38 
39  $join_str
40  = " LEFT JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = "
41  . $this->db->quote($this->getId(), 'integer') . ") ";
42 
43  $join_str .= " LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id";
44 
45  $where_str = " AND ";
46  if ($filter_value == 'none') {
47  $where_str .= "("
48  . "filter_stloc_{$this->getId()}.value IS NULL "
49  . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("", 'text')
50  . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("[]", 'text')
51  . ") ";
52  } else {
53  if ($this->isMulti()) {
54  $where_str .= " (" .
55  "filter_stloc_{$this->getId()}.value LIKE " . $this->db->quote("%\"$filter_value\"%", 'text') .
56  ") ";
57  } else {
58  $where_str .= "filter_stloc_{$this->getId()}.value = "
59  . $this->db->quote($filter_value, 'integer');
60  }
61  }
62 
63  $join_str .= ") ";
64 
65  $sql_obj = new ilDclRecordQueryObject();
66  $sql_obj->setJoinStatement($join_str);
67  $sql_obj->setWhereStatement($where_str);
68 
69  return $sql_obj;
70  }
71 
72  public function isMulti(): bool
73  {
74  return ($this->getProperty($this::PROP_SELECTION_TYPE) === $this::SELECTION_TYPE_MULTI);
75  }
76 
80  public function setProperty(string $key, $value): ?ilDclFieldProperty
81  {
82  if ($key === $this::PROP_SELECTION_OPTIONS) {
84  $sorting = 1;
85  foreach ($value as $id => $val) {
86  ilDclSelectionOption::storeOption((int) $this->getId(), $id, $sorting, $val);
87  $sorting++;
88  }
89  return null;
90  }
91  return parent::setProperty($key, $value);
92  }
93 
97  public function getProperty(string $key): mixed
98  {
99  if ($key == $this::PROP_SELECTION_OPTIONS) {
100  $prop_values = [];
101  foreach (ilDclSelectionOption::getAllForField((int) $this->getId()) as $option) {
102  $prop_values[$option->getOptId()] = $option->getValue();
103  }
104 
105  return $prop_values;
106  }
107  return parent::getProperty($key);
108  }
109 
110  public function cloneProperties(ilDclBaseFieldModel $originalField): void
111  {
112  parent::cloneProperties($originalField);
113  $options = ilDclSelectionOption::getAllForField((int) $originalField->getId());
114  foreach ($options as $opt) {
115  $new_opt = new ilDclSelectionOption();
116  $new_opt->cloneOption($opt);
117  $new_opt->setFieldId((int) $this->getId());
118  $new_opt->store();
119  }
120  }
121 
122  public function doDelete(): void
123  {
124  foreach (ilDclSelectionOption::getAllForField((int) $this->getId()) as $option) {
125  $option->delete();
126  }
127  parent::doDelete();
128  }
129 }
cloneProperties(ilDclBaseFieldModel $originalField)
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
static flushOptions(int $field_id)
static getAllForField(int $field_id)