ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAdvancedMDFieldDefinitionFloat.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/Types/class.ilAdvancedMDFieldDefinitionInteger.php";
5
15{
16 protected $decimals; // [integer]
17
18 //
19 // generic types
20 //
21
22 public function getType()
23 {
24 return self::TYPE_FLOAT;
25 }
26
27 protected function init()
28 {
29 parent::init();
30 $this->setDecimals(2);
31 }
32
33 public function isFilterSupported()
34 {
35 return false;
36 }
37
38
39 //
40 // ADT
41 //
42
43 protected function initADTDefinition()
44 {
45 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Float");
46
47 $def->setMin($this->getMin());
48 $def->setMax($this->getMax());
49 $def->setDecimals($this->getDecimals());
50 $def->setSuffix($this->getSuffix());
51
52 return $def;
53 }
54
55
56 //
57 // properties
58 //
59
65 public function setDecimals($a_value)
66 {
67 $this->decimals = max(1, abs((int) $a_value));
68 }
69
75 public function getDecimals()
76 {
77 return $this->decimals;
78 }
79
80
81 //
82 // definition (NOT ADT-based)
83 //
84
85 protected function importFieldDefinition(array $a_def)
86 {
87 parent::importFieldDefinition($a_def);
88 $this->setDecimals($a_def["decimals"]);
89 }
90
91 protected function getFieldDefinition()
92 {
93 $def = parent::getFieldDefinition();
94 $def["decimals"] = $this->getDecimals();
95 return $def;
96 }
97
99 {
100 global $DIC;
101
102 $lng = $DIC['lng'];
103
104 $res = parent::getFieldDefinitionForTableGUI();
105 $res[$lng->txt("md_adv_number_decimals")] = $this->getDecimals();
106 return $res;
107 }
108
115 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
116 {
117 global $DIC;
118
119 $lng = $DIC['lng'];
120
121 // #32
122 parent::addCustomFieldToDefinitionForm($a_form, $a_disabled);
123
124 $decimals = new ilNumberInputGUI($lng->txt("md_adv_number_decimals"), "dec");
125 $decimals->setRequired(true);
126 $decimals->setValue($this->getDecimals());
127 $decimals->setSize(5);
128 $a_form->addItem($decimals);
129
130 if ($a_disabled) {
131 $decimals->setDisabled(true);
132 }
133 }
134
141 {
142 parent::importCustomDefinitionFormPostValues($a_form);
143
144 $this->setDecimals($a_form->getInput("dec"));
145 }
146
147
148 //
149 // export/import
150 //
151
152 protected function addPropertiesToXML(ilXmlWriter $a_writer)
153 {
154 parent::addPropertiesToXML($a_writer);
155
156 $a_writer->xmlElement('FieldValue', array("id" => "decimals"), $this->getDecimals());
157 }
158
159 public function importXMLProperty($a_key, $a_value)
160 {
161 if ($a_key == "decimals") {
162 $this->setDecimals($a_value != "" ? $a_value : null);
163 }
164
165 parent::importXMLProperty($a_key, $a_value);
166 }
167}
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Get singleton.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.
importXMLProperty($a_key, $a_value)
Import property from XML.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
getFieldDefinitionForTableGUI()
Parse properties for table gui.
getFieldDefinition()
Get (type-specific) field definition.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
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.
XML writer class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$lng
foreach($_POST as $key=> $value) $res
$DIC
Definition: xapitoken.php:46