ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
34 //
35 // ADT
36 //
37
38 protected function initADTDefinition()
39 {
40 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Float");
41
42 $def->setMin($this->getMin());
43 $def->setMax($this->getMax());
44 $def->setDecimals($this->getDecimals());
45 $def->setSuffix($this->getSuffix());
46
47 return $def;
48 }
49
50
51 //
52 // properties
53 //
54
60 public function setDecimals($a_value)
61 {
62 $this->decimals = max(1, abs((int)$a_value));
63 }
64
70 public function getDecimals()
71 {
72 return $this->decimals;
73 }
74
75
76 //
77 // definition (NOT ADT-based)
78 //
79
80 protected function importFieldDefinition(array $a_def)
81 {
82 parent::importFieldDefinition($a_def);
83 $this->setDecimals($a_def["decimals"]);
84 }
85
86 protected function getFieldDefinition()
87 {
88 $def = parent::getFieldDefinition();
89 $def["decimals"] = $this->getDecimals();
90 return $def;
91 }
92
94 {
95 global $lng;
96
97 $res = parent::getFieldDefinitionForTableGUI();
98 $res[$lng->txt("md_adv_number_decimals")] = $this->getDecimals();
99 return $res;
100 }
101
108 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
109 {
110 global $lng;
111
112 // #32
113 parent::addCustomFieldToDefinitionForm($a_form, $a_disabled);
114
115 $decimals = new ilNumberInputGUI($lng->txt("md_adv_number_decimals"), "dec");
116 $decimals->setRequired(true);
117 $decimals->setValue($this->getDecimals());
118 $decimals->setSize(5);
119 $a_form->addItem($decimals);
120
121 if($a_disabled)
122 {
123 $decimals->setDisabled(true);
124 }
125 }
126
133 {
134 parent::importCustomDefinitionFormPostValues($a_form);
135
136 $this->setDecimals($a_form->getInput("dec"));
137 }
138
139
140 //
141 // export/import
142 //
143
144 protected function addPropertiesToXML(ilXmlWriter $a_writer)
145 {
146 parent::addPropertiesToXML($a_writer);
147
148 $a_writer->xmlElement('FieldValue',array("id"=>"decimals"),$this->getDecimals());
149 }
150
151 public function importXMLProperty($a_key, $a_value)
152 {
153 if($a_key == "decimals")
154 {
155 $this->setDecimals($a_value != "" ? $a_value : null);
156 }
157
158 parent::importXMLProperty($a_key, $a_value);
159 }
160}
161
162?>
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)
global $lng
Definition: privfeed.php:40