ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDFieldDefinitionInteger.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php";
5
15{
16 protected $min; // [integer]
17 protected $max; // [integer]
18 protected $suffix; // [string]
19
20 protected $suffix_translations = [];
21
22 //
23 // generic types
24 //
25
26 public function getType()
27 {
28 return self::TYPE_INTEGER;
29 }
30
31 public function isFilterSupported()
32 {
33 return false;
34 }
35
39 public function getSuffixTranslations()
40 {
42 }
43
48 public function setSuffixTranslation(string $language, string $suffix)
49 {
50 $this->suffix_translations[$language] = $suffix;
51 }
52
57 {
58 $this->suffix_translations = $suffix_translations;
59 }
60
61 //
62 // ADT
63 //
64
69 protected function initADTDefinition()
70 {
71 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType('Integer');
72 $def->setMin($this->getMin());
73 $def->setMax($this->getMax());
74 $def->setSuffix(isset($this->getSuffixTranslations()[$this->language]) ? $this->getSuffixTranslations()[$this->language] : $this->getSuffix());
75 return $def;
76 }
77
78
79 //
80 // properties
81 //
82
88 public function setMin($a_value)
89 {
90 if ($a_value !== null) {
91 $a_value = (int) $a_value;
92 }
93 $this->min = $a_value;
94 }
95
101 public function getMin()
102 {
103 return $this->min;
104 }
105
111 public function setMax($a_value)
112 {
113 if ($a_value !== null) {
114 $a_value = (int) $a_value;
115 }
116 $this->max = $a_value;
117 }
118
124 public function getMax()
125 {
126 return $this->max;
127 }
128
134 public function setSuffix($a_value)
135 {
136 if ($a_value !== null) {
137 $a_value = trim($a_value);
138 }
139 $this->suffix = $a_value;
140 }
141
147 public function getSuffix()
148 {
149 return $this->suffix;
150 }
151
152
153 //
154 // definition (NOT ADT-based)
155 //
156
157 protected function importFieldDefinition(array $a_def)
158 {
159 $this->setMin($a_def["min"]);
160 $this->setMax($a_def["max"]);
161 $this->setSuffix($a_def["suffix"]);
162 $this->setSuffixTranslations(isset($a_def['suffix_translations']) ? $a_def['suffix_translations'] : []);
163 }
164
165 protected function getFieldDefinition()
166 {
167 return array(
168 "min" => $this->getMin(),
169 "max" => $this->getMax(),
170 "suffix" => $this->getSuffix(),
171 'suffix_translations' => $this->getSuffixTranslations()
172 );
173 }
174
175 public function getFieldDefinitionForTableGUI(string $content_language)
176 {
177 global $DIC;
178
179 $lng = $DIC['lng'];
180
181 $res = array();
182
183 if ($this->getMin() !== null) {
184 $res[$lng->txt("md_adv_number_min")] = $this->getMin();
185 }
186 if ($this->getMax() !== null) {
187 $res[$lng->txt("md_adv_number_max")] = $this->getMax();
188 }
189 if ($this->getSuffix()) {
190 if ($this->useDefaultLanguageMode($content_language)) {
191 $suffix = $this->getSuffix();
192 } else {
193 $suffix = $this->getSuffixTranslations()[$content_language] ?? '';
194 }
195 $res[$lng->txt("md_adv_number_suffix")] = $suffix;
196 }
197
198 return $res;
199 }
200
207 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false, string $language = '')
208 {
209 global $DIC;
210
211 $lng = $DIC['lng'];
212
213 $min = new ilNumberInputGUI($lng->txt("md_adv_number_min"), "min");
214 $min->setValue($this->getMin());
215 $min->setSize(10);
216 $a_form->addItem($min);
217
218 $max = new ilNumberInputGUI($lng->txt("md_adv_number_max"), "max");
219 $max->setValue($this->getMax());
220 $max->setSize(10);
221 $a_form->addItem($max);
222
223 $suffix = new ilTextInputGUI($lng->txt("md_adv_number_suffix"), "suffix");
224 if ($this->useDefaultLanguageMode($language)) {
225 $suffix->setValue($this->getSuffix());
226 } else {
227 $default_language = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id)->getDefaultLanguage();
228 $suffix->setInfo($default_language . ': ' . $this->getSuffix());
229 $suffix->setValue(isset($this->getSuffixTranslations()[$language]) ? $this->getSuffixTranslations()[$language] : '');
230 }
231 $suffix->setSize(10);
232 $a_form->addItem($suffix);
233
234 if ($a_disabled) {
235 $min->setDisabled(true);
236 $max->setDisabled(true);
237 $suffix->setDisabled(true);
238 }
239 }
240
247 {
248 $min = $a_form->getInput("min");
249 $this->setMin(($min !== "") ? $min : null);
250
251 $max = $a_form->getInput("max");
252 $this->setMax(($max !== "") ? $max : null);
253
254 if ($this->useDefaultLanguageMode($language)) {
255 $suffix = $a_form->getInput("suffix");
256 $this->setSuffix(($suffix !== "") ? $suffix : null);
257 } else {
258 $suffix = $a_form->getInput('suffix');
260 }
261 }
262
263
264 protected function addPropertiesToXML(ilXmlWriter $a_writer)
265 {
266 $a_writer->xmlElement('FieldValue', array("id" => "min"), $this->getMin());
267 $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMax());
268 $a_writer->xmlElement('FieldValue', array("id" => "suffix"), $this->getSuffix());
269
270 foreach ($this->getSuffixTranslations() as $lang_key => $suffix) {
271 $a_writer->xmlElement('FieldValue', ['id' => 'suffix_' . $lang_key], $suffix);
272 }
273 }
274
279 public function importXMLProperty($a_key, $a_value)
280 {
281 if ($a_key == "min") {
282 $this->setMin($a_value != "" ? $a_value : null);
283 return;
284 }
285 if ($a_key == "max") {
286 $this->setMax($a_value != "" ? $a_value : null);
287 return;
288 }
289 if ($a_key == "suffix") {
290 $this->setSuffix($a_value != "" ? $a_value : null);
291 return;
292 }
293
294 $parts = explode('_',$a_key);
295 if (isset($parts[0]) && $parts[0] == 'suffix') {
296 $this->setSuffixTranslation($parts[1], $a_value);
297 }
298 }
299
300 public function getValueForXML(ilADT $element)
301 {
302 return $element->getNumber();
303 }
304
305 public function importValueFromXML($a_cdata)
306 {
307 $this->getADT()->setNumber($a_cdata);
308 }
309}
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:12
getFieldDefinition()
Get (type-specific) field definition.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false, string $language='')
Add input elements to definition form.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
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($a_record_id)
Get instance by record id.
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
This class represents a text property in a property form.
XML writer class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
$lng
foreach($_POST as $key=> $value) $res