ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $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 }
AMD field type float (based on integer)
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
XML writer class.
addItem($a_item)
Add Item (Property, SectionHeader).
static getInstance()
Get singleton.
foreach($_POST as $key=> $value) $res
$lng
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.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
$def
Definition: croninfo.php:21
while(count($oldTaskList) > 0) foreach(array_keys($newTaskList) as $task) init()
Definition: build.php:77