ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
15{
19 protected $access;
20
24 protected $user;
25
26 protected $ref_id; // [int]
27 protected $pool_id; // [int]
28 protected $has_schedule; // [bool]
29 protected $may_edit; // [bool]
30 protected $overall_limit; // [int]
31 protected $reservations = array(); // [array]
32 protected $current_bookings; // [int]
33 protected $advmd; // [array]
34 protected $filter; // [array]
35
45 public function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule, $a_pool_overall_limit)
46 {
47 global $DIC;
48
49 $this->ctrl = $DIC->ctrl();
50 $this->lng = $DIC->language();
51 $this->access = $DIC->access();
52 $this->user = $DIC->user();
53 $ilCtrl = $DIC->ctrl();
54 $lng = $DIC->language();
55 $ilAccess = $DIC->access();
56
57 $this->ref_id = $a_ref_id;
58 $this->pool_id = $a_pool_id;
59 $this->has_schedule = $a_pool_has_schedule;
60 $this->overall_limit = $a_pool_overall_limit;
61 $this->may_edit = $ilAccess->checkAccess('write', '', $this->ref_id);
62
63 $this->advmd = ilObjBookingPool::getAdvancedMDFields($this->ref_id);
64
65 $this->setId("bkobj");
66
67 parent::__construct($a_parent_obj, $a_parent_cmd);
68
69 $this->setTitle($lng->txt("book_objects_list"));
70
71 // $this->setLimit(9999);
72
73 $this->addColumn($this->lng->txt("title"), "title");
74
75 $cols = $this->getSelectableColumns();
76 foreach ($this->getSelectedColumns() as $col) {
77 $this->addColumn($cols[$col]["txt"], $col);
78 }
79
80 if (!$this->has_schedule) {
81 $this->addColumn($this->lng->txt("available"));
82 }
83
84 $this->addColumn($this->lng->txt("actions"));
85
86 $this->setEnableHeader(true);
87 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
88 $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
89
90 $this->initFilter();
91 $this->getItems();
92 }
93
99 protected function getAdvMDRecordGUI()
100 {
101 // #16827
102 return $this->record_gui;
103 }
104
105 public function initFilter()
106 {
108
109 /*
110 // preset period from parameters, e.g. course period
111 // currently NOT active
112 if(trim($_GET["pf"]) ||
113 trim($_GET["pt"]))
114 {
115 $_SESSION["form_".$this->getId()]["period"] = serialize(array(
116 "from" => $_GET["pf"]
117 ? serialize(new ilDateTime(trim($_GET["pf"]), IL_CAL_DATE))
118 : "",
119 "to" => $_GET["pt"]
120 ? serialize(new ilDateTime(trim($_GET["pt"]), IL_CAL_DATE))
121 : "",
122 ));
123 }
124 */
125
126 // title/description
128 "title",
130 false,
131 $lng->txt("title") . "/" . $lng->txt("description")
132 );
133 $this->filter["title"] = $title->getValue();
134
135 // #18651
136 if ($this->has_schedule) {
137 // booking period
138 $period = $this->addFilterItemByMetaType(
139 "period",
141 false,
142 $lng->txt("book_period")
143 );
144 $this->filter["period"] = $period->getValue();
145 }
146 }
147
151 public function getItems()
152 {
154
155 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
156 $data = ilBookingObject::getList($this->pool_id, $this->filter["title"]);
157
158 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
159 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
160
161 // check schedule availability
162 if ($this->has_schedule) {
163 $now = time();
164 $limit = strtotime("+1year");
165 foreach ($data as $idx => $item) {
166 $schedule = new ilBookingSchedule($item["schedule_id"]);
167 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
168 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
169 : null;
170 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
171 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
172 : null;
173 if (($av_from && $av_from > $limit) ||
174 ($av_to && $av_to < $now)) {
175 unset($data[$idx]);
176 }
177 if ($av_from > $now) {
178 $data[$idx]["not_yet"] = ilDatePresentation::formatDate(new ilDate($av_from, IL_CAL_UNIX));
179 }
180 if ($av_to) {
181 // #18658
182 if (!ilBookingReservation::isObjectAvailableInPeriod($item["booking_object_id"], $schedule, $av_from, $av_to)) {
183 $this->lng->loadLanguageModule("dateplaner");
184 $data[$idx]["full_up"] = $this->lng->txt("cal_booked_out");
185 }
186 }
187 }
188 }
189
190 foreach ($data as $item) {
191 $item_id = $item["booking_object_id"];
192
193 // available for given period?
194 if (is_object($this->filter["period"]["from"]) ||
195 is_object($this->filter["period"]["to"])) {
196 $from = is_object($this->filter["period"]["from"])
197 ? strtotime($this->filter["period"]["from"]->get(IL_CAL_DATE) . " 00:00:00")
198 : null;
199 $to = is_object($this->filter["period"]["to"])
200 ? strtotime($this->filter["period"]["to"]->get(IL_CAL_DATE) . " 23:59:59")
201 : null;
202
203 $bobj = new ilBookingObject($item_id);
204 $schedule = new ilBookingSchedule($bobj->getScheduleId());
205
206 if (!ilBookingReservation::isObjectAvailableInPeriod($item_id, $schedule, $from, $to)) {
207 unset($data[$idx]);
208 continue;
209 }
210 }
211
212 // cache reservations
213 $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
214 $this->reservations[$item_id] = $item_rsv["data"];
215 }
216
217 if (!$this->has_schedule &&
218 $this->overall_limit) {
219 $this->current_bookings = 0;
220 foreach ($this->reservations as $obj_rsv) {
221 foreach ($obj_rsv as $item) {
222 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
223 if ($item["user_id"] == $ilUser->getId()) {
224 $this->current_bookings++;
225 }
226 }
227 }
228 }
229
230 if ($this->current_bookings >= $this->overall_limit) {
231 ilUtil::sendInfo($this->lng->txt("book_overall_limit_warning"));
232 }
233 }
234
235 if ($this->advmd) {
236 // advanced metadata
237 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
238 $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_FILTER, "book", $this->pool_id, "bobj");
239 $this->record_gui->setTableGUI($this);
240 $this->record_gui->parse();
241
242 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
244 $this->ref_id,
245 "book",
246 "bobj",
247 $this->pool_id,
248 "bobj",
249 $data,
250 "pool_id",
251 "booking_object_id",
252 $this->record_gui->getFilterElements()
253 );
254 }
255
256 $this->setMaxCount(sizeof($data));
257 $this->setData($data);
258 }
259
260 public function numericOrdering($a_field)
261 {
262 if (substr($a_field, 0, 3) == "md_") {
263 $md_id = (int) substr($a_field, 3);
264 if ($this->advmd[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
265 return true;
266 }
267 }
268 return false;
269 }
270
271 public function getSelectableColumns()
272 {
273 $cols = array();
274
275 $cols["description"] = array(
276 "txt" => $this->lng->txt("description"),
277 "default" => true
278 );
279
280 foreach ($this->advmd as $field) {
281 $cols["advmd" . $field["id"]] = array(
282 "txt" => $field["title"],
283 "default" => false
284 );
285 }
286
287 return $cols;
288 }
289
294 protected function fillRow($a_set)
295 {
299
300 $has_booking = false;
301 $booking_possible = true;
302 $has_reservations = false;
303
304 $selected = $this->getSelectedColumns();
305
306 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
307
308 if (in_array("description", $selected)) {
309 $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
310 }
311
312 if ($a_set["full_up"]) {
313 $this->tpl->setVariable("NOT_YET", $a_set["full_up"]);
314 $booking_possible = false;
315 } elseif ($a_set["not_yet"]) {
316 $this->tpl->setVariable("NOT_YET", $a_set["not_yet"]);
317 }
318
319 if (!$this->has_schedule) {
320 $cnt = 0;
321 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
322 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
323 $cnt++;
324
325 if ($item["user_id"] == $ilUser->getId()) {
326 $has_booking = true;
327 }
328
329 $has_reservations = true;
330 }
331 }
332
333 $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"]-$cnt);
334 $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
335
336 if ($a_set["nr_items"] <= $cnt || $has_booking
337 || ($this->overall_limit && $this->current_bookings && $this->current_bookings >= $this->overall_limit)) {
338 $booking_possible = false;
339 }
340 } elseif (!$this->may_edit) {
341 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
342 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
343 $item["user_id"] == $ilUser->getId()) {
344 $has_booking = true;
345 }
346 }
347 }
348
349 $items = array();
350
351 $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
352
353 if ($booking_possible) {
354 if (is_object($this->filter['period']['from'])) {
355 $ilCtrl->setParameter($this->parent_obj, 'sseed', $this->filter['period']['from']->get(IL_CAL_DATE));
356 }
357
358 $items['book'] = array($lng->txt('book_book'), $ilCtrl->getLinkTarget($this->parent_obj, 'book'));
359
360 $ilCtrl->setParameter($this->parent_obj, 'sseed', '');
361 }
362
363 // #16663
364 if (!$this->has_schedule && $has_booking) {
365 if (trim($a_set['post_text']) || $a_set['post_file']) {
366 $items['post'] = array($lng->txt('book_post_booking_information'), $ilCtrl->getLinkTarget($this->parent_obj, 'displayPostInfo'));
367 }
368
369 $items['cancel'] = array($lng->txt('book_set_cancel'), $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancelUser'));
370 }
371
372 if ($this->may_edit || $has_booking) {
373 $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', $a_set['booking_object_id']);
374 $items['log'] = array($lng->txt('book_log'), $ilCtrl->getLinkTargetByClass('ilObjBookingPoolGUI', 'log'));
375 $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', '');
376 }
377
378 if ($a_set['info_file']) {
379 $items['info'] = array($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
380 }
381
382 if ($this->may_edit) {
383 $items['edit'] = array($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
384
385 // #10890
386 if (!$has_reservations) {
387 $items['delete'] = array($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
388 }
389 }
390
391 if ($this->advmd) {
392 foreach ($this->advmd as $item) {
393 $advmd_id = (int) $item["id"];
394
395 if (!in_array("advmd" . $advmd_id, $selected)) {
396 continue;
397 }
398
399 $val = " ";
400 if (isset($a_set["md_" . $advmd_id . "_presentation"])) {
401 $pb = $a_set["md_" . $advmd_id . "_presentation"]->getList();
402 if ($pb) {
403 $val = $pb;
404 }
405 }
406
407 $this->tpl->setCurrentBlock("advmd_bl");
408 $this->tpl->setVariable("ADVMD_VAL", $val);
409 $this->tpl->parseCurrentBlock();
410 }
411 }
412
413 if (sizeof($items)) {
414 $this->tpl->setCurrentBlock("actions");
415 foreach ($items as $item) {
416 $this->tpl->setVariable("ACTION_CAPTION", $item[0]);
417 $this->tpl->setVariable("ACTION_LINK", $item[1]);
418 $this->tpl->parseCurrentBlock();
419 }
420 }
421 }
422}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
static queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
Query data for given object records.
a bookable ressource
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
List booking objects (for booking type)
getItems()
Gather data and build rows.
getAdvMDRecordGUI()
needed for advmd filter handling
numericOrdering($a_field)
Should this field be sorted numeric?
getSelectableColumns()
Get selectable columns.
__construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule, $a_pool_overall_limit)
Constructor.
static isObjectAvailableInPeriod($a_obj_id, ilBookingSchedule $a_schedule, $a_from, $a_to)
static getList($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
List all reservations.
schedule for booking ressource
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
Class for single dates.
static getAdvancedMDFields($a_ref_id)
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setEnableHeader($a_enableheader)
Set Enable Header.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setMaxCount($a_max_count)
set max.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7
$from
$ilUser
Definition: imgupload.php:18
$cols
Definition: xhr_table.php:11