ILIAS  release_7 Revision v7.30-3-g800a261c036
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 function isValidADTDefinition(ilADTDefinition $a_adt_def)
8 {
9 return ($a_adt_def instanceof ilADTDateTimeDefinition);
10 }
11
12
13 // table2gui / filter
14
15 public function loadFilter()
16 {
17 $value = $this->readFilter();
18 if ($value !== null) {
19 if ($value["lower"]) {
20 $this->getLowerADT()->setDate(new ilDateTime($value["lower"], IL_CAL_DATETIME));
21 }
22 if ($value["upper"]) {
23 $this->getUpperADT()->setDate(new ilDateTime($value["upper"], IL_CAL_DATETIME));
24 }
25 }
26 }
27
28
29 // form
30
31 public function addToForm()
32 {
33 global $DIC;
34
35 $lng = $DIC['lng'];
36
37 if ($this->getForm() instanceof ilPropertyFormGUI) {
38 // :TODO: use DateDurationInputGUI ?!
39
40 $check = new ilCustomInputGUI($this->getTitle());
41
42 $date_from = new ilDateTimeInputGUI($lng->txt('from'), $this->addToElementId("lower"));
43 $date_from->setShowTime(true);
44 $check->addSubItem($date_from);
45
46 if ($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull()) {
47 $date_from->setDate($this->getLowerADT()->getDate());
48 $checked = true;
49 }
50
51 $date_until = new ilDateTimeInputGUI($lng->txt('until'), $this->addToElementId("upper"));
52 $date_until->setShowTime(true);
53 $check->addSubItem($date_until);
54
55 if ($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull()) {
56 $date_until->setDate($this->getUpperADT()->getDate());
57 $checked = true;
58 }
59
60 $this->addToParentElement($check);
61 } else {
62 // see ilTable2GUI::addFilterItemByMetaType()
63 include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
64 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
65 $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
66
67 $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
68 $lower->setShowTime(true);
69 $item->addCombinationItem("lower", $lower, $lng->txt("from"));
70
71 if ($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull()) {
72 $lower->setDate($this->getLowerADT()->getDate());
73 }
74
75 $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
76 $upper->setShowTime(true);
77 $item->addCombinationItem("upper", $upper, $lng->txt("to"));
78
79 if ($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull()) {
80 $upper->setDate($this->getUpperADT()->getDate());
81 }
82
83 $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
84
85 $this->addToParentElement($item);
86 }
87 }
88
89 protected function shouldBeImportedFromPost($a_post)
90 {
91 if ($this->getForm() instanceof ilPropertyFormGUI &&
92 !(bool) $this->text_input) {
93 return (bool) $a_post["tgl"];
94 }
95 return parent::shouldBeImportedFromPost($a_post);
96 }
97
98 public function importFromPost(array $a_post = null)
99 {
100 $post = $this->extractPostValues($a_post);
101
102 if ($post && $this->shouldBeImportedFromPost($post)) {
103 include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
104 $start = ilCalendarUtil::parseIncomingDate($post["lower"], 1);
105 $end = ilCalendarUtil::parseIncomingDate($post["upper"], 1);
106
107 if ($start && $end && $start->get(IL_CAL_UNIX) > $end->get(IL_CAL_UNIX)) {
108 $tmp = $start;
109 $start = $end;
110 $end = $tmp;
111 }
112
113 if ($this->getForm() instanceof ilPropertyFormGUI) {
114 $item = $this->getForm()->getItemByPostVar($this->getElementId() . "[lower]");
115 $item->setDate($start);
116
117 $item = $this->getForm()->getItemByPostVar($this->getElementId() . "[upper]");
118 $item->setDate($end);
119 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
120 $this->table_filter_fields[$this->getElementId()]->getCombinationItem("lower")->setDate($start);
121 $this->table_filter_fields[$this->getElementId()]->getCombinationItem("upper")->setDate($end);
122 $this->writeFilter(array(
123 "lower" => (!$start || $start->isNull()) ? null: $start->get(IL_CAL_DATETIME),
124 "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATETIME)
125 ));
126 }
127
128 $this->getLowerADT()->setDate($start);
129 $this->getUpperADT()->setDate($end);
130 } else {
131 $this->getLowerADT()->setDate();
132 $this->getUpperADT()->setDate();
133 }
134 }
135
136
137 // db
138
139 public function getSQLCondition($a_element_id)
140 {
141 global $DIC;
142
143 $ilDB = $DIC['ilDB'];
144
145 if (!$this->isNull() && $this->isValid()) {
146 $sql = array();
147 if (!$this->getLowerADT()->isNull()) {
148 $sql[] = $a_element_id . " >= " . $ilDB->quote($this->getLowerADT()->getDate()->get(IL_CAL_DATETIME), "timestamp");
149 }
150 if (!$this->getUpperADT()->isNull()) {
151 $sql[] = $a_element_id . " <= " . $ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATETIME), "timestamp");
152 }
153 return "(" . implode(" AND ", $sql) . ")";
154 }
155 }
156
157 public function isInCondition(ilADT $a_adt)
158 {
159 assert($a_adt instanceof ilADTDateTime);
160
161 if (!$this->getLowerADT()->isNull() && !$this->getUpperADT()->isNull()) {
162 return $a_adt->isInbetweenOrEqual($this->getLowerADT(), $this->getUpperADT());
163 } elseif (!$this->getLowerADT()->isNull()) {
164 return $a_adt->isLargerOrEqual($this->getLowerADT());
165 } else {
166 return $a_adt->isSmallerOrEqual($this->getUpperADT());
167 }
168 }
169
170
171 // import/export
172
173 public function getSerializedValue()
174 {
175 if (!$this->isNull() && $this->isValid()) {
176 $res = array();
177 if (!$this->getLowerADT()->isNull()) {
178 $res["lower"] = $this->getLowerADT()->getDate()->get(IL_CAL_DATETIME);
179 }
180 if (!$this->getUpperADT()->isNull()) {
181 $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATETIME);
182 }
183 return serialize($res);
184 }
185 }
186
187 public function setSerializedValue($a_value)
188 {
189 $a_value = unserialize($a_value);
190 if (is_array($a_value)) {
191 if (isset($a_value["lower"])) {
192 $this->getLowerADT()->setDate(new ilDateTime($a_value["lower"], IL_CAL_DATETIME));
193 }
194 if (isset($a_value["upper"])) {
195 $this->getUpperADT()->setDate(new ilDateTime($a_value["upper"], IL_CAL_DATETIME));
196 }
197 }
198 }
199}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
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)
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
isInCondition(ilADT $a_adt)
Compare directly against ADT.
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)
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.
@classDescription Date and time handling
This class represents a property form user interface.
global $DIC
Definition: goto.php:24
$lng
foreach($_POST as $key=> $value) $res
global $ilDB