ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDFieldDefinitionInteger.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected ?int $min = null;
29 protected ?int $max = null;
30 protected ?string $suffix = null;
31
32 protected $suffix_translations = [];
33
34 //
35 // generic types
36 //
37
38 public function getType(): int
39 {
40 return self::TYPE_INTEGER;
41 }
42
43 public function isFilterSupported(): bool
44 {
45 return false;
46 }
47
51 public function getSuffixTranslations(): array
52 {
54 }
55
56 public function setSuffixTranslation(string $language, string $suffix): void
57 {
58 $this->suffix_translations[$language] = $suffix;
59 }
60
61 public function setSuffixTranslations(array $suffix_translations): void
62 {
63 $this->suffix_translations = $suffix_translations;
64 }
65
66 protected function initADTDefinition(): ilADTDefinition
67 {
68 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType('Integer');
69 $def->setMin($this->getMin());
70 $def->setMax($this->getMax());
71 $def->setSuffix((string) ($this->getSuffixTranslations()[$this->language] ?? $this->getSuffix()));
72 return $def;
73 }
74
75 public function setMin(?int $a_value): void
76 {
77 if ($a_value !== null) {
78 $a_value = $a_value;
79 }
80 $this->min = $a_value;
81 }
82
83 public function getMin(): ?int
84 {
85 return $this->min;
86 }
87
88 public function setMax(?int $a_value): void
89 {
90 if ($a_value !== null) {
91 $a_value = $a_value;
92 }
93 $this->max = $a_value;
94 }
95
96 public function getMax(): ?int
97 {
98 return $this->max;
99 }
100
101 public function setSuffix(?string $a_value): void
102 {
103 if ($a_value !== null) {
104 $a_value = trim($a_value);
105 }
106 $this->suffix = $a_value;
107 }
108
109 public function getSuffix(): ?string
110 {
111 return $this->suffix;
112 }
113
114 protected function importFieldDefinition(array $a_def): void
115 {
116 $this->setMin(isset($a_def["min"]) ? (int) $a_def["min"] : null);
117 $this->setMax(isset($a_def["max"]) ? (int) $a_def["max"] : null);
118 $this->setSuffix($a_def["suffix"] ?? null);
119 $this->setSuffixTranslations($a_def['suffix_translations'] ?? []);
120 }
121
122 protected function getFieldDefinition(): array
123 {
124 return array(
125 "min" => $this->getMin(),
126 "max" => $this->getMax(),
127 "suffix" => $this->getSuffix(),
128 'suffix_translations' => $this->getSuffixTranslations()
129 );
130 }
131
132 public function getFieldDefinitionForTableGUI(string $content_language): array
133 {
134 $res = [];
135
136 if ($this->getMin() !== null) {
137 $res[$this->lng->txt("md_adv_number_min")] = $this->getMin();
138 }
139 if ($this->getMax() !== null) {
140 $res[$this->lng->txt("md_adv_number_max")] = $this->getMax();
141 }
142 if ($this->getSuffix()) {
143 if ($this->useDefaultLanguageMode($content_language)) {
144 $suffix = $this->getSuffix();
145 } else {
146 $suffix = $this->getSuffixTranslations()[$content_language] ?? '';
147 }
148 $res[$this->lng->txt("md_adv_number_suffix")] = $suffix;
149 }
150 return $res;
151 }
152
154 ilPropertyFormGUI $a_form,
155 bool $a_disabled = false,
156 string $language = ''
157 ): void {
158 $min = new ilNumberInputGUI($this->lng->txt("md_adv_number_min"), "min");
159 $min->setValue((string) $this->getMin());
160 $min->setSize(10);
161 $a_form->addItem($min);
162
163 $max = new ilNumberInputGUI($this->lng->txt("md_adv_number_max"), "max");
164 $max->setValue((string) $this->getMax());
165 $max->setSize(10);
166 $a_form->addItem($max);
167
168 $suffix = new ilTextInputGUI($this->lng->txt("md_adv_number_suffix"), "suffix");
169 if ($this->useDefaultLanguageMode($language)) {
170 $suffix->setValue($this->getSuffix());
171 } else {
173 $this->getRecordId()
174 )->getDefaultLanguage();
175 $suffix->setInfo($default_language . ': ' . $this->getSuffix());
176 $suffix->setValue($this->getSuffixTranslations()[$language] ?? '');
177 }
178 $suffix->setSize(10);
179 $a_form->addItem($suffix);
180
181 if ($a_disabled) {
182 $min->setDisabled(true);
183 $max->setDisabled(true);
184 $suffix->setDisabled(true);
185 }
186 }
187
188 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
189 {
190 $min = $a_form->getInput("min");
191 $this->setMin(($min !== "" && !is_null($min)) ? (int) $min : null);
192
193 $max = $a_form->getInput("max");
194 $this->setMax(($max !== "" && !is_null($max)) ? (int) $max : null);
195
196 if ($this->useDefaultLanguageMode($language)) {
197 $suffix = $a_form->getInput("suffix");
198 $this->setSuffix(($suffix !== "") ? $suffix : null);
199 } else {
200 $suffix = $a_form->getInput('suffix');
201 $this->setSuffixTranslation($language, $suffix);
202 }
203 }
204
205 protected function addPropertiesToXML(ilXmlWriter $a_writer): void
206 {
207 $a_writer->xmlElement('FieldValue', array("id" => "min"), $this->getMin());
208 $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMax());
209 $a_writer->xmlElement('FieldValue', array("id" => "suffix"), $this->getSuffix());
210
211 foreach ($this->getSuffixTranslations() as $lang_key => $suffix) {
212 $a_writer->xmlElement('FieldValue', ['id' => 'suffix_' . $lang_key], $suffix);
213 }
214 }
215
216 public function importXMLProperty(string $a_key, string $a_value): void
217 {
218 if ($a_key == "min") {
219 $this->setMin($a_value != "" ? (int) $a_value : null);
220 return;
221 }
222 if ($a_key == "max") {
223 $this->setMax($a_value != "" ? (int) $a_value : null);
224 return;
225 }
226 if ($a_key == "suffix") {
227 $this->setSuffix($a_value != "" ? $a_value : null);
228 return;
229 }
230
231 $parts = explode('_', $a_key);
232 if (isset($parts[0]) && $parts[0] == 'suffix') {
233 $this->setSuffixTranslation($parts[1], $a_value);
234 }
235 }
236
237 public function getValueForXML(ilADT $element): string
238 {
239 return (string) $element->getNumber();
240 }
241
242 public function importValueFromXML(string $a_cdata): void
243 {
244 $this->getADT()->setNumber($a_cdata);
245 }
246}
ADT definition base class.
ADT base class.
Definition: class.ilADT.php:26
getFieldDefinition()
Get (type-specific) field definition.
importValueFromXML(string $a_cdata)
Import value from xml.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add custom input elements to definition form.
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language.
static _getInstanceByRecordId(int $a_record_id)
This class represents a number property in a property form.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61