ILIAS  Release_4_1_x_branch Revision 61804
 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; // object
19 
27  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id)
28  {
29  global $ilCtrl, $lng, $ilAccess, $lng, $ilObjDataCache;
30 
31  $this->pool = $a_parent_obj->object;
32  $this->ref_id = $a_ref_id;
33  $this->setId("bkrsv");
34 
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 
37  $this->setTitle($lng->txt("book_reservations_list"));
38 
39  $this->addColumn($this->lng->txt("title"));
40  $this->addColumn($this->lng->txt("book_period"));
41  $this->addColumn($this->lng->txt("user"));
42  $this->addColumn($this->lng->txt("status"));
43  $this->addColumn($this->lng->txt("actions"));
44 
45  $this->setExternalSegmentation(true);
46  $this->setEnableHeader(true);
47  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
48  $this->setRowTemplate("tpl.booking_reservation_row.html", "Modules/BookingManager");
49  $this->setResetCommand("resetLogFilter");
50  $this->setFilterCommand("applyLogFilter");
51  $this->setDisableFilterHiding(true);
52 
53 
54  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
55 
56  $this->initFilter();
57 
58  $this->getItems($this->getCurrentFilter());
59  }
60 
64  function initFilter()
65  {
66  include_once "Modules/BookingManager/classes/class.ilBookingType.php";
67  $options = array(""=>$this->lng->txt('book_all'));
68  foreach(ilBookingType::getList($this->pool->getId()) as $item)
69  {
70  $options[$item["booking_type_id"]] = $item["title"];
71  }
73  $item->setOptions($options);
74  $this->filter["type"] = $item->getValue();
75 
76  $options = array(""=>$this->lng->txt('book_all'));
78  {
79  if($loop > 0)
80  {
81  $options[$loop] = $this->lng->txt('book_reservation_status_'.$loop);
82  }
83  else
84  {
85  $options[$loop] = $this->lng->txt('book_not').' '.$this->lng->txt('book_reservation_status_'.-$loop);
86  }
87  }
88  $item = $this->addFilterItemByMetaType("status", ilTable2GUI::FILTER_SELECT);
89  $item->setOptions($options);
90  $this->filter["status"] = $item->getValue();
91 
92  $item = $this->addFilterItemByMetaType("fromto", ilTable2GUI::FILTER_DATE_RANGE, false, $this->lng->txt('book_fromto'));
93  $this->filter["fromto"] = $item->getDate();
94  }
95 
100  function getCurrentFilter()
101  {
102  $filter = array();
103  if($this->filter["type"])
104  {
105  $filter["type"] = $this->filter["type"];
106  }
107  if($this->filter["status"])
108  {
109  $filter["status"] = $this->filter["status"];
110  }
111  if($this->filter["fromto"]["from"] || $this->filter["fromto"]["to"])
112  {
113  if($this->filter["fromto"]["from"])
114  {
115  $filter["from"] = $this->filter["fromto"]["from"]->get(IL_CAL_UNIX);
116  }
117  if($this->filter["fromto"]["to"])
118  {
119  $filter["to"] = $this->filter["fromto"]["to"]->get(IL_CAL_UNIX);
120  }
121  }
122  return $filter;
123  }
124 
129  function getItems(array $filter)
130  {
131  global $lng;
132 
133  $this->determineOffsetAndOrder();
134 
135  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
136  $data = ilBookingReservation::getList(ilBookingObject::getByPoolId($this->pool->getId()), $this->getLimit(), $this->getOffset(), $filter);
137 
138  $this->setMaxCount($data['counter']);
139  $this->setData($data['data']);
140  }
141 
146  protected function fillRow($a_set)
147  {
148  global $lng, $ilAccess, $ilCtrl, $ilUser;
149 
150  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
151  $this->tpl->setVariable("RESERVATION_ID", $a_set["booking_reservation_id"]);
152 
153  $date_from = new ilDateTime($a_set['date_from'], IL_CAL_UNIX);
154  $date_to = new ilDateTime($a_set['date_to'], IL_CAL_UNIX);
155 
157  {
158  $this->tpl->setVariable("TXT_STATUS", $lng->txt('book_reservation_status_'.$a_set['status']));
159  }
160 
161  $this->tpl->setVariable("TXT_CURRENT_USER", ilObjUser::_lookupFullName($a_set['user_id']));
162 
163  $ilCtrl->setParameter($this->parent_obj, 'user_id', $a_set['user_id']);
164  $this->tpl->setVariable("HREF_PROFILE", $ilCtrl->getLinkTarget($this->parent_obj, 'showprofile'));
165  $ilCtrl->setParameter($this->parent_obj, 'user_id', '');
166 
167  $this->tpl->setVariable("VALUE_DATE", ilDatePresentation::formatPeriod($date_from, $date_to));
168 
169  if ($date_from->get(IL_CAL_UNIX) > time())
170  {
171  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
172  $alist = new ilAdvancedSelectionListGUI();
173  $alist->setId($a_set['booking_reservation_id']);
174  $alist->setListTitle($lng->txt("actions"));
175 
176  $ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
177 
178  if($ilAccess->checkAccess('write', '', $this->ref_id))
179  {
180  if($a_set['status'] == ilBookingReservation::STATUS_CANCELLED)
181  {
182  /*
183  // can be uncancelled?
184  if(ilBookingReservation::getAvailableObject(array($a_set['object_id']), $date_from->get(IL_CAL_UNIX), $date_to->get(IL_CAL_UNIX)))
185  {
186  $alist->addItem($lng->txt('book_set_not_cancel'), 'not_cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvUncancel'));
187  }
188  */
189  }
190  else if($a_set['status'] != ilBookingReservation::STATUS_IN_USE)
191  {
192  $alist->addItem($lng->txt('book_set_in_use'), 'in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvInUse'));
193  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvCancel'));
194  }
195  else
196  {
197  $alist->addItem($lng->txt('book_set_not_in_use'), 'not_in_use', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvNotInUse'));
198  }
199  }
200  else if($a_set['user_id'] == $ilUser->getId() && $a_set['status'] != ilBookingReservation::STATUS_CANCELLED)
201  {
202  $alist->addItem($lng->txt('book_set_cancel'), 'cancel', $ilCtrl->getLinkTarget($this->parent_obj, 'rsvCancel'));
203  }
204 
205  $this->tpl->setVariable('LAYER', $alist->getHTML());
206  }
207  }
208 }
209 
210 ?>