ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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 $lng;
101 
102  $res = parent::getFieldDefinitionForTableGUI();
103  $res[$lng->txt("md_adv_number_decimals")] = $this->getDecimals();
104  return $res;
105  }
106 
113  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
114  {
115  global $lng;
116 
117  // #32
118  parent::addCustomFieldToDefinitionForm($a_form, $a_disabled);
119 
120  $decimals = new ilNumberInputGUI($lng->txt("md_adv_number_decimals"), "dec");
121  $decimals->setRequired(true);
122  $decimals->setValue($this->getDecimals());
123  $decimals->setSize(5);
124  $a_form->addItem($decimals);
125 
126  if($a_disabled)
127  {
128  $decimals->setDisabled(true);
129  }
130  }
131 
138  {
139  parent::importCustomDefinitionFormPostValues($a_form);
140 
141  $this->setDecimals($a_form->getInput("dec"));
142  }
143 
144 
145  //
146  // export/import
147  //
148 
149  protected function addPropertiesToXML(ilXmlWriter $a_writer)
150  {
151  parent::addPropertiesToXML($a_writer);
152 
153  $a_writer->xmlElement('FieldValue',array("id"=>"decimals"),$this->getDecimals());
154  }
155 
156  public function importXMLProperty($a_key, $a_value)
157  {
158  if($a_key == "decimals")
159  {
160  $this->setDecimals($a_value != "" ? $a_value : null);
161  }
162 
163  parent::importXMLProperty($a_key, $a_value);
164  }
165 }
166 
167 ?>
AMD field type float (based on integer)
This class represents a property form user interface.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
addItem($a_item)
Add Item (Property, SectionHeader).
static getInstance()
Get singleton.
This class represents a number property in a property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.