ILIAS  Release_4_4_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 
16 {
17  protected $ref_id; // int
18  protected $filter; // array
19  protected $pool_id; // int
20  protected $show_all; // bool
21  protected $has_schedule; // bool
22  protected $objects; // array
23  protected $group_id; // int
24 
36  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)
37  {
38  global $ilCtrl, $lng;
39 
40  $this->pool_id = $a_pool_id;
41  $this->ref_id = $a_ref_id;
42  $this->show_all = $a_show_all;
43  $this->has_schedule = (bool)$a_has_schedule;
44  $this->group_id = $a_group_id;
45 
46  $this->setId("bkrsv".$a_ref_id);
47 
48  parent::__construct($a_parent_obj, $a_parent_cmd);
49 
50  $this->setTitle($lng->txt("book_reservations_list"));
51 
52  $this->addColumn("", "", 1);
53  $this->addColumn($this->lng->txt("title"));
54 
55  if($this->has_schedule)
56  {
57  $this->addColumn($this->lng->txt("book_period"));
58  }
59 
60  $this->addColumn($this->lng->txt("user"));
61  $this->addColumn($this->lng->txt("status"));
62  $this->addColumn($this->lng->txt("actions"));
63 
64  $this->setExternalSegmentation(true);
65  $this->setEnableHeader(true);
66  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
67  $this->setRowTemplate("tpl.booking_reservation_row.html", "Modules/BookingManager");
68  $this->setResetCommand("resetLogFilter");
69  $this->setFilterCommand("applyLogFilter");
70  $this->setDisableFilterHiding(true);
71 
72  $this->initFilter($a_filter_pre);
73 
74  if($this->group_id)
75  {
76  $this->setLimit(9999);
77  $this->disable("numinfo");
78  $this->filters = array();
79  }
80  else
81  {
82  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
83  }
84 
85  $this->addMultiCommand('rsvInUse', $lng->txt('book_set_in_use'));
86  $this->addMultiCommand('rsvNotInUse', $lng->txt('book_set_not_in_use'));
87  $this->addMultiCommand('rsvConfirmCancel', $lng->txt('book_set_cancel'));
88  // $this->addMultiCommand('rsvUncancel', $lng->txt('book_set_not_cancel'));
89  $this->setSelectAllCheckbox('mrsv');
90 
91  $this->getItems($this->getCurrentFilter());
92  }
93 
97  function initFilter(array $a_filter_pre = null)
98  {
99  if(is_array($a_filter_pre) &&
100  isset($a_filter_pre["object"]))
101  {
102  $_SESSION["form_".$this->getId()]["object"] = serialize($a_filter_pre["object"]);
103  if($this->has_schedule)
104  {
105  $_SESSION["form_".$this->getId()]["fromto"] = serialize(array(
106  "from" => serialize(new ilDateTime(date("Y-m-d"), IL_CAL_DATE)),
107  "to" => ""
108  ));
109  }
110  }
111 
112  $this->objects = array();
113  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
114  foreach(ilBookingObject::getList($this->pool_id) as $item)
115  {
116  $this->objects[$item["booking_object_id"]] = $item["title"];
117  }
118  $item = $this->addFilterItemByMetaType("object", ilTable2GUI::FILTER_SELECT);
119  $item->setOptions(array(""=>$this->lng->txt('book_all'))+$this->objects);
120  $this->filter["object"] = $item->getValue();
121 
122  if($this->hasSchedule)
123  {
124  $valid_status = array(ilBookingReservation::STATUS_IN_USE,
128  }
129  else
130  {
131  $valid_status = array(ilBookingReservation::STATUS_CANCELLED,
133  };
134 
135  $options = array(""=>$this->lng->txt('book_all'));
136  foreach($valid_status as $loop)
137  {
138  if($loop > 0)
139  {
140  $options[$loop] = $this->lng->txt('book_reservation_status_'.$loop);
141  }
142  else
143  {
144  $options[$loop] = $this->lng->txt('book_not').' '.$this->lng->txt('book_reservation_status_'.-$loop);
145  }
146  }
147  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
148  $item->setOptions($options);
149  $this->filter["status"] = $item->getValue();
150 
151  if($this->has_schedule)
152  {
153  $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
154  $this->filter["fromto"] = $item->getDate();
155  }
156  }
157 
162  function getCurrentFilter()
163  {
164  $filter = array();
165  if($this->filter["object"])
166  {
167  $filter["object"] = $this->filter["object"];
168  }
169  if($this->filter["status"])
170  {
171  $filter["status"] = $this->filter["status"];
172  }
173 
174  if($this->has_schedule)
175  {
176  if($this->filter["fromto"]["from"] || $this->filter["fromto"]["to"])
177  {
178  if($this->filter["fromto"]["from"])
179  {
180  $filter["from"] = $this->filter["fromto"]["from"]->get(IL_CAL_UNIX);
181  }
182  if($this->filter["fromto"]["to"])
183  {
184  $filter["to"] = $this->filter["fromto"]["to"]->get(IL_CAL_UNIX);
185  }
186  }
187  }
188 
189  return $filter;
190  }
191 
196  function getItems(array $filter)
197  {
198  global $ilUser;
199 
200  $this->determineOffsetAndOrder();
201 
202  if(!$filter["object"])
203  {
204  $ids = array_keys($this->objects);
205  }
206  else
207  {
208  $ids = array($filter["object"]);
209  }
210 
211  include_once "Modules/BookingManager/classes/class.ilBookingReservation.php";
212  $data = ilBookingReservation::getGroupedList($ids, $this->getLimit(), $this->getOffset(), $filter, $this->group_id);
213 
214  if(!$this->show_all)
215  {
216  foreach($data['data'] as $idx => $item)
217  {
218  if($item["user_id"] != $ilUser->getId())
219  {
220  unset($data['data'][$idx]);
221  }
222  }
223  }
224 
225  // #14411
226  if(!$this->has_schedule)
227  {
228  $data['data'] = ilUtil::sortArray($data['data'], "title", "asc");
229  }
230 
231  $this->setData($data['data']);
232  $this->setMaxCount($data['counter']);
233  }
234 
239  protected function fillRow($a_set)
240  {
241  global $lng, $ilAccess, $ilCtrl, $ilUser;
242 
243  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
244  $this->tpl->setVariable("RESERVATION_ID", $a_set["booking_reservation_id"]);
245 
247  {
248  $this->tpl->setVariable("TXT_STATUS", $lng->txt('book_reservation_status_'.$a_set['status']));
249  }
250 
251  // #11995
252  $uname = ilObjUser::_lookupFullName($a_set['user_id']);
253  if(!trim($uname))
254  {
255  $uname = "[".$lng->txt("user_deleted")."]";
256  }
257  else
258  {
259  $ilCtrl->setParameter($this->parent_obj, 'user_id', $a_set['user_id']);
260  $this->tpl->setVariable("HREF_PROFILE", $ilCtrl->getLinkTarget($this->parent_obj, 'showprofile'));
261  $ilCtrl->setParameter($this->parent_obj, 'user_id', '');
262  }
263  $this->tpl->setVariable("TXT_CURRENT_USER", $uname);
264 
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  $this->tpl->setVariable("VALUE_DATE", ilDatePresentation::formatPeriod($date_from, $date_to));
270  }
271 
272  if (!$this->has_schedule || $date_to->get(IL_CAL_UNIX) > time())
273  {
274  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
275  $alist = new ilAdvancedSelectionListGUI();
276  $alist->setId($a_set['booking_reservation_id']);
277  $alist->setListTitle($lng->txt("actions"));
278 
279  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
280 
281  if(!$a_set['group_id'])
282  {
283  if($ilAccess->checkAccess('write', '', $this->ref_id))
284  {
285  if($a_set['status'] == ilBookingReservation::STATUS_CANCELLED)
286  {
287  /*
288  // can be uncancelled?
289  if(ilBookingReservation::getAvailableObject(array($a_set['object_id']), $date_from->get(IL_CAL_UNIX), $date_to->get(IL_CAL_UNIX)))
290  {
291  $alist->addItem($lng->txt('book_set_not_cancel'), 'not_cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvUncancel'));
292  }
293  */
294  }
295  else if($a_set['status'] != ilBookingReservation::STATUS_IN_USE)
296  {
297  if($this->has_schedule)
298  {
299  $alist->addItem($lng->txt('book_set_in_use'), 'in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvInUse'));
300  }
301  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancel'));
302  }
303  else if($this->has_schedule)
304  {
305  $alist->addItem($lng->txt('book_set_not_in_use'), 'not_in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvNotInUse'));
306  }
307  }
308  else if($a_set['user_id'] == $ilUser->getId() && $a_set['status'] != ilBookingReservation::STATUS_CANCELLED)
309  {
310  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancel'));
311  }
312  }
313  else if($ilAccess->checkAccess('write', '', $this->ref_id) || $a_set['user_id'] == $ilUser->getId())
314  {
315  $alist->addItem($lng->txt('details'), 'details', $ilCtrl->getLinkTarget($this->parent_obj, 'logDetails'));
316  }
317 
318  if(sizeof($alist->getItems()))
319  {
320  if(!$a_set['group_id'])
321  {
322  $this->tpl->setVariable('MULTI_ID', $a_set['booking_reservation_id']);
323  }
324  $this->tpl->setVariable('LAYER', $alist->getHTML());
325  }
326  }
327  }
328 
329  protected function fillHeaderExcel($a_worksheet, &$a_row)
330  {
331  $a_worksheet->write($a_row, 0, $this->lng->txt("title"));
332  $col = 0;
333  if($this->has_schedule)
334  {
335  $a_worksheet->write($a_row, ++$col, $this->lng->txt("from"));
336  $a_worksheet->write($a_row, ++$col, $this->lng->txt("to"));
337  }
338  $a_worksheet->write($a_row, ++$col, $this->lng->txt("user"));
339  $a_worksheet->write($a_row, ++$col, $this->lng->txt("status"));
340  $a_row++;
341  }
342 
343  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
344  {
345  $a_worksheet->write($a_row, 0, $a_set["title"]);
346  $col = 0;
347  if($this->has_schedule)
348  {
349  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
350  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
351  $a_worksheet->write($a_row, ++$col, ilDatePresentation::formatDate($date_from));
352  $a_worksheet->write($a_row, ++$col, ilDatePresentation::formatDate($date_to));
353  }
354  $a_worksheet->write($a_row, ++$col, ilObjUser::_lookupFullName($a_set['user_id']));
355 
356  $status = "";
358  {
359  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
360  }
361  $a_worksheet->write($a_row, ++$col, $status);
362 
363  $a_row++;
364  }
365 
366  protected function fillHeaderCSV($a_csv)
367  {
368  $a_csv->addColumn($this->lng->txt("title"));
369  if($this->has_schedule)
370  {
371  $a_csv->addColumn($this->lng->txt("from"));
372  $a_csv->addColumn($this->lng->txt("to"));
373  }
374  $a_csv->addColumn($this->lng->txt("user"));
375  $a_csv->addColumn($this->lng->txt("status"));
376  $a_csv->addRow();
377  }
378 
379  protected function fillRowCSV($a_csv, $a_set)
380  {
381  $a_csv->addColumn($a_set["title"]);
382  if($this->has_schedule)
383  {
384  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
385  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
386  $a_csv->addColumn(ilDatePresentation::formatDate($date_from));
387  $a_csv->addColumn(ilDatePresentation::formatDate($date_to));
388  }
389  $a_csv->addColumn(ilObjUser::_lookupFullName($a_set['user_id']));
390 
391  $status = "";
393  {
394  $status = $this->lng->txt('book_reservation_status_'.$a_set['status']);
395  }
396  $a_csv->addColumn($status);
397 
398  $a_csv->addRow();
399  }
400 }
401 
402 ?>