ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCombinationInputGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
32{
33 protected $items = array();
34 protected $labels;
35 protected $comparison;
36
39
47 function addCombinationItem($id, $item, $label = "")
48 {
49 $this->items[$id] = $item;
50 if($label)
51 {
52 $this->labels[$id] = $label;
53 }
54 }
55
62 function getCombinationItem($id)
63 {
64 if(isset($this->items[$id]))
65 {
66 return $this->items[$id];
67 }
68 }
69
76 {
77 if(isset($this->items[$id]))
78 {
79 unset($this->items[$id]);
80 }
81 }
82
89 function __call($method, $param)
90 {
91 $result = array();
92 foreach($this->items as $id => $obj)
93 {
94 if(method_exists($obj, $method))
95 {
96 $result[$id] = call_user_func_array(array($obj, $method), $param);
97 }
98 }
99 return $result;
100 }
101
105 function serializeData()
106 {
107 $result = array();
108 foreach($this->items as $id => $obj)
109 {
110 $result[$id] = $obj->serializeData();
111 }
112 return serialize($result);
113 }
114
118 function unserializeData($a_data)
119 {
120 $data = unserialize($a_data);
121
122 if ($data)
123 {
124 foreach($this->items as $id => $obj)
125 {
126 $obj->unserializeData($data[$id]);
127 }
128 }
129 else
130 {
131 foreach($this->items as $id => $obj)
132 {
133 if(method_exists($obj, "setValue"))
134 {
135 $this->setValue(false);
136 }
137 }
138 }
139 }
140
147 function setComparisonMode($mode)
148 {
149 if(in_array($mode, array(self::COMPARISON_ASCENDING, self::COMPARISON_DESCENDING)))
150 {
151 foreach($this->items as $obj)
152 {
153 if(!method_exists($obj, "getPostValueForComparison"))
154 {
155 return false;
156 }
157 }
158 $this->comparison_mode = $mode;
159 return true;
160 }
161 }
162
168 function setValue($a_value)
169 {
170 if(is_array($a_value))
171 {
172 foreach($a_value as $id => $value)
173 {
174 if(isset($this->items[$id]))
175 {
176 if(method_exists($this->items[$id], "setValue"))
177 {
178 $this->items[$id]->setValue($value);
179 }
180 // datetime
181 else if(method_exists($this->items[$id], "setDate"))
182 {
183 $this->items[$id]->setDate($value);
184 }
185 }
186 }
187 }
188 else if($a_value === NULL)
189 {
190 foreach($this->items as $item)
191 {
192 if(method_exists($item, "setValue"))
193 {
194 $item->setValue(NULL);
195 }
196 // datetime
197 else if(method_exists($item, "setDate"))
198 {
199 $item->setDate();
200 }
201 // duration
202 else if(method_exists($item, "setMonths"))
203 {
204 $item->setMonths(0);
205 $item->setDays(0);
206 $item->setHours(0);
207 $item->setMinutes(0);
208 $item->setSeconds(0);
209 }
210 }
211 }
212 }
213
219 function getValue()
220 {
221 $result = array();
222 foreach($this->items as $id => $obj)
223 {
224 if(method_exists($obj, "getValue"))
225 {
226 $result[$id] = $obj->getValue();
227 }
228 // datetime
229 else if(method_exists($obj, "setDate"))
230 {
231 $result[$id] = $obj->getDate();
232 }
233 }
234 return $result;
235 }
236
242 function setValueByArray($a_values)
243 {
244 foreach($this->items as $id => $obj)
245 {
246 $obj->setValueByArray($a_values);
247 }
248 }
249
255 function checkInput()
256 {
257 if(sizeof($this->items))
258 {
259 foreach($this->items as $id => $obj)
260 {
261 if(!$obj->checkInput())
262 {
263 return false;
264 }
265 }
266
267 if($this->comparison_mode)
268 {
269 $prev = NULL;
270 foreach($this->items as $id => $obj)
271 {
272 $value = $obj->getPostValueForComparison();
273 if($value != "")
274 {
275 if($prev !== NULL)
276 {
277 if($this->comparison_mode == self::COMPARISON_ASCENDING)
278 {
279 if($value < $prev)
280 {
281 return false;
282 }
283 }
284 else
285 {
286 if($value > $prev)
287 {
288 return false;
289 }
290 }
291 }
292 $prev = $value;
293 }
294 }
295 }
296 }
297
298 return $this->checkSubItemsInput();
299 }
300
306 function insert(&$a_tpl)
307 {
308 $html = $this->render();
309
310 $a_tpl->setCurrentBlock("prop_generic");
311 $a_tpl->setVariable("PROP_GENERIC", $html);
312 $a_tpl->parseCurrentBlock();
313 }
314
318 function render()
319 {
320 global $lng;
321
322 $tpl = new ilTemplate("tpl.prop_combination.html", true, true, "Services/Form");
323
324 if(sizeof($this->items))
325 {
326 foreach($this->items as $id => $obj)
327 {
328 // label
329 if(isset($this->labels[$id]))
330 {
331 $tpl->setCurrentBlock("prop_combination_label");
332 $tpl->setVariable("LABEL", $this->labels[$id]);
333 $tpl->parseCurrentBlock();
334 }
335
336 $tpl->setCurrentBlock("prop_combination");
337 $tpl->setVariable("FIELD", $obj->render());
338 $tpl->parseCurrentBlock();
339 }
340 }
341
342 return $tpl->get();
343 }
344
349 {
350 $html = $this->render();
351 return $html;
352 }
353}
$result
global $tpl
Definition: ilias.php:8
This class represents a number property in a property form.
checkInput()
Check input, strip slashes etc.
addCombinationItem($id, $item, $label="")
Add property item.
getCombinationItem($id)
Get property item.
setValueByArray($a_values)
Set value by array.
unserializeData($a_data)
unserialize data
removeCombinationItem($id)
Remove property item.
insert(&$a_tpl)
Insert property html.
setComparisonMode($mode)
Set mode for comparison (extended validation)
__call($method, $param)
Call item methods.
getTableFilterHTML()
Get HTML for table filter.
This class represents a property that may include a sub form.
special template class to simplify handling of ITX/PEAR
$html
Definition: example_001.php:87
$data
Interface for property form input GUI classes that can be used in table filters.
global $lng
Definition: privfeed.php:40