ILIAS  release_8 Revision v8.24
class.ilAdvancedMDFieldDefinitionFloat.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
13 private const MIN_DECIMALS = 1;
14
15 protected int $decimals;
16
17 public function getType(): int
18 {
19 return self::TYPE_FLOAT;
20 }
21
22 protected function init(): void
23 {
24 parent::init();
25 $this->setDecimals(2);
26 }
27
28 public function isFilterSupported(): bool
29 {
30 return false;
31 }
32
33 protected function initADTDefinition(): ilADTDefinition
34 {
35 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Float");
36
37 $def->setMin($this->getMin());
38 $def->setMax($this->getMax());
39 $def->setDecimals($this->getDecimals());
40 $def->setSuffix($this->getSuffixTranslations()[$this->language] ?? $this->getSuffix());
41 return $def;
42 }
43
48 public function setDecimals($a_value)
49 {
50 $this->decimals = max(self::MIN_DECIMALS, abs((int) $a_value));
51 }
52
57 public function getDecimals()
58 {
59 return $this->decimals;
60 }
61
62
63 //
64 // definition (NOT ADT-based)
65 //
66
67 protected function importFieldDefinition(array $a_def): void
68 {
69 parent::importFieldDefinition($a_def);
70 $this->setDecimals($a_def["decimals"] ?? self::MIN_DECIMALS);
71 }
72
73 protected function getFieldDefinition(): array
74 {
75 $def = parent::getFieldDefinition();
76 $def["decimals"] = $this->getDecimals();
77 return $def;
78 }
79
80 public function getFieldDefinitionForTableGUI(string $content_language): array
81 {
82 global $DIC;
83
84 $lng = $DIC['lng'];
85
86 $res = parent::getFieldDefinitionForTableGUI($content_language);
87 $res[$lng->txt("md_adv_number_decimals")] = $this->getDecimals();
88 return $res;
89 }
90
98 ilPropertyFormGUI $a_form,
99 bool $a_disabled = false,
100 string $language = ''
101 ): void {
102 global $DIC;
103
104 $lng = $DIC['lng'];
105
106 // #32
107 parent::addCustomFieldToDefinitionForm($a_form, $a_disabled, $language);
108
109 $decimals = new ilNumberInputGUI($lng->txt("md_adv_number_decimals"), "dec");
110 $decimals->setRequired(true);
111 $decimals->setValue((string) $this->getDecimals());
112 $decimals->setSize(5);
113 $a_form->addItem($decimals);
114
115 if ($a_disabled) {
116 $decimals->setDisabled(true);
117 }
118 }
119
123 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
124 {
125 parent::importCustomDefinitionFormPostValues($a_form, $language);
126 $this->setDecimals((int) $a_form->getInput("dec"));
127 }
128
129
130 //
131 // export/import
132 //
133
134 protected function addPropertiesToXML(ilXmlWriter $a_writer): void
135 {
136 parent::addPropertiesToXML($a_writer);
137 $a_writer->xmlElement('FieldValue', array("id" => "decimals"), $this->getDecimals());
138 }
139
140 public function importXMLProperty(string $a_key, string $a_value): void
141 {
142 if ($a_key == "decimals") {
143 $this->setDecimals($a_value != "" ? $a_value : null);
144 }
145
146 parent::importXMLProperty($a_key, $a_value);
147 }
148}
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.
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)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69