ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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  if ($value["lower"]) {
20  $this->getLowerADT()->setDate(new ilDate($value["lower"], IL_CAL_DATE));
21  }
22  if ($value["upper"]) {
23  $this->getUpperADT()->setDate(new ilDate($value["upper"], IL_CAL_DATE));
24  }
25  }
26  }
27 
28 
29  // form
30 
31  public function addToForm()
32  {
33  global $lng;
34 
35  if ($this->getForm() instanceof ilPropertyFormGUI) {
36  $check = new ilCustomInputGUI($this->getTitle());
37 
38  $date_from = new ilDateTimeInputGUI($lng->txt('from'), $this->addToElementId("lower"));
39  $date_from->setShowTime(false);
40  $check->addSubItem($date_from);
41 
42  if ($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull()) {
43  $date_from->setDate($this->getLowerADT()->getDate());
44  $checked = true;
45  }
46 
47  $date_until = new ilDateTimeInputGUI($lng->txt('until'), $this->addToElementId("upper"));
48  $date_until->setShowTime(false);
49  $check->addSubItem($date_until);
50 
51  if ($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull()) {
52  $date_until->setDate($this->getUpperADT()->getDate());
53  $checked = true;
54  }
55 
56  $this->addToParentElement($check);
57  } else {
58  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
59  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
60 
61  $item = new ilCombinationInputGUI($this->getTitle(), $this->getElementId());
62 
63  $lower = new ilDateTimeInputGUI("", $this->addToElementId("lower"));
64  $item->addCombinationItem("lower", $lower, $lng->txt("from"));
65 
66  if ($this->getLowerADT()->getDate() && !$this->getLowerADT()->isNull()) {
67  $lower->setDate($this->getLowerADT()->getDate());
68  }
69 
70  $upper = new ilDateTimeInputGUI("", $this->addToElementId("upper"));
71  $item->addCombinationItem("upper", $upper, $lng->txt("to"));
72 
73  if ($this->getUpperADT()->getDate() && !$this->getUpperADT()->isNull()) {
74  $upper->setDate($this->getUpperADT()->getDate());
75  }
76 
77  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
78 
79  $this->addToParentElement($item);
80  }
81  }
82 
83  protected function shouldBeImportedFromPost($a_post)
84  {
85  if ($this->getForm() instanceof ilPropertyFormGUI &&
86  !(bool) $this->text_input) {
87  return (bool) $a_post["tgl"];
88  }
89  return parent::shouldBeImportedFromPost($a_post);
90  }
91 
92  public function importFromPost(array $a_post = null)
93  {
94  $post = $this->extractPostValues($a_post);
95 
96  if ($post && $this->shouldBeImportedFromPost($post)) {
97  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
98  $start = ilCalendarUtil::parseIncomingDate($post["lower"]);
100 
101  if ($start && $end && $start->get(IL_CAL_UNIX) > $end->get(IL_CAL_UNIX)) {
102  $tmp = $start;
103  $start = $end;
104  $end = $tmp;
105  }
106 
107  if ($this->getForm() instanceof ilPropertyFormGUI) {
108  $item = $this->getForm()->getItemByPostVar($this->getElementId() . "[lower]");
109  $item->setDate($start);
110 
111  $item = $this->getForm()->getItemByPostVar($this->getElementId() . "[upper]");
112  $item->setDate($end);
113  } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
114  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("lower")->setDate($start);
115  $this->table_filter_fields[$this->getElementId()]->getCombinationItem("upper")->setDate($end);
116  $this->writeFilter(array(
117  "lower" => (!$start || $start->isNull()) ? null: $start->get(IL_CAL_DATE),
118  "upper" => (!$end || $end->isNull()) ? null : $end->get(IL_CAL_DATE)
119  ));
120  }
121 
122  $this->getLowerADT()->setDate($start);
123  $this->getUpperADT()->setDate($end);
124  } else {
125  $this->getLowerADT()->setDate();
126  $this->getUpperADT()->setDate();
127  }
128  }
129 
130 
131  // db
132 
133  public function getSQLCondition($a_element_id)
134  {
135  global $ilDB;
136 
137  if (!$this->isNull() && $this->isValid()) {
138  $sql = array();
139  if (!$this->getLowerADT()->isNull()) {
140  $sql[] = $a_element_id . " >= " . $ilDB->quote($this->getLowerADT()->getDate()->get(IL_CAL_DATE), "date");
141  }
142  if (!$this->getUpperADT()->isNull()) {
143  $sql[] = $a_element_id . " <= " . $ilDB->quote($this->getUpperADT()->getDate()->get(IL_CAL_DATE), "date");
144  }
145  return "(" . implode(" AND ", $sql) . ")";
146  }
147  }
148 
149  public function isInCondition(ilADT $a_adt)
150  {
151  assert($a_adt instanceof ilADTDate);
152 
153  if (!$this->getLowerADT()->isNull() && !$this->getUpperADT()->isNull()) {
154  return $a_adt->isInbetweenOrEqual($this->getLowerADT(), $this->getUpperADT());
155  } elseif (!$this->getLowerADT()->isNull()) {
156  return $a_adt->isLargerOrEqual($this->getLowerADT());
157  } else {
158  return $a_adt->isSmallerOrEqual($this->getUpperADT());
159  }
160  }
161 
162 
163  // import/export
164 
165  public function getSerializedValue()
166  {
167  if (!$this->isNull() && $this->isValid()) {
168  $res = array();
169  if (!$this->getLowerADT()->isNull()) {
170  $res["lower"] = $this->getLowerADT()->getDate()->get(IL_CAL_DATE);
171  }
172  if (!$this->getUpperADT()->isNull()) {
173  $res["upper"] = $this->getUpperADT()->getDate()->get(IL_CAL_DATE);
174  }
175  return serialize($res);
176  }
177  }
178 
179  public function setSerializedValue($a_value)
180  {
181  $a_value = unserialize($a_value);
182  if (is_array($a_value)) {
183  if (isset($a_value["lower"])) {
184  $this->getLowerADT()->setDate(new ilDate($a_value["lower"], IL_CAL_DATE));
185  }
186  if (isset($a_value["upper"])) {
187  $this->getUpperADT()->setDate(new ilDate($a_value["upper"], IL_CAL_DATE));
188  }
189  }
190  }
191 }
This class represents a property form user interface.
isValidADTDefinition(ilADTDefinition $a_adt_def)
$end
Definition: saml1-acs.php:18
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.
Class for single dates.
foreach($_POST as $key=> $value) $res
readFilter()
Load value(s) from filter store (in session)
$post
Definition: post.php:34
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.
const IL_CAL_DATE
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.