ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilADTDateSearchBridgeSingle.php
Go to the documentation of this file.
1 <?php
2 
3 require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeSingle.php";
4 
6 {
7  protected $text_input; // [bool]
8 
9  protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
10  {
11  return ($a_adt_def instanceof ilADTDateDefinition);
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  // $this->getADT()->setDate(new ilDate($value, IL_CAL_DATE));
28  }
29  }
30 
31 
32  // form
33 
34  public function addToForm()
35  {
36  global $lng;
37 
38  $adt_date = $this->getADT()->getDate();
39 
40  $date = new ilDateTimeInputGUI($this->getTitle(), $this->getElementId());
41  $date->setShowTime(false);
42 
43  if(!(bool)$this->text_input)
44  {
45  $checked = !(!$adt_date || $adt_date->isNull());
46  $date->enableDateActivation($lng->txt("enabled"), $this->addToElementId("tgl"), $checked);
47  }
48  else
49  {
50  $date->setMode(ilDateTimeInputGUI::MODE_INPUT);
51  }
52 
53  $date->setDate($adt_date);
54 
55  $this->addToParentElement($date);
56  }
57 
58  protected function shouldBeImportedFromPost(array $a_post)
59  {
60  if(!(bool)$this->text_input)
61  {
62  return (bool)$a_post["tgl"];
63  }
65  }
66 
67  public function importFromPost(array $a_post = null)
68  {
69  $post = $this->extractPostValues($a_post);
70 
71  if($post && $this->shouldBeImportedFromPost($post))
72  {
73  include_once "Services/ADT/classes/class.ilADTDateSearchUtil.php";
74 
75  if((bool)$this->text_input)
76  {
78  }
79  else
80  {
82  }
83 
84  // :TODO: all dates are imported as valid
85 
86  if($date)
87  {
88  $date = new ilDate($date, IL_CAL_UNIX);
89  }
90 
91  if($this->getForm() instanceof ilPropertyFormGUI)
92  {
93  $item = $this->getForm()->getItemByPostVar($this->getElementId());
94  $item->setDate($date);
95  }
96  else if(array_key_exists($this->getElementId(), $this->table_filter_fields))
97  {
98  $this->table_filter_fields[$this->getElementId()]->setDate($date);
99  $this->writeFilter($date->get(IL_CAL_DATE));
100  }
101 
102  $this->getADT()->setDate($date);
103  }
104  else
105  {
106  $this->writeFilter();
107  $this->getADT()->setDate();
108  }
109  }
110 
111 
112  // db
113 
114  public function getSQLCondition($a_element_id)
115  {
116  global $ilDB;
117 
118  if(!$this->isNull() && $this->isValid())
119  {
120  return $a_element_id." = ".$ilDB->quote($this->getADT()->getDate()->get(IL_CAL_DATE), "date");
121  }
122  }
123 
124  public function isInCondition(ilADTDate $a_adt)
125  {
126  return $this->getADT()->equals($a_adt);
127  }
128 
129 
130  // import/export
131 
132  public function getSerializedValue()
133  {
134  if(!$this->isNull() && $this->isValid())
135  {
136  return serialize(array($this->getADT()->getDate()->get(IL_CAL_DATE)));
137  }
138  }
139 
140  public function setSerializedValue($a_value)
141  {
142  $a_value = unserialize($a_value);
143  if(is_array($a_value))
144  {
145  $this->getADT()->setDate(new ilDate($a_value[0], IL_CAL_DATE));
146  }
147  }
148 }
149 
150 ?>