ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTDateSearchBridgeRange.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeRange.php";
4
6{
7 protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
8 {
9 return ($a_adt_def instanceof ilADTDateDefinition);
10 }
11
12
13 // table2gui / filter
14
15 public function loadFilter()
16 {
17 $value = $this->readFilter();
18 if($value !== null)
19 {
20 if($value["lower"])
21 {
22 $this->getLowerADT()->setDate(new ilDate($value["lower"], IL_CAL_DATE));
23 }
24 if($value["upper"])
25 {
26 $this->getUpperADT()->setDate(new ilDate($value["upper"], IL_CAL_DATE));
27 }
28 }
29 }
30
31
32 // form
33
34 public function addToForm()
35 {
36 global $lng;
37
38 if($this->getForm() instanceof ilPropertyFormGUI)
39 {
40 $check = new ilCustomInputGUI($this->getTitle());
41
42 $date_from = new ilDateTimeInputGUI($lng->txt('from'), $this->addToElementId("lower"));
43 $date_from->setShowTime(false);
44 $check->addSubItem($date_from);
45
46 if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
47 {
48 $date_from->setDate($this->getLowerADT()->getDate());
49 $checked = true;
50 }
51
52 $date_until = new ilDateTimeInputGUI($lng->txt('until'), $this->addToElementId("upper"));
53 $date_until->setShowTime(false);
54 $check->addSubItem($date_until);
55
56 if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
57 {
58 $date_until->setDate($this->getUpperADT()->getDate());
59 $checked = true;
60 }
61
62 $this->addToParentElement($check);
63 }
64 else
65 {
66 include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
67 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
68
69 $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
70
71 $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
72 $item->addCombinationItem("lower", $lower, $lng->txt("from"));
73
74 if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
75 {
76 $lower->setDate($this->getLowerADT()->getDate());
77 }
78
79 $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
80 $item->addCombinationItem("upper", $upper, $lng->txt("to"));
81
82 if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
83 {
84 $upper->setDate($this->getUpperADT()->getDate());
85 }
86
87 $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
88
89 $this->addToParentElement($item);
90 }
91 }
92
93 protected function shouldBeImportedFromPost($a_post)
94 {
95 if($this->getForm() instanceof ilPropertyFormGUI &&
96 !(bool)$this->text_input)
97 {
98 return (bool)$a_post["tgl"];
99 }
100 return parent::shouldBeImportedFromPost($a_post);
101 }
102
103 public function importFromPost(array $a_post = null)
104 {
105 $post = $this->extractPostValues($a_post);
106
107 if($post && $this->shouldBeImportedFromPost($post))
108 {
109 include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
111 $end = ilCalendarUtil::parseIncomingDate($post["upper"]);
112
113 if($start && $end && $start->get(IL_CAL_UNIX) > $end->get(IL_CAL_UNIX))
114 {
115 $tmp = $start;
116 $start = $end;
117 $end = $tmp;
118 }
119
120 if($this->getForm() instanceof ilPropertyFormGUI)
121 {
122 $item = $this->getForm()->getItemByPostVar($this->getElementId()."[lower]");
123 $item->setDate($start);
124
125 $item = $this->getForm()->getItemByPostVar($this->getElementId()."[upper]");
126 $item->setDate($end);
127 }
128 else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
129 {
130 $this->table_filter_fields[$this->getElementId()]->getCombinationItem("lower")->setDate($start);
131 $this->table_filter_fields[$this->getElementId()]->getCombinationItem("upper")->setDate($end);
132 $this->writeFilter(array(
133 "lower" => (!$start || $start->isNull()) ? null: $start->get(IL_CAL_DATE),
134 "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATE)
135 ));
136 }
137
138 $this->getLowerADT()->setDate($start);
139 $this->getUpperADT()->setDate($end);
140 }
141 else
142 {
143 $this->getLowerADT()->setDate();
144 $this->getUpperADT()->setDate();
145 }
146 }
147
148
149 // db
150
151 public function getSQLCondition($a_element_id)
152 {
153 global $ilDB;
154
155 if(!$this->isNull() && $this->isValid())
156 {
157 $sql = array();
158 if(!$this->getLowerADT()->isNull())
159 {
160 $sql[] = $a_element_id." >= ".$ilDB->quote($this->getLowerADT()->getDate()->get(IL_CAL_DATE), "date");
161 }
162 if(!$this->getUpperADT()->isNull())
163 {
164 $sql[] = $a_element_id." <= ".$ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATE), "date");
165 }
166 return "(".implode(" AND ", $sql).")";
167 }
168 }
169
170 public function isInCondition(ilADT $a_adt)
171 {
172 assert($a_adt instanceof ilADTDate);
173
174 if(!$this->getLowerADT()->isNull() && !$this->getUpperADT()->isNull())
175 {
176 return $a_adt->isInbetweenOrEqual($this->getLowerADT(), $this->getUpperADT());
177 }
178 else if(!$this->getLowerADT()->isNull())
179 {
180 return $a_adt->isLargerOrEqual($this->getLowerADT());
181 }
182 else
183 {
184 return $a_adt->isSmallerOrEqual($this->getUpperADT());
185 }
186 }
187
188
189 // import/export
190
191 public function getSerializedValue()
192 {
193 if(!$this->isNull() && $this->isValid())
194 {
195 $res = array();
196 if(!$this->getLowerADT()->isNull())
197 {
198 $res["lower"] = $this->getLowerADT()->getDate()->get(IL_CAL_DATE);
199 }
200 if(!$this->getUpperADT()->isNull())
201 {
202 $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATE);
203 }
204 return serialize($res);
205 }
206 }
207
208 public function setSerializedValue($a_value)
209 {
210 $a_value = unserialize($a_value);
211 if(is_array($a_value))
212 {
213 if(isset($a_value["lower"]))
214 {
215 $this->getLowerADT()->setDate(new ilDate($a_value["lower"], IL_CAL_DATE));
216 }
217 if(isset($a_value["upper"]))
218 {
219 $this->getUpperADT()->setDate(new ilDate($a_value["upper"], IL_CAL_DATE));
220 }
221 }
222 }
223}
224
225?>
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
addToForm()
Add ADT-specific fields to form.
loadFilter()
Load filter value(s) into ADT.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
isInCondition(ilADT $a_adt)
Compare directly against ADT.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
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)
ADT base class.
Definition: class.ilADT.php:12
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)
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
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.
Class for single dates.
This class represents a property form user interface.
global $lng
Definition: privfeed.php:17
global $ilDB