ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilADTDateTimeSearchBridgeRange.php
Go to the documentation of this file.
1<?php
2
3require_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 ilADTDateTimeDefinition);
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 ilDateTime($value["lower"], IL_CAL_DATETIME));
30 }
31 if($value["upper"])
32 {
33 $this->getUpperADT()->setDate(new ilDateTime($value["upper"], IL_CAL_DATETIME));
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(true);
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(true);
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 // see ilTable2GUI::addFilterItemByMetaType()
95 include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
96 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
97 $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
98
99 $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
100 $lower->setShowTime(true);
101 $item->addCombinationItem("lower", $lower, $lng->txt("from"));
102
103 if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
104 {
105 $lower->setDate($this->getLowerADT()->getDate());
106 }
107
108 $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
109 $upper->setShowTime(true);
110 $item->addCombinationItem("upper", $upper, $lng->txt("to"));
111
112 if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
113 {
114 $upper->setDate($this->getUpperADT()->getDate());
115 }
116
117 $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
118 $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
119
120 $this->addToParentElement($item);
121 }
122 }
123
124 protected function shouldBeImportedFromPost(array $a_post)
125 {
126 if($this->getForm() instanceof ilPropertyFormGUI &&
127 !(bool)$this->text_input)
128 {
129 return (bool)$a_post["tgl"];
130 }
131 return parent::shouldBeImportedFromPost($a_post);
132 }
133
134 public function importFromPost(array $a_post = null)
135 {
136 $post = $this->extractPostValues($a_post);
137
138 if($post && $this->shouldBeImportedFromPost($post))
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 ilDateTime($start, IL_CAL_UNIX);
168 }
169 if($end)
170 {
171 $end = new ilDateTime($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_DATETIME),
194 "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATETIME)
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_DATETIME), "timestamp");
228 }
229 if(!$this->getUpperADT()->isNull())
230 {
231 $sql[] = $a_element_id." <= ".$ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATETIME), "timestamp");
232 }
233 return "(".implode(" AND ", $sql).")";
234 }
235 }
236
237 public function isInCondition(ilADTDateTime $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_DATETIME);
264 }
265 if(!$this->getUpperADT()->isNull())
266 {
267 $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATETIME);
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 ilDateTime($a_value["lower"], IL_CAL_DATETIME));
281 }
282 if(isset($a_value["upper"]))
283 {
284 $this->getUpperADT()->setDate(new ilDateTime($a_value["upper"], IL_CAL_DATETIME));
285 }
286 }
287 }
288}
289
290?>
const IL_CAL_UNIX
const IL_CAL_DATETIME
static handleTextInputPost($a_mode, $a_post)
Import text input post data.
static handleSelectInputPost($a_mode, $a_post)
Import select post data.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
ADT definition base class.
readFilter()
Load value(s) from filter store (in session)
extractPostValues(array $a_post=null)
Extract data from (post) values.
addToElementId($a_add)
Add sub-element.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
getElementId()
Get element id.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
isSmallerOrEqual(ilADT $a_adt)
Check if given ADT is smaller or equal than self.
isLargerOrEqual(ilADT $a_adt)
Check if given ADT is larger or equal than self.
isInbetweenOrEqual(ilADT $a_adt_from, ilADT $a_adt_to)
Check if self is inbetween given ADTs (inclusive)
This class represents a checkbox property in a property form.
This class represents a number property in a property form.
This class represents a custom property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a property form user interface.
global $lng
Definition: privfeed.php:40
global $ilDB