ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng;
148
149 $res = array();
150
151 if ($this->getMin() !== null) {
152 $res[$lng->txt("md_adv_number_min")] = $this->getMin();
153 }
154 if ($this->getMax() !== null) {
155 $res[$lng->txt("md_adv_number_max")] = $this->getMax();
156 }
157 if ($this->getSuffix()) {
158 $res[$lng->txt("md_adv_number_suffix")] = $this->getSuffix();
159 }
160
161 return $res;
162 }
163
170 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
171 {
172 global $lng;
173
174 $min = new ilNumberInputGUI($lng->txt("md_adv_number_min"), "min");
175 $min->setValue($this->getMin());
176 $min->setSize(10);
177 $a_form->addItem($min);
178
179 $max = new ilNumberInputGUI($lng->txt("md_adv_number_max"), "max");
180 $max->setValue($this->getMax());
181 $max->setSize(10);
182 $a_form->addItem($max);
183
184 $suffix = new ilTextInputGUI($lng->txt("md_adv_number_suffix"), "suffix");
185 $suffix->setValue($this->getSuffix());
186 $suffix->setSize(10);
187 $a_form->addItem($suffix);
188
189 if ($a_disabled) {
190 $min->setDisabled(true);
191 $max->setDisabled(true);
192 $suffix->setDisabled(true);
193 }
194 }
195
202 {
203 $min = $a_form->getInput("min");
204 $this->setMin(($min !== "") ? $min : null);
205
206 $max = $a_form->getInput("max");
207 $this->setMax(($max !== "") ? $max : null);
208
209 $suffix = $a_form->getInput("suffix");
210 $this->setSuffix(($suffix !== "") ? $suffix : null);
211 }
212
213
214 //
215 // export/import
216 //
217
218 protected function addPropertiesToXML(ilXmlWriter $a_writer)
219 {
220 $a_writer->xmlElement('FieldValue', array("id"=>"min"), $this->getMin());
221 $a_writer->xmlElement('FieldValue', array("id"=>"max"), $this->getMax());
222 $a_writer->xmlElement('FieldValue', array("id"=>"suffix"), $this->getSuffix());
223 }
224
225 public function importXMLProperty($a_key, $a_value)
226 {
227 if ($a_key == "min") {
228 $this->setMin($a_value != "" ? $a_value : null);
229 }
230 if ($a_key == "max") {
231 $this->setMax($a_value != "" ? $a_value : null);
232 }
233 if ($a_key == "suffix") {
234 $this->setSuffix($a_value != "" ? $a_value : null);
235 }
236 }
237
238 public function getValueForXML(ilADT $element)
239 {
240 return $element->getNumber();
241 }
242
243 public function importValueFromXML($a_cdata)
244 {
245 $this->getADT()->setNumber($a_cdata);
246 }
247}
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 $lng
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res