ILIAS  Release_5_0_x_branch Revision 61816
 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  protected $overall_limit; // [int]
21  protected $reservations; // [array]
22  protected $current_bookings; // [int]
23 
33  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule, $a_pool_overall_limit)
34  {
35  global $ilCtrl, $lng, $ilAccess;
36 
37  $this->ref_id = $a_ref_id;
38  $this->pool_id = $a_pool_id;
39  $this->has_schedule = $a_pool_has_schedule;
40  $this->overall_limit = $a_pool_overall_limit;
41  $this->may_edit = $ilAccess->checkAccess('write', '', $this->ref_id);
42 
43  $this->setId("bkobj");
44 
45  parent::__construct($a_parent_obj, $a_parent_cmd);
46 
47  $this->setTitle($lng->txt("book_objects_list"));
48 
49  $this->setLimit(9999);
50 
51  $this->addColumn($this->lng->txt("title"), "title");
52  $this->addColumn($this->lng->txt("description"), "description");
53 
54  if(!$this->has_schedule)
55  {
56  $this->addColumn($this->lng->txt("available"));
57  }
58 
59  $this->addColumn($this->lng->txt("actions"));
60 
61  $this->setEnableHeader(true);
62  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
63  $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
64 
65  $this->getItems();
66  }
67 
71  function getItems()
72  {
73  global $ilUser;
74 
75  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
76  $data = ilBookingObject::getList($this->pool_id);
77 
78  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
79  foreach($data as $item)
80  {
81  $item_id = $item["booking_object_id"];
82  $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
83  $this->reservations[$item_id] = $item_rsv["data"];
84  }
85 
86  if(!$this->has_schedule &&
87  $this->overall_limit)
88  {
89  $this->current_bookings = 0;
90  foreach($this->reservations as $obj_rsv)
91  {
92  foreach($obj_rsv as $item)
93  {
94  if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
95  {
96  if($item["user_id"] == $ilUser->getId())
97  {
98  $this->current_bookings++;
99  }
100  }
101  }
102  }
103 
104  if($this->current_bookings >= $this->overall_limit)
105  {
106  ilUtil::sendInfo($this->lng->txt("book_overall_limit_warning"));
107  }
108  }
109 
110  $this->setMaxCount(sizeof($data));
111  $this->setData($data);
112  }
113 
118  protected function fillRow($a_set)
119  {
120  global $lng, $ilCtrl, $ilUser;
121 
122  $has_booking = false;
123  $booking_possible = true;
124  $has_reservations = false;
125 
126  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
127  $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
128 
129  if(!$this->has_schedule)
130  {
131  $cnt = 0;
132  foreach($this->reservations[$a_set["booking_object_id"]] as $item)
133  {
134  if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
135  {
136  $cnt++;
137 
138  if($item["user_id"] == $ilUser->getId())
139  {
140  $has_booking = true;
141  }
142 
143  $has_reservations = true;
144  }
145  }
146 
147  $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"]-$cnt);
148  $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
149 
150  if($a_set["nr_items"] <= $cnt || $has_booking
151  || ($this->overall_limit && $this->current_bookings && $this->current_bookings >= $this->overall_limit))
152  {
153  $booking_possible = false;
154  }
155  }
156  else if(!$this->may_edit)
157  {
158  foreach($this->reservations[$a_set["booking_object_id"]] as $item)
159  {
160  if($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
161  $item["user_id"] == $ilUser->getId())
162  {
163  $has_booking = true;
164  }
165  }
166  }
167 
168  $items = array();
169 
170  $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
171 
172  if($booking_possible)
173  {
174  $items['book'] = array($lng->txt('book_book'), $ilCtrl->getLinkTarget($this->parent_obj, 'book'));
175  }
176 
177  // #16663
178  if(!$this->has_schedule && $has_booking)
179  {
180  if(trim($a_set['post_text']) || $a_set['post_file'])
181  {
182  $items['post'] = array($lng->txt('book_post_booking_information'), $ilCtrl->getLinkTarget($this->parent_obj, 'displayPostInfo'));
183  }
184 
185  $items['cancel'] = array($lng->txt('book_set_cancel'), $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancelUser'));
186  }
187 
188  if($this->may_edit || $has_booking)
189  {
190  $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', $a_set['booking_object_id']);
191  $items['log'] = array($lng->txt('book_log'), $ilCtrl->getLinkTargetByClass('ilObjBookingPoolGUI', 'log'));
192  $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', '');
193  }
194 
195  if($a_set['info_file'])
196  {
197  $items['info'] = array($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
198  }
199 
200  if ($this->may_edit)
201  {
202  $items['edit'] = array($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
203 
204  // #10890
205  if(!$has_reservations)
206  {
207  $items['delete'] = array($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
208  }
209  }
210 
211  if(sizeof($items))
212  {
213  $this->tpl->setCurrentBlock("actions");
214  foreach($items as $item)
215  {
216  $this->tpl->setVariable("ACTION_CAPTION", $item[0]);
217  $this->tpl->setVariable("ACTION_LINK", $item[1]);
218  $this->tpl->parseCurrentBlock();
219  }
220  }
221  }
222 }
223 
224 ?>