ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
36  protected $lng;
37 
38 
42  public function __construct($a_title = "", $a_postvar = "")
43  {
44  parent::__construct($a_title, $a_postvar);
45  global $DIC;
46 
47  $this->lng = $DIC->language();
48  }
49 
50  protected $items = array();
51  protected $labels;
52  protected $comparison;
53 
56 
64  public function addCombinationItem($id, $item, $label = "")
65  {
66  $this->items[$id] = $item;
67  if ($label) {
68  $this->labels[$id] = $label;
69  }
70  }
71 
78  public function getCombinationItem($id)
79  {
80  if (isset($this->items[$id])) {
81  return $this->items[$id];
82  }
83  }
84 
90  public function removeCombinationItem($id)
91  {
92  if (isset($this->items[$id])) {
93  unset($this->items[$id]);
94  }
95  }
96 
103  public function __call($method, $param)
104  {
105  $result = array();
106  foreach ($this->items as $id => $obj) {
107  if (method_exists($obj, $method)) {
108  $result[$id] = call_user_func_array(array($obj, $method), $param);
109  }
110  }
111  return $result;
112  }
113 
117  public function serializeData()
118  {
119  $result = array();
120  foreach ($this->items as $id => $obj) {
121  $result[$id] = $obj->serializeData();
122  }
123  return serialize($result);
124  }
125 
129  public function unserializeData($a_data)
130  {
131  $data = unserialize($a_data);
132 
133  if ($data) {
134  foreach ($this->items as $id => $obj) {
135  $obj->unserializeData($data[$id]);
136  }
137  } else {
138  foreach ($this->items as $id => $obj) {
139  if (method_exists($obj, "setValue")) {
140  $this->setValue(false);
141  }
142  }
143  }
144  }
145 
152  public function setComparisonMode($mode)
153  {
154  if (in_array($mode, array(self::COMPARISON_ASCENDING, self::COMPARISON_DESCENDING))) {
155  foreach ($this->items as $obj) {
156  if (!method_exists($obj, "getPostValueForComparison")) {
157  return false;
158  }
159  }
160  $this->comparison_mode = $mode;
161  return true;
162  }
163  }
164 
170  public function setValue($a_value)
171  {
172  if (is_array($a_value)) {
173  foreach ($a_value as $id => $value) {
174  if (isset($this->items[$id])) {
175  if (method_exists($this->items[$id], "setValue")) {
176  $this->items[$id]->setValue($value);
177  }
178  // datetime
179  elseif (method_exists($this->items[$id], "setDate")) {
180  $this->items[$id]->setDate($value);
181  }
182  }
183  }
184  } elseif ($a_value === null) {
185  foreach ($this->items as $item) {
186  if (method_exists($item, "setValue")) {
187  $item->setValue(null);
188  }
189  // datetime
190  elseif (method_exists($item, "setDate")) {
191  $item->setDate();
192  }
193  // duration
194  elseif (method_exists($item, "setMonths")) {
195  $item->setMonths(0);
196  $item->setDays(0);
197  $item->setHours(0);
198  $item->setMinutes(0);
199  $item->setSeconds(0);
200  }
201  }
202  }
203  }
204 
210  public function getValue()
211  {
212  $result = array();
213  foreach ($this->items as $id => $obj) {
214  if (method_exists($obj, "getValue")) {
215  $result[$id] = $obj->getValue();
216  }
217  // datetime
218  elseif (method_exists($obj, "setDate")) {
219  $result[$id] = $obj->getDate();
220  }
221  }
222  return $result;
223  }
224 
230  public function setValueByArray($a_values)
231  {
232  foreach ($this->items as $id => $obj) {
233  $obj->setValueByArray($a_values);
234  }
235  }
236 
242  public function checkInput()
243  {
244  if (sizeof($this->items)) {
245  foreach ($this->items as $id => $obj) {
246  if (!$obj->checkInput()) {
247  return false;
248  }
249  }
250 
251  if ($this->comparison_mode) {
252  $prev = null;
253  foreach ($this->items as $id => $obj) {
254  $value = $obj->getPostValueForComparison();
255  if ($value != "") {
256  if ($prev !== null) {
257  if ($this->comparison_mode == self::COMPARISON_ASCENDING) {
258  if ($value < $prev) {
259  return false;
260  }
261  } else {
262  if ($value > $prev) {
263  return false;
264  }
265  }
266  }
267  $prev = $value;
268  }
269  }
270  }
271  }
272 
273  return $this->checkSubItemsInput();
274  }
275 
281  public function insert($a_tpl)
282  {
283  $html = $this->render();
284 
285  $a_tpl->setCurrentBlock("prop_generic");
286  $a_tpl->setVariable("PROP_GENERIC", $html);
287  $a_tpl->parseCurrentBlock();
288  }
289 
293  public function render()
294  {
295  $lng = $this->lng;
296 
297  $tpl = new ilTemplate("tpl.prop_combination.html", true, true, "Services/Form");
298 
299  if (sizeof($this->items)) {
300  foreach ($this->items as $id => $obj) {
301  // label
302  if (isset($this->labels[$id])) {
303  $tpl->setCurrentBlock("prop_combination_label");
304  $tpl->setVariable("LABEL", $this->labels[$id]);
305  $tpl->parseCurrentBlock();
306  }
307 
308  $tpl->setCurrentBlock("prop_combination");
309  $tpl->setVariable("FIELD", $obj->render());
310  $tpl->parseCurrentBlock();
311  }
312  }
313 
314  return $tpl->get();
315  }
316 
320  public function getTableFilterHTML()
321  {
322  $html = $this->render();
323  return $html;
324  }
325 }
addCombinationItem($id, $item, $label="")
Add property item.
checkInput()
Check input, strip slashes etc.
Interface for property form input GUI classes that can be used in table filters.
$result
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getCombinationItem($id)
Get property item.
if(!array_key_exists('StateId', $_REQUEST)) $id
__construct($a_title="", $a_postvar="")
Constructor.
insert($a_tpl)
Insert property html.
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
removeCombinationItem($id)
Remove property item.
This class represents a number property in a property form.
This class represents a property that may include a sub form.
unserializeData($a_data)
unserialize data
setValueByArray($a_values)
Set value by array.
getTableFilterHTML()
Get HTML for table filter.
$html
Definition: example_001.php:87
setComparisonMode($mode)
Set mode for comparison (extended validation)
__call($method, $param)
Call item methods.