ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
30  //
31  // ADT
32  //
33 
34  protected function initADTDefinition()
35  {
36  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Integer");
37 
38  $def->setMin($this->getMin());
39  $def->setMax($this->getMax());
40  $def->setSuffix($this->getSuffix());
41 
42  return $def;
43  }
44 
45 
46  //
47  // properties
48  //
49 
55  public function setMin($a_value)
56  {
57  if($a_value !== null)
58  {
59  $a_value = (int)$a_value;
60  }
61  $this->min = $a_value;
62  }
63 
69  public function getMin()
70  {
71  return $this->min;
72  }
73 
79  public function setMax($a_value)
80  {
81  if($a_value !== null)
82  {
83  $a_value = (int)$a_value;
84  }
85  $this->max = $a_value;
86  }
87 
93  public function getMax()
94  {
95  return $this->max;
96  }
97 
103  public function setSuffix($a_value)
104  {
105  if($a_value !== null)
106  {
107  $a_value = trim($a_value);
108  }
109  $this->suffix = $a_value;
110  }
111 
117  public function getSuffix()
118  {
119  return $this->suffix;
120  }
121 
122 
123  //
124  // definition (NOT ADT-based)
125  //
126 
127  protected function importFieldDefinition(array $a_def)
128  {
129  $this->setMin($a_def["min"]);
130  $this->setMax($a_def["max"]);
131  $this->setSuffix($a_def["suffix"]);
132  }
133 
134  protected function getFieldDefinition()
135  {
136  return array(
137  "min" => $this->getMin(),
138  "max" => $this->getMax(),
139  "suffix" => $this->getSuffix()
140  );
141  }
142 
144  {
145  global $lng;
146 
147  $res = array();
148 
149  if($this->getMin() !== null)
150  {
151  $res[$lng->txt("md_adv_number_min")] = $this->getMin();
152  }
153  if($this->getMax() !== null)
154  {
155  $res[$lng->txt("md_adv_number_max")] = $this->getMax();
156  }
157  if($this->getSuffix())
158  {
159  $res[$lng->txt("md_adv_number_suffix")] = $this->getSuffix();
160  }
161 
162  return $res;
163  }
164 
171  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
172  {
173  global $lng;
174 
175  $min = new ilNumberInputGUI($lng->txt("md_adv_number_min"), "min");
176  $min->setValue($this->getMin());
177  $min->setSize(10);
178  $a_form->addItem($min);
179 
180  $max = new ilNumberInputGUI($lng->txt("md_adv_number_max"), "max");
181  $max->setValue($this->getMax());
182  $max->setSize(10);
183  $a_form->addItem($max);
184 
185  $suffix = new ilTextInputGUI($lng->txt("md_adv_number_suffix"), "suffix");
186  $suffix->setValue($this->getSuffix());
187  $suffix->setSize(10);
188  $a_form->addItem($suffix);
189 
190  if($a_disabled)
191  {
192  $min->setDisabled(true);
193  $max->setDisabled(true);
194  $suffix->setDisabled(true);
195  }
196  }
197 
204  {
205  $min = $a_form->getInput("min");
206  $this->setMin(($min !== "") ? $min : null);
207 
208  $max = $a_form->getInput("max");
209  $this->setMax(($max !== "") ? $max : null);
210 
211  $suffix = $a_form->getInput("suffix");
212  $this->setSuffix(($suffix !== "") ? $suffix : null);
213  }
214 
215 
216  //
217  // export/import
218  //
219 
220  protected function addPropertiesToXML(ilXmlWriter $a_writer)
221  {
222  $a_writer->xmlElement('FieldValue',array("id"=>"min"),$this->getMin());
223  $a_writer->xmlElement('FieldValue',array("id"=>"max"),$this->getMax());
224  $a_writer->xmlElement('FieldValue',array("id"=>"suffix"),$this->getSuffix());
225  }
226 
227  public function importXMLProperty($a_key, $a_value)
228  {
229  if($a_key == "min")
230  {
231  $this->setMin($a_value != "" ? $a_value : null);
232  }
233  if($a_key == "max")
234  {
235  $this->setMax($a_value != "" ? $a_value : null);
236  }
237  if($a_key == "suffix")
238  {
239  $this->setSuffix($a_value != "" ? $a_value : null);
240  }
241  }
242 
243  public function getValueForXML(ilADT $element)
244  {
245  return $element->getNumber();
246  }
247 
248  public function importValueFromXML($a_cdata)
249  {
250  $this->getADT()->setNumber($a_cdata);
251  }
252 }
253 
254 ?>