ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_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 $a_value = (int) $a_value;
64 }
65 $this->min = $a_value;
66 }
67
73 public function getMin()
74 {
75 return $this->min;
76 }
77
83 public function setMax($a_value)
84 {
85 if ($a_value !== null) {
86 $a_value = (int) $a_value;
87 }
88 $this->max = $a_value;
89 }
90
96 public function getMax()
97 {
98 return $this->max;
99 }
100
106 public function setSuffix($a_value)
107 {
108 if ($a_value !== null) {
109 $a_value = trim($a_value);
110 }
111 $this->suffix = $a_value;
112 }
113
119 public function getSuffix()
120 {
121 return $this->suffix;
122 }
123
124
125 //
126 // definition (NOT ADT-based)
127 //
128
129 protected function importFieldDefinition(array $a_def)
130 {
131 $this->setMin($a_def["min"]);
132 $this->setMax($a_def["max"]);
133 $this->setSuffix($a_def["suffix"]);
134 }
135
136 protected function getFieldDefinition()
137 {
138 return array(
139 "min" => $this->getMin(),
140 "max" => $this->getMax(),
141 "suffix" => $this->getSuffix()
142 );
143 }
144
146 {
147 global $DIC;
148
149 $lng = $DIC['lng'];
150
151 $res = array();
152
153 if ($this->getMin() !== null) {
154 $res[$lng->txt("md_adv_number_min")] = $this->getMin();
155 }
156 if ($this->getMax() !== null) {
157 $res[$lng->txt("md_adv_number_max")] = $this->getMax();
158 }
159 if ($this->getSuffix()) {
160 $res[$lng->txt("md_adv_number_suffix")] = $this->getSuffix();
161 }
162
163 return $res;
164 }
165
172 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
173 {
174 global $DIC;
175
176 $lng = $DIC['lng'];
177
178 $min = new ilNumberInputGUI($lng->txt("md_adv_number_min"), "min");
179 $min->setValue($this->getMin());
180 $min->setSize(10);
181 $a_form->addItem($min);
182
183 $max = new ilNumberInputGUI($lng->txt("md_adv_number_max"), "max");
184 $max->setValue($this->getMax());
185 $max->setSize(10);
186 $a_form->addItem($max);
187
188 $suffix = new ilTextInputGUI($lng->txt("md_adv_number_suffix"), "suffix");
189 $suffix->setValue($this->getSuffix());
190 $suffix->setSize(10);
191 $a_form->addItem($suffix);
192
193 if ($a_disabled) {
194 $min->setDisabled(true);
195 $max->setDisabled(true);
196 $suffix->setDisabled(true);
197 }
198 }
199
206 {
207 $min = $a_form->getInput("min");
208 $this->setMin(($min !== "") ? $min : null);
209
210 $max = $a_form->getInput("max");
211 $this->setMax(($max !== "") ? $max : null);
212
213 $suffix = $a_form->getInput("suffix");
214 $this->setSuffix(($suffix !== "") ? $suffix : null);
215 }
216
217
218 //
219 // export/import
220 //
221
222 protected function addPropertiesToXML(ilXmlWriter $a_writer)
223 {
224 $a_writer->xmlElement('FieldValue', array("id" => "min"), $this->getMin());
225 $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMax());
226 $a_writer->xmlElement('FieldValue', array("id" => "suffix"), $this->getSuffix());
227 }
228
229 public function importXMLProperty($a_key, $a_value)
230 {
231 if ($a_key == "min") {
232 $this->setMin($a_value != "" ? $a_value : null);
233 }
234 if ($a_key == "max") {
235 $this->setMax($a_value != "" ? $a_value : null);
236 }
237 if ($a_key == "suffix") {
238 $this->setSuffix($a_value != "" ? $a_value : null);
239 }
240 }
241
242 public function getValueForXML(ilADT $element)
243 {
244 return $element->getNumber();
245 }
246
247 public function importValueFromXML($a_cdata)
248 {
249 $this->getADT()->setNumber($a_cdata);
250 }
251}
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:12
getFieldDefinition()
Get (type-specific) field definition.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
importXMLProperty($a_key, $a_value)
Import property from XML.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
This class represents a text property in a property form.
XML writer class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$def
Definition: croninfo.php:21
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res