ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAdvancedMDFieldDefinitionInteger.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/class.ilAdvancedMDFieldDefinition.php";
5 
15 {
16  protected $min; // [integer]
17  protected $max; // [integer]
18  protected $suffix; // [string]
19 
20  //
21  // generic types
22  //
23 
24  public function getType()
25  {
26  return self::TYPE_INTEGER;
27  }
28 
29  public function isFilterSupported()
30  {
31  return false;
32  }
33 
34 
35  //
36  // ADT
37  //
38 
39  protected function initADTDefinition()
40  {
41  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Integer");
42 
43  $def->setMin($this->getMin());
44  $def->setMax($this->getMax());
45  $def->setSuffix($this->getSuffix());
46 
47  return $def;
48  }
49 
50 
51  //
52  // properties
53  //
54 
60  public function setMin($a_value)
61  {
62  if($a_value !== null)
63  {
64  $a_value = (int)$a_value;
65  }
66  $this->min = $a_value;
67  }
68 
74  public function getMin()
75  {
76  return $this->min;
77  }
78 
84  public function setMax($a_value)
85  {
86  if($a_value !== null)
87  {
88  $a_value = (int)$a_value;
89  }
90  $this->max = $a_value;
91  }
92 
98  public function getMax()
99  {
100  return $this->max;
101  }
102 
108  public function setSuffix($a_value)
109  {
110  if($a_value !== null)
111  {
112  $a_value = trim($a_value);
113  }
114  $this->suffix = $a_value;
115  }
116 
122  public function getSuffix()
123  {
124  return $this->suffix;
125  }
126 
127 
128  //
129  // definition (NOT ADT-based)
130  //
131 
132  protected function importFieldDefinition(array $a_def)
133  {
134  $this->setMin($a_def["min"]);
135  $this->setMax($a_def["max"]);
136  $this->setSuffix($a_def["suffix"]);
137  }
138 
139  protected function getFieldDefinition()
140  {
141  return array(
142  "min" => $this->getMin(),
143  "max" => $this->getMax(),
144  "suffix" => $this->getSuffix()
145  );
146  }
147 
149  {
150  global $lng;
151 
152  $res = array();
153 
154  if($this->getMin() !== null)
155  {
156  $res[$lng->txt("md_adv_number_min")] = $this->getMin();
157  }
158  if($this->getMax() !== null)
159  {
160  $res[$lng->txt("md_adv_number_max")] = $this->getMax();
161  }
162  if($this->getSuffix())
163  {
164  $res[$lng->txt("md_adv_number_suffix")] = $this->getSuffix();
165  }
166 
167  return $res;
168  }
169 
176  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
177  {
178  global $lng;
179 
180  $min = new ilNumberInputGUI($lng->txt("md_adv_number_min"), "min");
181  $min->setValue($this->getMin());
182  $min->setSize(10);
183  $a_form->addItem($min);
184 
185  $max = new ilNumberInputGUI($lng->txt("md_adv_number_max"), "max");
186  $max->setValue($this->getMax());
187  $max->setSize(10);
188  $a_form->addItem($max);
189 
190  $suffix = new ilTextInputGUI($lng->txt("md_adv_number_suffix"), "suffix");
191  $suffix->setValue($this->getSuffix());
192  $suffix->setSize(10);
193  $a_form->addItem($suffix);
194 
195  if($a_disabled)
196  {
197  $min->setDisabled(true);
198  $max->setDisabled(true);
199  $suffix->setDisabled(true);
200  }
201  }
202 
209  {
210  $min = $a_form->getInput("min");
211  $this->setMin(($min !== "") ? $min : null);
212 
213  $max = $a_form->getInput("max");
214  $this->setMax(($max !== "") ? $max : null);
215 
216  $suffix = $a_form->getInput("suffix");
217  $this->setSuffix(($suffix !== "") ? $suffix : null);
218  }
219 
220 
221  //
222  // export/import
223  //
224 
225  protected function addPropertiesToXML(ilXmlWriter $a_writer)
226  {
227  $a_writer->xmlElement('FieldValue',array("id"=>"min"),$this->getMin());
228  $a_writer->xmlElement('FieldValue',array("id"=>"max"),$this->getMax());
229  $a_writer->xmlElement('FieldValue',array("id"=>"suffix"),$this->getSuffix());
230  }
231 
232  public function importXMLProperty($a_key, $a_value)
233  {
234  if($a_key == "min")
235  {
236  $this->setMin($a_value != "" ? $a_value : null);
237  }
238  if($a_key == "max")
239  {
240  $this->setMax($a_value != "" ? $a_value : null);
241  }
242  if($a_key == "suffix")
243  {
244  $this->setSuffix($a_value != "" ? $a_value : null);
245  }
246  }
247 
248  public function getValueForXML(ilADT $element)
249  {
250  return $element->getNumber();
251  }
252 
253  public function importValueFromXML($a_cdata)
254  {
255  $this->getADT()->setNumber($a_cdata);
256  }
257 }
258 
259 ?>
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.
ADT base class.
Definition: class.ilADT.php:11
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
This class represents a number property in a property form.
This class represents a text property in a property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.