ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
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(); // [array]
22 protected $current_bookings; // [int]
23 protected $advmd; // [array]
24 protected $filter; // [array]
25
35 function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule, $a_pool_overall_limit)
36 {
37 global $ilCtrl, $lng, $ilAccess;
38
39 $this->ref_id = $a_ref_id;
40 $this->pool_id = $a_pool_id;
41 $this->has_schedule = $a_pool_has_schedule;
42 $this->overall_limit = $a_pool_overall_limit;
43 $this->may_edit = $ilAccess->checkAccess('write', '', $this->ref_id);
44
45 $this->advmd = ilObjBookingPool::getAdvancedMDFields($this->pool_id);
46
47 $this->setId("bkobj");
48
49 parent::__construct($a_parent_obj, $a_parent_cmd);
50
51 $this->setTitle($lng->txt("book_objects_list"));
52
53 // $this->setLimit(9999);
54
55 $this->addColumn($this->lng->txt("title"), "title");
56
57 $cols = $this->getSelectableColumns();
58 foreach($this->getSelectedColumns() as $col)
59 {
60 $this->addColumn($cols[$col]["txt"], $col);
61 }
62
63 if(!$this->has_schedule)
64 {
65 $this->addColumn($this->lng->txt("available"));
66 }
67
68 $this->addColumn($this->lng->txt("actions"));
69
70 $this->setEnableHeader(true);
71 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
72 $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
73
74 $this->initFilter();
75 $this->getItems();
76 }
77
83 protected function getAdvMDRecordGUI()
84 {
85 // #16827
86 return $this->record_gui;
87 }
88
89 function initFilter()
90 {
91 global $lng;
92
93 /*
94 // preset period from parameters, e.g. course period
95 // currently NOT active
96 if(trim($_GET["pf"]) ||
97 trim($_GET["pt"]))
98 {
99 $_SESSION["form_".$this->getId()]["period"] = serialize(array(
100 "from" => $_GET["pf"]
101 ? serialize(new ilDateTime(trim($_GET["pf"]), IL_CAL_DATE))
102 : "",
103 "to" => $_GET["pt"]
104 ? serialize(new ilDateTime(trim($_GET["pt"]), IL_CAL_DATE))
105 : "",
106 ));
107 }
108 */
109
110 // title/description
112 "title",
114 false,
115 $lng->txt("title")."/".$lng->txt("description")
116 );
117 $this->filter["title"] = $title->getValue();
118
119 // #18651
120 if($this->has_schedule)
121 {
122 // booking period
123 $period = $this->addFilterItemByMetaType(
124 "period",
126 false,
127 $lng->txt("book_period")
128 );
129 $this->filter["period"] = $period->getValue();
130 }
131 }
132
136 function getItems()
137 {
138 global $ilUser;
139
140 include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
141 $data = ilBookingObject::getList($this->pool_id, $this->filter["title"]);
142
143 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
144 include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
145
146 // check schedule availability
147 if($this->has_schedule)
148 {
149 $now = time();
150 $limit = strtotime("+1year");
151 foreach($data as $idx => $item)
152 {
153 $schedule = new ilBookingSchedule($item["schedule_id"]);
154 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
155 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
156 : null;
157 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
158 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE)." 23:59:59")
159 : null;
160 if(($av_from && $av_from > $limit) ||
161 ($av_to && $av_to < $now))
162 {
163 unset($data[$idx]);
164 }
165 if($av_from > $now)
166 {
167 $data[$idx]["not_yet"] = ilDatePresentation::formatDate(new ilDate($av_from, IL_CAL_UNIX));
168 }
169 if($av_to)
170 {
171 // #18658
172 if(!ilBookingReservation::isObjectAvailableInPeriod($item["booking_object_id"], $schedule, $av_from, $av_to))
173 {
174 $this->lng->loadLanguageModule("dateplaner");
175 $data[$idx]["full_up"] = $this->lng->txt("cal_booked_out");
176 }
177 }
178 }
179 }
180
181 foreach($data as $item)
182 {
183 $item_id = $item["booking_object_id"];
184
185 // available for given period?
186 if(is_object($this->filter["period"]["from"]) ||
187 is_object($this->filter["period"]["to"]))
188 {
189 $from = is_object($this->filter["period"]["from"])
190 ? strtotime($this->filter["period"]["from"]->get(IL_CAL_DATE)." 00:00:00")
191 : null;
192 $to = is_object($this->filter["period"]["to"])
193 ? strtotime($this->filter["period"]["to"]->get(IL_CAL_DATE)." 23:59:59")
194 : null;
195
196 $bobj = new ilBookingObject($item_id);
197 $schedule = new ilBookingSchedule($bobj->getScheduleId());
198
199 if(!ilBookingReservation::isObjectAvailableInPeriod($item_id, $schedule, $from, $to))
200 {
201 unset($data[$idx]);
202 continue;
203 }
204 }
205
206 // cache reservations
207 $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
208 $this->reservations[$item_id] = $item_rsv["data"];
209 }
210
211 if(!$this->has_schedule &&
212 $this->overall_limit)
213 {
214 $this->current_bookings = 0;
215 foreach($this->reservations as $obj_rsv)
216 {
217 foreach($obj_rsv as $item)
218 {
219 if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
220 {
221 if($item["user_id"] == $ilUser->getId())
222 {
223 $this->current_bookings++;
224 }
225 }
226 }
227 }
228
229 if($this->current_bookings >= $this->overall_limit)
230 {
231 ilUtil::sendInfo($this->lng->txt("book_overall_limit_warning"));
232 }
233 }
234
235 if($this->advmd)
236 {
237 // advanced metadata
238 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
239 $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_FILTER, "book", $this->pool_id, "bobj");
240 $this->record_gui->setTableGUI($this);
241 $this->record_gui->parse();
242
243 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
244 $data = ilAdvancedMDValues::queryForRecords($this->pool_id, "bobj", $data, "pool_id", "booking_object_id", $this->record_gui->getFilterElements());
245 }
246
247 $this->setMaxCount(sizeof($data));
248 $this->setData($data);
249 }
250
251 function numericOrdering($a_field)
252 {
253 if (substr($a_field, 0, 3) == "md_")
254 {
255 $md_id = (int) substr($a_field, 3);
256 if ($this->advmd[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE)
257 {
258 return true;
259 }
260 }
261 return false;
262 }
263
265 {
266 $cols = array();
267
268 $cols["description"] = array(
269 "txt" => $this->lng->txt("description"),
270 "default" => true
271 );
272
273 foreach($this->advmd as $field)
274 {
275 $cols["advmd".$field["id"]] = array(
276 "txt" => $field["title"],
277 "default" => false
278 );
279 }
280
281 return $cols;
282 }
283
288 protected function fillRow($a_set)
289 {
290 global $lng, $ilCtrl, $ilUser;
291
292 $has_booking = false;
293 $booking_possible = true;
294 $has_reservations = false;
295
296 $selected = $this->getSelectedColumns();
297
298 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
299
300 if(in_array("description", $selected))
301 {
302 $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
303 }
304
305 if($a_set["full_up"])
306 {
307 $this->tpl->setVariable("NOT_YET", $a_set["full_up"]);
308 $booking_possible = false;
309 }
310 else if($a_set["not_yet"])
311 {
312 $this->tpl->setVariable("NOT_YET", $a_set["not_yet"]);
313 }
314
315 if(!$this->has_schedule)
316 {
317 $cnt = 0;
318 foreach($this->reservations[$a_set["booking_object_id"]] as $item)
319 {
320 if($item["status"] != ilBookingReservation::STATUS_CANCELLED)
321 {
322 $cnt++;
323
324 if($item["user_id"] == $ilUser->getId())
325 {
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 {
339 $booking_possible = false;
340 }
341 }
342 else if(!$this->may_edit)
343 {
344 foreach($this->reservations[$a_set["booking_object_id"]] as $item)
345 {
346 if($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
347 $item["user_id"] == $ilUser->getId())
348 {
349 $has_booking = true;
350 }
351 }
352 }
353
354 $items = array();
355
356 $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
357
358 if($booking_possible)
359 {
360 if(is_object($this->filter['period']['from']))
361 {
362 $ilCtrl->setParameter($this->parent_obj, 'sseed', $this->filter['period']['from']->get(IL_CAL_DATE));
363 }
364
365 $items['book'] = array($lng->txt('book_book'), $ilCtrl->getLinkTarget($this->parent_obj, 'book'));
366
367 $ilCtrl->setParameter($this->parent_obj, 'sseed', '');
368 }
369
370 // #16663
371 if(!$this->has_schedule && $has_booking)
372 {
373 if(trim($a_set['post_text']) || $a_set['post_file'])
374 {
375 $items['post'] = array($lng->txt('book_post_booking_information'), $ilCtrl->getLinkTarget($this->parent_obj, 'displayPostInfo'));
376 }
377
378 $items['cancel'] = array($lng->txt('book_set_cancel'), $ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmCancelUser'));
379 }
380
381 if($this->may_edit || $has_booking)
382 {
383 $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', $a_set['booking_object_id']);
384 $items['log'] = array($lng->txt('book_log'), $ilCtrl->getLinkTargetByClass('ilObjBookingPoolGUI', 'log'));
385 $ilCtrl->setParameterByClass('ilObjBookingPoolGUI', 'object_id', '');
386 }
387
388 if($a_set['info_file'])
389 {
390 $items['info'] = array($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
391 }
392
393 if ($this->may_edit)
394 {
395 $items['edit'] = array($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
396
397 // #10890
398 if(!$has_reservations)
399 {
400 $items['delete'] = array($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
401 }
402 }
403
404 if($this->advmd)
405 {
406 foreach ($this->advmd as $item)
407 {
408 $advmd_id = (int)$item["id"];
409
410 if(!in_array("advmd".$advmd_id, $selected))
411 {
412 continue;
413 }
414
415 $val = " ";
416 if(isset($a_set["md_".$advmd_id."_presentation"]))
417 {
418 $pb = $a_set["md_".$advmd_id."_presentation"]->getList();
419 if($pb)
420 {
421 $val = $pb;
422 }
423 }
424
425 $this->tpl->setCurrentBlock("advmd_bl");
426 $this->tpl->setVariable("ADVMD_VAL", $val);
427 $this->tpl->parseCurrentBlock();
428 }
429 }
430
431 if(sizeof($items))
432 {
433 $this->tpl->setCurrentBlock("actions");
434 foreach($items as $item)
435 {
436 $this->tpl->setVariable("ACTION_CAPTION", $item[0]);
437 $this->tpl->setVariable("ACTION_LINK", $item[1]);
438 $this->tpl->parseCurrentBlock();
439 }
440 }
441 }
442}
443
444?>
const IL_CAL_DATE
const IL_CAL_UNIX
static queryForRecords($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)
Format a date @access public.
Class for single dates.
static getAdvancedMDFields($a_glossary_id)
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setEnableHeader($a_enableheader)
Set Enable Header.
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.
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.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=NULL)
Add filter by standard type.
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 $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15