ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookingReservationsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected $ref_id; // int
17  protected $filter; // array
18  protected $pool_id; // int
19  protected $has_schedule; // bool
20 
28  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_has_schedule)
29  {
30  global $ilCtrl, $lng;
31 
32  $this->pool_id = $a_pool_id;
33  $this->ref_id = $a_ref_id;
34  $this->has_schedule = (bool)$a_has_schedule;
35 
36  $this->setId("bkrsv");
37 
38  parent::__construct($a_parent_obj, $a_parent_cmd);
39 
40  $this->setTitle($lng->txt("book_reservations_list"));
41 
42  $this->addColumn($this->lng->txt("title"));
43 
44  if($this->has_schedule)
45  {
46  $this->addColumn($this->lng->txt("book_period"));
47  }
48 
49  $this->addColumn($this->lng->txt("user"));
50  $this->addColumn($this->lng->txt("status"));
51  $this->addColumn($this->lng->txt("actions"));
52 
53  $this->setExternalSegmentation(true);
54  $this->setEnableHeader(true);
55  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
56  $this->setRowTemplate("tpl.booking_reservation_row.html", "Modules/BookingManager");
57  $this->setResetCommand("resetLogFilter");
58  $this->setFilterCommand("applyLogFilter");
59  $this->setDisableFilterHiding(true);
60 
61  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
62 
63  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
64 
65  $this->initFilter();
66 
67  $this->getItems($this->getCurrentFilter());
68  }
69 
73  function initFilter()
74  {
75  if($this->hasSchedule)
76  {
77  $valid_status = array(ilBookingReservation::STATUS_IN_USE,
81  }
82  else
83  {
84  $valid_status = array(ilBookingReservation::STATUS_CANCELLED,
86  };
87 
88  $options = array(""=>$this->lng->txt('book_all'));
89  foreach($valid_status as $loop)
90  {
91  if($loop > 0)
92  {
93  $options[$loop] = $this->lng->txt('book_reservation_status_'.$loop);
94  }
95  else
96  {
97  $options[$loop] = $this->lng->txt('book_not').' '.$this->lng->txt('book_reservation_status_'.-$loop);
98  }
99  }
100  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
101  $item->setOptions($options);
102  $this->filter["status"] = $item->getValue();
103 
104  if($this->has_schedule)
105  {
106  $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
107  $this->filter["fromto"] = $item->getDate();
108  }
109  }
110 
115  function getCurrentFilter()
116  {
117  $filter = array();
118  if($this->filter["type"])
119  {
120  $filter["type"] = $this->filter["type"];
121  }
122  if($this->filter["status"])
123  {
124  $filter["status"] = $this->filter["status"];
125  }
126 
127  if($this->has_schedule)
128  {
129  if($this->filter["fromto"]["from"] || $this->filter["fromto"]["to"])
130  {
131  if($this->filter["fromto"]["from"])
132  {
133  $filter["from"] = $this->filter["fromto"]["from"]->get(IL_CAL_UNIX);
134  }
135  if($this->filter["fromto"]["to"])
136  {
137  $filter["to"] = $this->filter["fromto"]["to"]->get(IL_CAL_UNIX);
138  }
139  }
140  }
141 
142  return $filter;
143  }
144 
149  function getItems(array $filter)
150  {
151  $this->determineOffsetAndOrder();
152 
153  $ids = array();
154  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
155  foreach(ilBookingObject::getList($this->pool_id) as $item)
156  {
157  $ids[] = $item["booking_object_id"];
158  }
159 
160  include_once "Modules/BookingManager/classes/class.ilBookingReservation.php";
161  $data = ilBookingReservation::getList($ids, $this->getLimit(), $this->getOffset(), $filter);
162 
163  $this->setMaxCount($data['counter']);
164  $this->setData($data['data']);
165  }
166 
171  protected function fillRow($a_set)
172  {
173  global $lng, $ilAccess, $ilCtrl, $ilUser;
174 
175  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
176  $this->tpl->setVariable("RESERVATION_ID", $a_set["booking_reservation_id"]);
177 
179  {
180  $this->tpl->setVariable("TXT_STATUS", $lng->txt('book_reservation_status_'.$a_set['status']));
181  }
182 
183  // #11995
184  $uname = ilObjUser::_lookupFullName($a_set['user_id']);
185  if(!trim($uname))
186  {
187  $uname = "[".$lng->txt("user_deleted")."]";
188  }
189  else
190  {
191  $ilCtrl->setParameter($this->parent_obj, 'user_id', $a_set['user_id']);
192  $this->tpl->setVariable("HREF_PROFILE", $ilCtrl->getLinkTarget($this->parent_obj, 'showprofile'));
193  $ilCtrl->setParameter($this->parent_obj, 'user_id', '');
194  }
195  $this->tpl->setVariable("TXT_CURRENT_USER", $uname);
196 
197  if($this->has_schedule)
198  {
199  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
200  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
201  $this->tpl->setVariable("VALUE_DATE", ilDatePresentation::formatPeriod($date_from, $date_to));
202  }
203 
204  if (!$this->has_schedule || $date_from->get(IL_CAL_UNIX) > time())
205  {
206  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
207  $alist = new ilAdvancedSelectionListGUI();
208  $alist->setId($a_set['booking_reservation_id']);
209  $alist->setListTitle($lng->txt("actions"));
210 
211  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
212 
213  if($ilAccess->checkAccess('write', '', $this->ref_id))
214  {
215  if($a_set['status'] == ilBookingReservation::STATUS_CANCELLED)
216  {
217  /*
218  // can be uncancelled?
219  if(ilBookingReservation::getAvailableObject(array($a_set['object_id']), $date_from->get(IL_CAL_UNIX), $date_to->get(IL_CAL_UNIX)))
220  {
221  $alist->addItem($lng->txt('book_set_not_cancel'), 'not_cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvUncancel'));
222  }
223  */
224  }
225  else if($a_set['status'] != ilBookingReservation::STATUS_IN_USE)
226  {
227  if($this->has_schedule)
228  {
229  $alist->addItem($lng->txt('book_set_in_use'), 'in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvInUse'));
230  }
231  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvCancel'));
232  }
233  else if($this->has_schedule)
234  {
235  $alist->addItem($lng->txt('book_set_not_in_use'), 'not_in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvNotInUse'));
236  }
237  }
238  else if($a_set['user_id'] == $ilUser->getId() && $a_set['status'] != ilBookingReservation::STATUS_CANCELLED)
239  {
240  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvCancel'));
241  }
242 
243  $this->tpl->setVariable('LAYER', $alist->getHTML());
244  }
245  }
246 
247  protected function fillHeaderExcel($a_worksheet, &$a_row)
248  {
249  $a_worksheet->write($a_row, 0, $this->lng->txt("title"));
250  $col = 0;
251  if($this->has_schedule)
252  {
253  $a_worksheet->write($a_row, ++$col, $this->lng->txt("from"));
254  $a_worksheet->write($a_row, ++$col, $this->lng->txt("to"));
255  }
256  $a_worksheet->write($a_row, ++$col, $this->lng->txt("user"));
257  $a_worksheet->write($a_row, ++$col, $this->lng->txt("status"));
258  $a_row++;
259  }
260 
261  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
262  {
263  $a_worksheet->write($a_row, 0, $a_set["title"]);
264  $col = 0;
265  if($this->has_schedule)
266  {
267  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
268  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
269  $a_worksheet->write($a_row, ++$col, ilDatePresentation::formatDate($date_from));
270  $a_worksheet->write($a_row, ++$col, ilDatePresentation::formatDate($date_to));
271  }
272  $a_worksheet->write($a_row, ++$col, ilObjUser::_lookupFullName($a_set['user_id']));
273 
274  $status = "";
276  {
277  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
278  }
279  $a_worksheet->write($a_row, ++$col, $status);
280 
281  $a_row++;
282  }
283 
284  protected function fillHeaderCSV($a_csv)
285  {
286  $a_csv->addColumn($this->lng->txt("title"));
287  if($this->has_schedule)
288  {
289  $a_csv->addColumn($this->lng->txt("from"));
290  $a_csv->addColumn($this->lng->txt("to"));
291  }
292  $a_csv->addColumn($this->lng->txt("user"));
293  $a_csv->addColumn($this->lng->txt("status"));
294  $a_csv->addRow();
295  }
296 
297  protected function fillRowCSV($a_csv, $a_set)
298  {
299  $a_csv->addColumn($a_set["title"]);
300  if($this->has_schedule)
301  {
302  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
303  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
304  $a_csv->addColumn(ilDatePresentation::formatDate($date_from));
305  $a_csv->addColumn(ilDatePresentation::formatDate($date_to));
306  }
307  $a_csv->addColumn(ilObjUser::_lookupFullName($a_set['user_id']));
308 
309  $status = "";
311  {
312  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
313  }
314  $a_csv->addColumn($status);
315 
316  $a_csv->addRow();
317  }
318 }
319 
320 ?>