ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTDateTimeSearchBridgeRange.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 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  {
20  if($value["lower"])
21  {
22  $this->getLowerADT()->setDate(new ilDateTime($value["lower"], IL_CAL_DATETIME));
23  }
24  if($value["upper"])
25  {
26  $this->getUpperADT()->setDate(new ilDateTime($value["upper"], IL_CAL_DATETIME));
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  // :TODO: use DateDurationInputGUI ?!
41 
42  $check = new ilCustomInputGUI($this->getTitle());
43 
44  $date_from = new ilDateTimeInputGUI($lng->txt('from'), $this->addToElementId("lower"));
45  $date_from->setShowTime(true);
46  $check->addSubItem($date_from);
47 
48  if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
49  {
50  $date_from->setDate($this->getLowerADT()->getDate());
51  $checked = true;
52  }
53 
54  $date_until = new ilDateTimeInputGUI($lng->txt('until'), $this->addToElementId("upper"));
55  $date_until->setShowTime(true);
56  $check->addSubItem($date_until);
57 
58  if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
59  {
60  $date_until->setDate($this->getUpperADT()->getDate());
61  $checked = true;
62  }
63 
64  $this->addToParentElement($check);
65  }
66  else
67  {
68  // see ilTable2GUI::addFilterItemByMetaType()
69  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
70  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
71  $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
72 
73  $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
74  $lower->setShowTime(true);
75  $item->addCombinationItem("lower", $lower, $lng->txt("from"));
76 
77  if($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull())
78  {
79  $lower->setDate($this->getLowerADT()->getDate());
80  }
81 
82  $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
83  $upper->setShowTime(true);
84  $item->addCombinationItem("upper", $upper, $lng->txt("to"));
85 
86  if($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull())
87  {
88  $upper->setDate($this->getUpperADT()->getDate());
89  }
90 
91  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
92 
93  $this->addToParentElement($item);
94  }
95  }
96 
97  protected function shouldBeImportedFromPost($a_post)
98  {
99  if($this->getForm() instanceof ilPropertyFormGUI &&
100  !(bool)$this->text_input)
101  {
102  return (bool)$a_post["tgl"];
103  }
104  return parent::shouldBeImportedFromPost($a_post);
105  }
106 
107  public function importFromPost(array $a_post = null)
108  {
109  $post = $this->extractPostValues($a_post);
110 
111  if($post && $this->shouldBeImportedFromPost($post))
112  {
113  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
114  $start = ilCalendarUtil::parseIncomingDate($post["lower"], 1);
115  $end = ilCalendarUtil::parseIncomingDate($post["upper"], 1);
116 
117  if($start && $end && $start->get(IL_CAL_UNIX) > $end->get(IL_CAL_UNIX))
118  {
119  $tmp = $start;
120  $start = $end;
121  $end = $tmp;
122  }
123 
124  if($this->getForm() instanceof ilPropertyFormGUI)
125  {
126  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[lower]");
127  $item->setDate($start);
128 
129  $item = $this->getForm()->getItemByPostVar($this->getElementId()."[upper]");
130  $item->setDate($end);
131  }
132  else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
133  {
134  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("lower")->setDate($start);
135  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("upper")->setDate($end);
136  $this->writeFilter(array(
137  "lower" => (!$start || $start->isNull()) ? null: $start->get(IL_CAL_DATETIME),
138  "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATETIME)
139  ));
140  }
141 
142  $this->getLowerADT()->setDate($start);
143  $this->getUpperADT()->setDate($end);
144  }
145  else
146  {
147  $this->getLowerADT()->setDate();
148  $this->getUpperADT()->setDate();
149  }
150  }
151 
152 
153  // db
154 
155  public function getSQLCondition($a_element_id)
156  {
157  global $ilDB;
158 
159  if(!$this->isNull() && $this->isValid())
160  {
161  $sql = array();
162  if(!$this->getLowerADT()->isNull())
163  {
164  $sql[] = $a_element_id." >= ".$ilDB->quote($this->getLowerADT()->getDate()->get(IL_CAL_DATETIME), "timestamp");
165  }
166  if(!$this->getUpperADT()->isNull())
167  {
168  $sql[] = $a_element_id." <= ".$ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATETIME), "timestamp");
169  }
170  return "(".implode(" AND ", $sql).")";
171  }
172  }
173 
174  public function isInCondition(ilADT $a_adt)
175  {
176  assert($a_adt instanceof ilADTDateTime);
177 
178  if(!$this->getLowerADT()->isNull() && !$this->getUpperADT()->isNull())
179  {
180  return $a_adt->isInbetweenOrEqual($this->getLowerADT(), $this->getUpperADT());
181  }
182  else if(!$this->getLowerADT()->isNull())
183  {
184  return $a_adt->isLargerOrEqual($this->getLowerADT());
185  }
186  else
187  {
188  return $a_adt->isSmallerOrEqual($this->getUpperADT());
189  }
190  }
191 
192 
193  // import/export
194 
195  public function getSerializedValue()
196  {
197  if(!$this->isNull() && $this->isValid())
198  {
199  $res = array();
200  if(!$this->getLowerADT()->isNull())
201  {
202  $res["lower"] = $this->getLowerADT()->getDate()->get(IL_CAL_DATETIME);
203  }
204  if(!$this->getUpperADT()->isNull())
205  {
206  $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATETIME);
207  }
208  return serialize($res);
209  }
210  }
211 
212  public function setSerializedValue($a_value)
213  {
214  $a_value = unserialize($a_value);
215  if(is_array($a_value))
216  {
217  if(isset($a_value["lower"]))
218  {
219  $this->getLowerADT()->setDate(new ilDateTime($a_value["lower"], IL_CAL_DATETIME));
220  }
221  if(isset($a_value["upper"]))
222  {
223  $this->getUpperADT()->setDate(new ilDateTime($a_value["upper"], IL_CAL_DATETIME));
224  }
225  }
226  }
227 }
228 
229 ?>
const IL_CAL_DATETIME
This class represents a property form user interface.
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)
isSmallerOrEqual(ilADT $a_adt)
Check if given ADT is smaller or equal than self.
const IL_CAL_UNIX
ADT base class.
Definition: class.ilADT.php:11
extractPostValues(array $a_post=null)
Extract data from (post) values.
This class represents a date/time property in a property form.
readFilter()
Load value(s) from filter store (in session)
Date and time handling
Create styles array
The data for the language used.
This class represents a number property in a property form.
This class represents a custom property in a property form.
global $lng
Definition: privfeed.php:17
writeFilter($a_value=null)
Write value(s) to filter store (in session)
global $ilDB
ADT definition base class.
getElementId()
Get element id.
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
setShowTime($a_showtime)
Set Show Time Information.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
addToElementId($a_add)
Add sub-element.