ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $decimals->setDisabled(true);
128  }
129  }
130 
137  {
138  parent::importCustomDefinitionFormPostValues($a_form);
139 
140  $this->setDecimals($a_form->getInput("dec"));
141  }
142 
143 
144  //
145  // export/import
146  //
147 
148  protected function addPropertiesToXML(ilXmlWriter $a_writer)
149  {
150  parent::addPropertiesToXML($a_writer);
151 
152  $a_writer->xmlElement('FieldValue', array("id"=>"decimals"), $this->getDecimals());
153  }
154 
155  public function importXMLProperty($a_key, $a_value)
156  {
157  if ($a_key == "decimals") {
158  $this->setDecimals($a_value != "" ? $a_value : null);
159  }
160 
161  parent::importXMLProperty($a_key, $a_value);
162  }
163 }
AMD field type float (based on integer)
This class represents a property form user interface.
XML writer class.
addItem($a_item)
Add Item (Property, SectionHeader).
static getInstance()
Get singleton.
foreach($_POST as $key=> $value) $res
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.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $lng
Definition: privfeed.php:17
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
$def
Definition: croninfo.php:21