ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclSelectionFieldModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const string SELECTION_TYPE_SINGLE = 'selection_type_single';
24 public const string SELECTION_TYPE_MULTI = 'selection_type_multi';
25 public const string 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, $this::PROP_UNIQUE];
32 }
33
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, $this->sanitizeOptionValue($val));
87 $sorting++;
88 }
89 return null;
90 }
91 return parent::setProperty($key, $value);
92 }
93
94 public function sanitizeOptionValue(string $value): string
95 {
96 return $value;
97 }
98
99 public function personalizeOptionValue(string $value, ilObjUser $user): string
100 {
101 return $value;
102 }
103
107 public function getProperty(string $key): mixed
108 {
109 if ($key == $this::PROP_SELECTION_OPTIONS) {
110 $prop_values = [];
111 foreach (ilDclSelectionOption::getAllForField((int) $this->getId()) as $option) {
112 $prop_values[$option->getOptId()] = $option->getValue();
113 }
114
115 return $prop_values;
116 }
117 return parent::getProperty($key);
118 }
119
120 public function cloneProperties(ilDclBaseFieldModel $originalField): void
121 {
122 parent::cloneProperties($originalField);
123 $options = ilDclSelectionOption::getAllForField((int) $originalField->getId());
124 foreach ($options as $opt) {
125 $new_opt = new ilDclSelectionOption();
126 $new_opt->cloneOption($opt);
127 $new_opt->setFieldId((int) $this->getId());
128 $new_opt->store();
129 }
130 }
131
132 public function doDelete(): void
133 {
134 foreach (ilDclSelectionOption::getAllForField((int) $this->getId()) as $option) {
135 $option->delete();
136 }
137 parent::doDelete();
138 }
139
140 public function checkFieldCreationInput(ilPropertyFormGUI $form): bool
141 {
142 return $this->checkUniqueProp($form) && parent::checkFieldCreationInput($form);
143 }
144
145 public function checkValidity($value, ?int $record_id): bool
146 {
147 $this->checkUnique($value, $record_id);
148 return parent::checkValidity($value, $record_id);
149 }
150}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
doDelete()
Remove field and properties.
cloneProperties(ilDclBaseFieldModel $originalField)
personalizeOptionValue(string $value, ilObjUser $user)
checkFieldCreationInput(ilPropertyFormGUI $form)
Checks input of specific fields befor saving.
getValidFieldProperties()
Returns all valid properties for a field-type.
checkValidity($value, ?int $record_id)
Check if input is valid.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
static getAllForField(int $field_id)
static flushOptions(int $field_id)
User class.
This class represents a property form user interface.