ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilADTDateSearchBridgeRange.php
Go to the documentation of this file.
1 <?php
2 
3 require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeRange.php";
4 
6 {
7  protected $text_input; // [bool]
8 
9  protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
10  {
11  return ($a_adt_def instanceof ilADTDateDefinition);
12  }
13 
14  public function setTextInputMode($a_value)
15  {
16  $this->text_input = (bool)$a_value;
17  }
18 
19 
20  // table2gui / filter
21 
22  public function loadFilter()
23  {
24  $value = $this->readFilter();
25  if($value !== null)
26  {
27  if($value["lower"])
28  {
29  $this->getLowerADT()->setDate(new ilDate($value["lower"], IL_CAL_DATE));
30  }
31  if($value["upper"])
32  {
33  $this->getUpperADT()->setDate(new ilDate($value["upper"], IL_CAL_DATE));
34  }
35  }
36  }
37 
38 
39  // form
40 
41  public function addToForm()
42  {
43  global $lng;
44 
45  if($this->getForm() instanceof ilPropertyFormGUI)
46  {
47  // :TODO: use DateDurationInputGUI ?!
48 
49  if(!(bool)$this->text_input)
50  {
51  $check = new ilCheckboxInputGUI($this->getTitle(), $this->addToElementId("tgl"));
52  $check->setValue(1);
53  $checked = false;
54  }
55  else
56  {
57  $check = new ilCustomInputGUI($this->getTitle());
58  }
59 
60  $date_from = new ilDateTimeInputGUI($lng->txt('from'), $this->addToElementId("lower"));
61  $date_from->setShowTime(false);
62  $check->addSubItem($date_from);
63 
64  if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
65  {
66  $date_from->setDate($this->getLowerADT()->getDate());
67  $checked = true;
68  }
69 
70  $date_until = new ilDateTimeInputGUI($lng->txt('until'), $this->addToElementId("upper"));
71  $date_until->setShowTime(false);
72  $check->addSubItem($date_until);
73 
74  if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
75  {
76  $date_until->setDate($this->getUpperADT()->getDate());
77  $checked = true;
78  }
79 
80  if(!(bool)$this->text_input)
81  {
82  $check->setChecked($checked);
83  }
84  else
85  {
86  $date_from->setMode(ilDateTimeInputGUI::MODE_INPUT);
87  $date_until->setMode(ilDateTimeInputGUI::MODE_INPUT);
88  }
89 
90  $this->addToParentElement($check);
91  }
92  else
93  {
94  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
95  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
96 
97  $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
98 
99  $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
100  $item->addCombinationItem("lower", $lower, $lng->txt("from"));
101 
102  if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
103  {
104  $lower->setDate($this->getLowerADT()->getDate());
105  }
106 
107  $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
108  $item->addCombinationItem("upper", $upper, $lng->txt("to"));
109 
110  if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
111  {
112  $upper->setDate($this->getUpperADT()->getDate());
113  }
114 
115  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
116  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
117 
118  $this->addToParentElement($item);
119  }
120  }
121 
122  protected function shouldBeImportedFromPost(array $a_post)
123  {
124  if($this->getForm() instanceof ilPropertyFormGUI &&
125  !(bool)$this->text_input)
126  {
127  return (bool)$a_post["tgl"];
128  }
129  return parent::shouldBeImportedFromPost($a_post);
130  }
131 
132  public function importFromPost(array $a_post = null)
133  {
134  $post = $this->extractPostValues($a_post);
135 
136  if($post && $this->shouldBeImportedFromPost($post))
137  {
138  $start = $end = null;
139 
140  include_once "Services/ADT/classes/class.ilADTDateSearchUtil.php";
141 
142  if(!$this->getForm() instanceof ilPropertyFormGUI ||
143  (bool)$this->text_input)
144  {
147  }
148  else
149  {
150  // if checkInput() is called before, this will not work
151 
154  }
155 
156  if($start && $end && $start > $end)
157  {
158  $tmp = $start;
159  $start = $end;
160  $end = $tmp;
161  }
162 
163  // :TODO: all dates are imported as valid
164 
165  if($start)
166  {
167  $start = new ilDate($start, IL_CAL_UNIX);
168  }
169  if($end)
170  {
171  $end = new ilDate($end, IL_CAL_UNIX);
172  }
173 
174  if($this->getForm() instanceof ilPropertyFormGUI)
175  {
176  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[lower]");
177  $item->setDate($start);
178 
179  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[upper]");
180  $item->setDate($end);
181 
182  if(!(bool)$this->text_input)
183  {
184  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[tgl]");
185  $item->setChecked(true);
186  }
187  }
188  else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
189  {
190  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("lower")->setDate($start);
191  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("upper")->setDate($end);
192  $this->writeFilter(array(
193  "lower" => (!$start || $start->isNull()) ? null: $start->get(IL_CAL_DATE),
194  "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATE)
195  ));
196  }
197 
198  $this->getLowerADT()->setDate($start);
199  $this->getUpperADT()->setDate($end);
200  }
201  else
202  {
203  if($this->getForm() instanceof ilPropertyFormGUI &&
204  !(bool)$this->text_input)
205  {
206  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[tgl]");
207  $item->setChecked(false);
208  }
209 
210  $this->getLowerADT()->setDate();
211  $this->getUpperADT()->setDate();
212  }
213  }
214 
215 
216  // db
217 
218  public function getSQLCondition($a_element_id)
219  {
220  global $ilDB;
221 
222  if(!$this->isNull() && $this->isValid())
223  {
224  $sql = array();
225  if(!$this->getLowerADT()->isNull())
226  {
227  $sql[] = $a_element_id." >= ".$ilDB->quote($this->getLowerADT()->getDate()->get(IL_CAL_DATE), "date");
228  }
229  if(!$this->getUpperADT()->isNull())
230  {
231  $sql[] = $a_element_id." <= ".$ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATE), "date");
232  }
233  return "(".implode(" AND ", $sql).")";
234  }
235  }
236 
237  public function isInCondition(ilADTDate $a_adt)
238  {
239  if(!$this->getLowerADT()->isNull() && !$this->getUpperADT()->isNull())
240  {
241  return $a_adt->isInbetweenOrEqual($this->getLowerADT(), $this->getUpperADT());
242  }
243  else if(!$this->getLowerADT()->isNull())
244  {
245  return $a_adt->isLargerOrEqual($this->getLowerADT());
246  }
247  else
248  {
249  return $a_adt->isSmallerOrEqual($this->getUpperADT());
250  }
251  }
252 
253 
254  // import/export
255 
256  public function getSerializedValue()
257  {
258  if(!$this->isNull() && $this->isValid())
259  {
260  $res = array();
261  if(!$this->getLowerADT()->isNull())
262  {
263  $res["lower"] = $this->getLowerADT()->getDate()->get(IL_CAL_DATE);
264  }
265  if(!$this->getUpperADT()->isNull())
266  {
267  $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATE);
268  }
269  return serialize($res);
270  }
271  }
272 
273  public function setSerializedValue($a_value)
274  {
275  $a_value = unserialize($a_value);
276  if(is_array($a_value))
277  {
278  if(isset($a_value["lower"]))
279  {
280  $this->getLowerADT()->setDate(new ilDate($a_value["lower"], IL_CAL_DATE));
281  }
282  if(isset($a_value["upper"]))
283  {
284  $this->getUpperADT()->setDate(new ilDate($a_value["upper"], IL_CAL_DATE));
285  }
286  }
287  }
288 }
289 
290 ?>