ILIAS  Release_5_0_x_branch Revision 61816
 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 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
6 require_once "Services/Calendar/classes/class.ilCalendarUtil.php";
7 
17 {
18  protected $ref_id; // int
19  protected $filter; // array
20  protected $pool_id; // int
21  protected $show_all; // bool
22  protected $has_schedule; // bool
23  protected $objects; // array
24  protected $group_id; // int
25 
37  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_show_all, $a_has_schedule, array $a_filter_pre = null, $a_group_id = null)
38  {
39  global $ilCtrl, $lng, $ilUser, $ilAccess;
40 
41  $this->pool_id = $a_pool_id;
42  $this->ref_id = $a_ref_id;
43  $this->show_all = $a_show_all;
44  $this->has_schedule = (bool)$a_has_schedule;
45  $this->group_id = $a_group_id;
46 
47  $this->setId("bkrsv".$a_ref_id);
48 
49  parent::__construct($a_parent_obj, $a_parent_cmd);
50 
51  $this->setTitle($lng->txt("book_reservations_list"));
52 
53  $this->addColumn("", "", 1);
54  $this->addColumn($this->lng->txt("title"), "title");
55 
56  if($this->has_schedule)
57  {
58  $this->lng->loadLanguageModule("dateplaner");
59 
60  $this->addColumn($this->lng->txt("date"), "date");
61  $this->addColumn($this->lng->txt("wk_short"), "week");
62  $this->addColumn($this->lng->txt("cal_weekday"), "weekday");
63  $this->addColumn($this->lng->txt("book_schedule_slot"), "slot");
64  $this->addColumn($this->lng->txt("book_no_of_objects"), "counter");
65 
66  $this->setDefaultOrderField("date");
67  $this->setDefaultOrderDirection("asc");
68  }
69  else
70  {
71  $this->addColumn($this->lng->txt("status"), "status");
72 
73  $this->setDefaultOrderField("title");
74  $this->setDefaultOrderDirection("asc");
75  }
76 
77  $this->addColumn($this->lng->txt("user"), "user_name");
78  $this->addColumn($this->lng->txt("actions"));
79 
80  $this->setExternalSegmentation(true);
81  $this->setExternalSorting(true);
82 
83  $this->setEnableHeader(true);
84  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
85  $this->setRowTemplate("tpl.booking_reservation_row.html", "Modules/BookingManager");
86  $this->setResetCommand("resetLogFilter");
87  $this->setFilterCommand("applyLogFilter");
88  $this->setDisableFilterHiding(true);
89 
90  $this->initFilter($a_filter_pre);
91 
92  if($this->group_id)
93  {
94  $this->setLimit(9999);
95  $this->disable("numinfo");
96  $this->filters = array();
97  }
98  else
99  {
100  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
101  }
102 
103  if($ilUser->getId() != ANONYMOUS_USER_ID)
104  {
105  /*
106  if($ilAccess->checkAccess('write', '', $this->ref_id))
107  {
108  $this->addMultiCommand('rsvInUse', $lng->txt('book_set_in_use'));
109  $this->addMultiCommand('rsvNotInUse', $lng->txt('book_set_not_in_use'));
110  }
111  */
112 
113  $this->addMultiCommand('rsvConfirmCancel', $lng->txt('book_set_cancel'));
114  // $this->addMultiCommand('rsvUncancel', $lng->txt('book_set_not_cancel'));
115  $this->setSelectAllCheckbox('mrsv');
116  }
117 
118  $this->getItems($this->getCurrentFilter());
119 
121  }
122 
126  function initFilter(array $a_filter_pre = null)
127  {
128  if(is_array($a_filter_pre) &&
129  isset($a_filter_pre["object"]))
130  {
131  $_SESSION["form_".$this->getId()]["object"] = serialize($a_filter_pre["object"]);
132  if($this->has_schedule)
133  {
134  $_SESSION["form_".$this->getId()]["fromto"] = serialize(array(
135  "from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)),
136  "to" => ""
137  ));
138  }
139  }
140 
141  $this->objects = array();
142  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
143  foreach(ilBookingObject::getList($this->pool_id) as $item)
144  {
145  $this->objects[$item["booking_object_id"]] = $item["title"];
146  }
147  $item = $this->addFilterItemByMetaType("object", ilTable2GUI::FILTER_SELECT);
148  $item->setOptions(array(""=>$this->lng->txt('book_all'))+$this->objects);
149  $this->filter["object"] = $item->getValue();
150 
151  if($this->has_schedule)
152  {
153  if(!$_SESSION["form_".$this->getId()]["fromto"])
154  {
155  // default: from today
156  $_SESSION["form_".$this->getId()]["fromto"] = serialize(array(
157  "from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)),
158  "to" => null
159  ));
160  }
161 
162  $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
163  $this->filter["fromto"] = $item->getDate();
164 
165  // only needed for full log
166  if($this->show_all)
167  {
168  // see ilObjBookingPoolGUI::buildDatesBySchedule()
169  $map = array_flip(array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'));
170 
171  $options = array(""=>$this->lng->txt('book_all'));
172 
173  // schedule to slot
174  require_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
175  foreach(ilBookingSchedule::getList($this->pool_id) as $def)
176  {
177  $schedule = new ilBookingSchedule($def["booking_schedule_id"]);
178  foreach($schedule->getDefinition() as $day => $slots)
179  {
180  $day_caption = ilCalendarUtil::_numericDayToString($map[$day], false);
181 
182  foreach($slots as $slot)
183  {
184  $idx = $map[$day]."_".$slot;
185  $options[$idx] = $day_caption.", ".$slot;
186  }
187  }
188  }
189 
190  ksort($options);
191 
192  $item = $this->addFilterItemByMetaType("book_schedule_slot", ilTable2GUI::FILTER_SELECT);
193  $item->setOptions($options);
194  $this->filter["slot"] = $item->getValue();
195  }
196  }
197 
198  // status
199  $valid_status = array(-ilBookingReservation::STATUS_CANCELLED,
201  if(!$this->has_schedule)
202  {
203  $options = array(""=>$this->lng->txt('book_all'));
204  }
205  else
206  {
207  $options = array();
208  }
209  foreach($valid_status as $loop)
210  {
211  if($loop > 0)
212  {
213  $options[$loop] = $this->lng->txt('book_reservation_status_'.$loop);
214  }
215  else
216  {
217  $options[$loop] = $this->lng->txt('book_not').' '.$this->lng->txt('book_reservation_status_'.-$loop);
218  }
219  }
220  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
221  $item->setOptions($options);
222  $this->filter["status"] = $item->getValue();
223 
224  // only needed for full log
225  if($this->show_all)
226  {
227  $options = array(""=>$this->lng->txt('book_all'))+
228  ilBookingReservation::getUserFilter(array_keys($this->objects));
229  $item = $this->addFilterItemByMetaType("user", ilTable2GUI::FILTER_SELECT);
230  $item->setOptions($options);
231  $this->filter["user_id"] = $item->getValue();
232  }
233  }
234 
239  function getCurrentFilter()
240  {
241  $filter = array();
242  if($this->filter["object"])
243  {
244  $filter["object"] = $this->filter["object"];
245  }
246  if($this->filter["status"])
247  {
248  $filter["status"] = $this->filter["status"];
249  }
250  if($this->filter["user_id"])
251  {
252  $filter["user_id"] = $this->filter["user_id"];
253  }
254 
255  if($this->has_schedule)
256  {
257  if(!$filter["status"])
258  {
259  // needs distinct status because of aggregation
261  }
262  if($this->filter["slot"])
263  {
264  $filter["slot"] = $this->filter["slot"];
265  }
266 
267  if($this->filter["fromto"]["from"] || $this->filter["fromto"]["to"])
268  {
269  if($this->filter["fromto"]["from"])
270  {
271  $filter["from"] = $this->filter["fromto"]["from"]->get(IL_CAL_UNIX);
272  }
273  if($this->filter["fromto"]["to"])
274  {
275  $day_end = new ilDateTime($this->filter["fromto"]["to"]->get(IL_CAL_DATE)." 23:59:59", IL_CAL_DATETIME);
276  $filter["to"] = $day_end->get(IL_CAL_UNIX);
277  }
278  }
279  }
280 
281  return $filter;
282  }
283 
288  function getItems(array $filter)
289  {
290  global $ilUser;
291 
292  $this->determineOffsetAndOrder();
293 
294  if(!$filter["object"])
295  {
296  $ids = array_keys($this->objects);
297  }
298  else
299  {
300  $ids = array($filter["object"]);
301  }
302 
303  if(!$this->show_all)
304  {
305  $filter["user_id"] = $ilUser->getId();
306  }
307 
308  include_once "Modules/BookingManager/classes/class.ilBookingReservation.php";
309  $data = ilBookingReservation::getListByDate($this->has_schedule, $ids, $this->getOrderField(), $this->getOrderDirection(), $this->getOffset(), $this->getLimit(), $filter);
310 
311  $this->setData($data['data']);
312  $this->setMaxCount($data['counter']);
313  }
314 
319  protected function fillRow($a_set)
320  {
321  global $lng, $ilAccess, $ilCtrl, $ilUser;
322 
323  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
324 
325  $can_be_cancelled = (($ilAccess->checkAccess('write', '', $this->ref_id) ||
326  $a_set['user_id'] == $ilUser->getId()) &&
327  $a_set["can_be_cancelled"]);
328 
329  if($can_be_cancelled)
330  {
331  $this->tpl->setVariable("MULTI_ID", $a_set["booking_reservation_id"]);
332  }
333 
334  // #11995
335  $uname = $a_set["user_name"];
336  if(!trim($uname))
337  {
338  $uname = "[".$lng->txt("user_deleted")."]";
339  }
340  else
341  {
342  $ilCtrl->setParameter($this->parent_obj, 'user_id', $a_set['user_id']);
343  $this->tpl->setVariable("HREF_PROFILE", $ilCtrl->getLinkTarget($this->parent_obj, 'showprofile'));
344  $ilCtrl->setParameter($this->parent_obj, 'user_id', '');
345  }
346  $this->tpl->setVariable("TXT_CURRENT_USER", $uname);
347 
348  if($this->has_schedule)
349  {
350  $this->tpl->setVariable("VALUE_DATE", ilDatePresentation::formatDate(new ilDate($a_set["date"], IL_CAL_DATE)));
351  $this->tpl->setVariable("VALUE_WEEK", $a_set["week"]);
352  $this->tpl->setVariable("VALUE_WEEKDAY", ilCalendarUtil::_numericDayToString($a_set["weekday"], false));
353  $this->tpl->setVariable("VALUE_SLOT", $a_set["slot"]);
354  $this->tpl->setVariable("VALUE_COUNTER", $a_set["counter"]);
355  }
356  else
357  {
359  {
360  $this->tpl->setVariable("TXT_STATUS", $lng->txt('book_reservation_status_'.$a_set['status']));
361  }
362  else
363  {
364  $this->tpl->setVariable("TXT_STATUS", "&nbsp;");
365  }
366  }
367 
368  if($can_be_cancelled)
369  {
370  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
371  $this->tpl->setVariable("URL_ACTION", $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancel'));
372  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', "");
373  $this->tpl->setVariable("TXT_ACTION", $lng->txt('book_set_cancel'));
374  }
375 
376  /* advsellist version
377  if (!$this->has_schedule || $date_to->get(IL_CAL_UNIX) > time())
378  {
379  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
380  $alist = new ilAdvancedSelectionListGUI();
381  $alist->setId($a_set['booking_reservation_id']);
382  $alist->setListTitle($lng->txt("actions"));
383 
384  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
385 
386  if(!$a_set['group_id'])
387  {
388  if($ilAccess->checkAccess('write', '', $this->ref_id))
389  {
390  if($a_set['status'] == ilBookingReservation::STATUS_CANCELLED)
391  {
392  // can be uncancelled?
393  // if(ilBookingReservation::getAvailableObject(array($a_set['object_id']), $date_from->get(IL_CAL_UNIX), $date_to->get(IL_CAL_UNIX)))
394  // {
395  // $alist->addItem($lng->txt('book_set_not_cancel'), 'not_cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvUncancel'));
396  // }
397  }
398  else if($a_set['status'] != ilBookingReservation::STATUS_IN_USE)
399  {
400  if($this->has_schedule)
401  {
402  $alist->addItem($lng->txt('book_set_in_use'), 'in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvInUse'));
403  }
404  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancel'));
405  }
406  else if($this->has_schedule)
407  {
408  $alist->addItem($lng->txt('book_set_not_in_use'), 'not_in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvNotInUse'));
409  }
410  }
411  else if($a_set['user_id'] == $ilUser->getId() && $a_set['status'] != ilBookingReservation::STATUS_CANCELLED)
412  {
413  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancel'));
414  }
415  }
416  else if($ilAccess->checkAccess('write', '', $this->ref_id) || $a_set['user_id'] == $ilUser->getId())
417  {
418  $alist->addItem($lng->txt('details'), 'details', $ilCtrl->getLinkTarget($this->parent_obj, 'logDetails'));
419  }
420 
421  if(sizeof($alist->getItems()))
422  {
423  if(!$a_set['group_id'])
424  {
425  $this->tpl->setVariable('MULTI_ID', $a_set['booking_reservation_id']);
426  }
427  $this->tpl->setVariable('LAYER', $alist->getHTML());
428  }
429  }
430  */
431  }
432 
433  protected function fillHeaderExcel($a_worksheet, &$a_row)
434  {
435  $a_worksheet->write($a_row, 0, $this->lng->txt("title"));
436  $col = 0;
437  if($this->has_schedule)
438  {
439  $a_worksheet->write($a_row, ++$col, $this->lng->txt("date"));
440  $a_worksheet->write($a_row, ++$col, $this->lng->txt("book_schedule_weekday"));
441  $a_worksheet->write($a_row, ++$col, $this->lng->txt("book_schedule_slot"));
442  $a_worksheet->write($a_row, ++$col, $this->lng->txt("book_no_of_objects"));
443  }
444  else
445  {
446  $a_worksheet->write($a_row, ++$col, $this->lng->txt("status"));
447  }
448  $a_worksheet->write($a_row, ++$col, $this->lng->txt("user"));
449  }
450 
451  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
452  {
453  $a_worksheet->write($a_row, 0, $a_set["title"]);
454  $col = 0;
455  if($this->has_schedule)
456  {
457  $a_worksheet->write($a_row, ++$col, ilDatePresentation::formatDate(new ilDate($a_set["date"], IL_CAL_DATE)));
458  $a_worksheet->write($a_row, ++$col, ilCalendarUtil::_numericDayToString($a_set["weekday"], false));
459  $a_worksheet->write($a_row, ++$col, $a_set["slot"]);
460  $a_worksheet->write($a_row, ++$col, $a_set["counter"]);
461  }
462  else
463  {
464  $status = "";
466  {
467  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
468  }
469  $a_worksheet->write($a_row, ++$col, $status);
470  }
471  $a_worksheet->write($a_row, ++$col, $a_set['user_name']);
472  }
473 
474  protected function fillHeaderCSV($a_csv)
475  {
476  $a_csv->addColumn($this->lng->txt("title"));
477  if($this->has_schedule)
478  {
479  $a_csv->addColumn($this->lng->txt("date"));
480  $a_csv->addColumn($this->lng->txt("book_schedule_weekday"));
481  $a_csv->addColumn($this->lng->txt("book_schedule_slot"));
482  $a_csv->addColumn($this->lng->txt("book_no_of_objects"));
483  }
484  else
485  {
486  $a_csv->addColumn($this->lng->txt("status"));
487  }
488  $a_csv->addColumn($this->lng->txt("user"));
489  $a_csv->addRow();
490  }
491 
492  protected function fillRowCSV($a_csv, $a_set)
493  {
494  $a_csv->addColumn($a_set["title"]);
495  if($this->has_schedule)
496  {
497  $a_csv->addColumn(ilDatePresentation::formatDate(new ilDate($a_set["date"], IL_CAL_DATE)));
498  $a_csv->addColumn(ilCalendarUtil::_numericDayToString($a_set["weekday"], false));
499  $a_csv->addColumn($a_set["slot"]);
500  $a_csv->addColumn($a_set["counter"]);
501  }
502  else
503  {
504  $status = "";
506  {
507  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
508  }
509  $a_csv->addColumn($status);
510  }
511  $a_csv->addColumn($a_set['user_name']);
512  $a_csv->addRow();
513  }
514 }
515 
516 ?>