ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookingObjectsTableGUI.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 $pool_id; // [int]
18  protected $has_schedule; // [bool]
19  protected $may_edit; // [bool]
20 
28  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule)
29  {
30  global $ilCtrl, $lng, $ilAccess;
31 
32  $this->ref_id = $a_ref_id;
33  $this->pool_id = $a_pool_id;
34  $this->has_schedule = $a_pool_has_schedule;
35  $this->may_edit = $ilAccess->checkAccess('write', '', $this->ref_id);
36 
37  $this->setId("bkobj");
38 
39  parent::__construct($a_parent_obj, $a_parent_cmd);
40 
41  $this->setTitle($lng->txt("book_objects_list"));
42 
43  $this->setLimit(9999);
44 
45  $this->addColumn($this->lng->txt("title"), "title");
46  $this->addColumn($this->lng->txt("description"), "description");
47 
48  if(!$this->has_schedule)
49  {
50  $this->addColumn($this->lng->txt("available"));
51  }
52 
53  if ($this->may_edit)
54  {
55  $this->addColumn($this->lng->txt("book_current_user"));
56 
57  if($this->has_schedule)
58  {
59  $this->addColumn($this->lng->txt("book_period"));
60  }
61  }
62 
63  $this->addColumn($this->lng->txt("actions"));
64 
65  $this->setEnableHeader(true);
66  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
67  $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
68 
69  $this->getItems();
70  }
71 
75  function getItems()
76  {
77  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
78  $data = ilBookingObject::getList($this->pool_id);
79 
80  $this->setMaxCount(sizeof($data));
81  $this->setData($data);
82  }
83 
88  protected function fillRow($a_set)
89  {
90  global $lng, $ilCtrl, $ilUser;
91 
92  $has_booking = false;
93  $booking_possible = true;
94  $has_reservations = false;
95 
96  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
97  $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
98 
99  if(!$this->has_schedule)
100  {
101  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
102  $reservation = ilBookingReservation::getList(array($a_set['booking_object_id']), 1000, 0, array());
103  $cnt = 0;
104  $user_ids = array();
105  foreach($reservation["data"] as $item)
106  {
107  if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
108  {
109  $cnt++;
110 
111  // #11995
112  $uname = ilObjUser::_lookupFullName($item['user_id']);
113  if(!trim($uname))
114  {
115  $uname = "[".$lng->txt("user_deleted")."]";
116  }
117  $user_ids[$item["user_id"]] = $uname;
118 
119  if($item["user_id"] == $ilUser->getId())
120  {
121  $has_booking = true;
122  }
123 
124  $has_reservations = true;
125  }
126  }
127 
128  $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"]-$cnt);
129  $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
130 
131  if($a_set["nr_items"] <= $cnt)
132  {
133  $booking_possible = false;
134  }
135 
136  if ($this->may_edit)
137  {
138  if($user_ids)
139  {
140  $this->tpl->setVariable("TXT_CURRENT_USER", implode("<br />", array_unique($user_ids)));
141  }
142  else
143  {
144  $this->tpl->setVariable("TXT_CURRENT_USER", "");
145  }
146  }
147  }
148  else
149  {
150  if ($this->may_edit)
151  {
152  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
153  $reservation = ilBookingReservation::getCurrentOrUpcomingReservation($a_set['booking_object_id']);
154 
155  if($reservation)
156  {
157  $date_from = new ilDateTime($reservation['date_from'], IL_CAL_UNIX);
158  $date_to = new ilDateTime($reservation['date_to'], IL_CAL_UNIX);
159 
160  // #11995
161  $uname = ilObjUser::_lookupFullName($reservation['user_id']);
162  if(!trim($uname))
163  {
164  $uname = "[".$lng->txt("user_deleted")."]";
165  }
166  $this->tpl->setVariable("TXT_CURRENT_USER", $uname);
167  $this->tpl->setVariable("VALUE_DATE", ilDatePresentation::formatPeriod($date_from, $date_to));
168 
169  $has_reservations = true;
170  }
171  else
172  {
173  $this->tpl->setVariable("TXT_CURRENT_USER", "");
174  $this->tpl->setVariable("VALUE_DATE", "");
175  }
176  }
177  }
178 
179 
180  $items = array();
181 
182  $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
183 
184  if(!$has_booking)
185  {
186  if($booking_possible)
187  {
188  $items['book'] = array($lng->txt('book_book'), $ilCtrl->getLinkTarget($this->parent_obj, 'book'));
189  }
190  }
191  else
192  {
193  if(trim($a_set['post_text']) || $a_set['post_file'])
194  {
195  $items['post'] = array($lng->txt('book_post_booking_information'), $ilCtrl->getLinkTarget($this->parent_obj, 'displayPostInfo'));
196  }
197 
198  $items['cancel'] = array($lng->txt('book_set_cancel'), $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancelUser'));
199  }
200 
201  if($a_set['info_file'])
202  {
203  $items['info'] = array($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
204  }
205 
206  if ($this->may_edit)
207  {
208  $items['edit'] = array($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
209 
210  // #10890
211  if(!$has_reservations)
212  {
213  $items['delete'] = array($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
214  }
215  }
216 
217  if(sizeof($items))
218  {
219  $this->tpl->setCurrentBlock("actions");
220  foreach($items as $item)
221  {
222  $this->tpl->setVariable("ACTION_CAPTION", $item[0]);
223  $this->tpl->setVariable("ACTION_LINK", $item[1]);
224  $this->tpl->parseCurrentBlock();
225  }
226  }
227  }
228 }
229 
230 ?>