ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDFieldDefinitionFloat.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
21
28{
29 private const MIN_DECIMALS = 1;
30
31 protected int $decimals;
32
33 public function __construct(GenericData $generic_data, string $language = '')
34 {
35 $this->init();
36 parent::__construct($generic_data, $language);
37 }
38
39 public function getType(): int
40 {
41 return self::TYPE_FLOAT;
42 }
43
44 protected function init(): void
45 {
46 $this->setDecimals(2);
47 }
48
49 public function isFilterSupported(): bool
50 {
51 return false;
52 }
53
54 protected function initADTDefinition(): ilADTDefinition
55 {
56 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Float");
57
58 $def->setMin($this->getMin());
59 $def->setMax($this->getMax());
60 $def->setDecimals($this->getDecimals());
61 $def->setSuffix($this->getSuffixTranslations()[$this->language] ?? $this->getSuffix());
62 return $def;
63 }
64
69 public function setDecimals($a_value)
70 {
71 $this->decimals = max(self::MIN_DECIMALS, abs((int) $a_value));
72 }
73
78 public function getDecimals()
79 {
80 return $this->decimals;
81 }
82
83
84 //
85 // definition (NOT ADT-based)
86 //
87
88 protected function importFieldDefinition(array $a_def): void
89 {
90 parent::importFieldDefinition($a_def);
91 $this->setDecimals($a_def["decimals"] ?? self::MIN_DECIMALS);
92 }
93
94 protected function getFieldDefinition(): array
95 {
96 $def = parent::getFieldDefinition();
97 $def["decimals"] = $this->getDecimals();
98 return $def;
99 }
100
101 public function getFieldDefinitionForTableGUI(string $content_language): array
102 {
103 global $DIC;
104
105 $lng = $DIC['lng'];
106
107 $res = parent::getFieldDefinitionForTableGUI($content_language);
108 $res[$lng->txt("md_adv_number_decimals")] = $this->getDecimals();
109 return $res;
110 }
111
119 ilPropertyFormGUI $a_form,
120 bool $a_disabled = false,
121 string $language = ''
122 ): void {
123 global $DIC;
124
125 $lng = $DIC['lng'];
126
127 // #32
128 parent::addCustomFieldToDefinitionForm($a_form, $a_disabled, $language);
129
130 $decimals = new ilNumberInputGUI($lng->txt("md_adv_number_decimals"), "dec");
131 $decimals->setRequired(true);
132 $decimals->setValue((string) $this->getDecimals());
133 $decimals->setSize(5);
134 $a_form->addItem($decimals);
135
136 if ($a_disabled) {
137 $decimals->setDisabled(true);
138 }
139 }
140
144 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
145 {
146 parent::importCustomDefinitionFormPostValues($a_form, $language);
147 $this->setDecimals((int) $a_form->getInput("dec"));
148 }
149
150
151 //
152 // export/import
153 //
154
155 protected function addPropertiesToXML(ilXmlWriter $a_writer): void
156 {
157 parent::addPropertiesToXML($a_writer);
158 $a_writer->xmlElement('FieldValue', array("id" => "decimals"), $this->getDecimals());
159 }
160
161 public function importXMLProperty(string $a_key, string $a_value): void
162 {
163 if ($a_key == "decimals") {
164 $this->setDecimals($a_value != "" ? $a_value : null);
165 }
166
167 parent::importXMLProperty($a_key, $a_value);
168 }
169}
ADT definition base class.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
__construct(GenericData $generic_data, string $language='')
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add input elements to definition form.
getFieldDefinition()
Get (type-specific) field definition.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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 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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26