ILIAS  Release_4_4_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 
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  $this->addColumn($this->lng->txt("actions"));
54 
55  $this->setEnableHeader(true);
56  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
57  $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
58 
59  $this->getItems();
60  }
61 
65  function getItems()
66  {
67  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
68  $data = ilBookingObject::getList($this->pool_id);
69 
70  $this->setMaxCount(sizeof($data));
71  $this->setData($data);
72  }
73 
78  protected function fillRow($a_set)
79  {
80  global $lng, $ilCtrl, $ilUser;
81 
82  $has_booking = false;
83  $booking_possible = true;
84  $has_reservations = false;
85 
86  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
87  $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
88 
89  if(!$this->has_schedule)
90  {
91  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
92  $reservation = ilBookingReservation::getList(array($a_set['booking_object_id']), 1000, 0, array());
93  $cnt = 0;
94  foreach($reservation["data"] as $item)
95  {
96  if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
97  {
98  $cnt++;
99 
100  if($item["user_id"] == $ilUser->getId())
101  {
102  $has_booking = true;
103  }
104 
105  $has_reservations = true;
106  }
107  }
108 
109  $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"]-$cnt);
110  $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
111 
112  if($a_set["nr_items"] <= $cnt || $has_booking)
113  {
114  $booking_possible = false;
115  }
116  }
117  else if(!$this->may_edit)
118  {
119  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
120  $reservation = ilBookingReservation::getList(array($a_set['booking_object_id']), 1000, 0, array());
121  foreach($reservation["data"] as $item)
122  {
123  if($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
124  $item["user_id"] == $ilUser->getId())
125  {
126  $has_booking = true;
127  }
128  }
129  }
130 
131  $items = array();
132 
133  $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
134 
135  if($booking_possible)
136  {
137  $items['book'] = array($lng->txt('book_book'), $ilCtrl->getLinkTarget($this->parent_obj, 'book'));
138  }
139 
140  // #16663
141  if(!$this->has_schedule && $has_booking)
142  {
143  if(trim($a_set['post_text']) || $a_set['post_file'])
144  {
145  $items['post'] = array($lng->txt('book_post_booking_information'), $ilCtrl->getLinkTarget($this->parent_obj, 'displayPostInfo'));
146  }
147 
148  $items['cancel'] = array($lng->txt('book_set_cancel'), $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancelUser'));
149  }
150 
151  if($this->may_edit || $has_booking)
152  {
153  $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', $a_set['booking_object_id']);
154  $items['log'] = array($lng->txt('book_log'), $ilCtrl->getLinkTargetByClass('ilObjBookingPoolGUI', 'log'));
155  $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', '');
156  }
157 
158  if($a_set['info_file'])
159  {
160  $items['info'] = array($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
161  }
162 
163  if ($this->may_edit)
164  {
165  $items['edit'] = array($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
166 
167  // #10890
168  if(!$has_reservations)
169  {
170  $items['delete'] = array($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
171  }
172  }
173 
174  if(sizeof($items))
175  {
176  $this->tpl->setCurrentBlock("actions");
177  foreach($items as $item)
178  {
179  $this->tpl->setVariable("ACTION_CAPTION", $item[0]);
180  $this->tpl->setVariable("ACTION_LINK", $item[1]);
181  $this->tpl->parseCurrentBlock();
182  }
183  }
184  }
185 }
186 
187 ?>