ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
14{
18 protected $access;
19
23 protected $user;
24
25 protected $ref_id; // [int]
26 protected $pool_id; // [int]
27 protected $has_schedule; // [bool]
28 protected $may_edit; // [bool]
29 protected $may_assign; // [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 protected $ui_factory;
36 protected $ui_renderer;
37
42
52 public function __construct(
53 $a_parent_obj,
54 $a_parent_cmd,
55 $a_ref_id,
56 $a_pool_id,
57 $a_pool_has_schedule,
58 $a_pool_overall_limit,
59 bool $active_management = true
60 ) {
61 global $DIC;
62
63 $this->ctrl = $DIC->ctrl();
64 $this->lng = $DIC->language();
65 $this->access = $DIC->access();
66 $this->user = $DIC->user();
67 $ilCtrl = $DIC->ctrl();
68 $lng = $DIC->language();
69 $ilAccess = $DIC->access();
70 $this->ui_factory = $DIC->ui()->factory();
71 $this->ui_renderer = $DIC->ui()->renderer();
72
73 $this->ref_id = $a_ref_id;
74 $this->pool_id = $a_pool_id;
75 $this->has_schedule = $a_pool_has_schedule;
76 $this->overall_limit = $a_pool_overall_limit;
77 $this->active_management = $active_management;
78 $this->may_edit = ($this->active_management &&
79 $ilAccess->checkAccess('write', '', $this->ref_id));
80 $this->may_assign = ($this->active_management &&
81 $ilAccess->checkAccess('write', '', $this->ref_id));
82
83 $this->advmd = ilObjBookingPool::getAdvancedMDFields($this->ref_id);
84
85 $this->setId("bkobj");
86
87 parent::__construct($a_parent_obj, $a_parent_cmd);
88
89 $this->setTitle($lng->txt("book_objects_list"));
90
91 // $this->setLimit(9999);
92
93 $this->addColumn($this->lng->txt("title"), "title");
94
95 $cols = $this->getSelectableColumns();
96 foreach ($this->getSelectedColumns() as $col) {
97 $this->addColumn($cols[$col]["txt"], $col);
98 }
99
100 if (!$this->has_schedule) {
101 $this->addColumn($this->lng->txt("available"));
102 }
103
104 $this->addColumn($this->lng->txt("actions"));
105
106 $this->setEnableHeader(true);
107 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
108 $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
109
110 $this->initFilter();
111 $this->getItems();
112 }
113
119 protected function getAdvMDRecordGUI()
120 {
121 // #16827
122 return $this->record_gui;
123 }
124
125 public function initFilter()
126 {
128
129 // title/description
131 "title",
133 false,
134 $lng->txt("title") . "/" . $lng->txt("description")
135 );
136 $this->filter["title"] = $title->getValue();
137
138 // #18651
139 if ($this->has_schedule) {
140 // booking period
141 $period = $this->addFilterItemByMetaType(
142 "period",
144 false,
145 $lng->txt("book_period")
146 );
147 $this->filter["period"] = $period->getValue();
148 }
149 }
150
154 public function getItems()
155 {
157
158 $data = ilBookingObject::getList($this->pool_id, $this->filter["title"]);
159
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 unset($data[$idx]);
175 }
176 if ($av_from > $now) {
177 $data[$idx]["not_yet"] = ilDatePresentation::formatDate(new ilDate($av_from, IL_CAL_UNIX));
178 }
179 if ($av_to) {
180 // #18658
181 if (!ilBookingReservation::isObjectAvailableInPeriod($item["booking_object_id"], $schedule, $av_from, $av_to)) {
182 $this->lng->loadLanguageModule("dateplaner");
183 $data[$idx]["full_up"] = $this->lng->txt("cal_booked_out");
184 }
185 }
186 }
187 }
188
189 foreach ($data as $idx => $item) {
190 $item_id = $item["booking_object_id"];
191
192 // available for given period?
193 if (is_object($this->filter["period"]["from"]) ||
194 is_object($this->filter["period"]["to"])) {
195 $from = is_object($this->filter["period"]["from"])
196 ? strtotime($this->filter["period"]["from"]->get(IL_CAL_DATE) . " 00:00:00")
197 : null;
198 $to = is_object($this->filter["period"]["to"])
199 ? strtotime($this->filter["period"]["to"]->get(IL_CAL_DATE) . " 23:59:59")
200 : null;
201
202 $bobj = new ilBookingObject($item_id);
203 $schedule = new ilBookingSchedule($bobj->getScheduleId());
204
205 if (!ilBookingReservation::isObjectAvailableInPeriod($item_id, $schedule, $from, $to)) {
206 unset($data[$idx]);
207 continue;
208 }
209 }
210
211 // cache reservations
212 $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
213 $this->reservations[$item_id] = $item_rsv["data"];
214 }
215
216 if (!$this->has_schedule &&
217 $this->overall_limit) {
218 $this->current_bookings = 0;
219 foreach ($this->reservations as $obj_rsv) {
220 foreach ($obj_rsv as $item) {
221 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
222 if ($item["user_id"] == $ilUser->getId()) {
223 $this->current_bookings++;
224 }
225 }
226 }
227 }
228
229 if ($this->current_bookings >= $this->overall_limit) {
230 ilUtil::sendInfo($this->lng->txt("book_overall_limit_warning"));
231 }
232 }
233
234 if ($this->advmd) {
235 // advanced metadata
236 $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_FILTER, "book", $this->pool_id, "bobj");
237 $this->record_gui->setTableGUI($this);
238 $this->record_gui->parse();
239
241 $this->ref_id,
242 "book",
243 "bobj",
244 $this->pool_id,
245 "bobj",
246 $data,
247 "pool_id",
248 "booking_object_id",
249 $this->record_gui->getFilterElements()
250 );
251 }
252
253 $this->setMaxCount(sizeof($data));
254 $this->setData($data);
255 }
256
257 public function numericOrdering($a_field)
258 {
259 if (substr($a_field, 0, 3) == "md_") {
260 $md_id = (int) substr($a_field, 3);
261 if ($this->advmd[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
262 return true;
263 }
264 }
265 return false;
266 }
267
268 public function getSelectableColumns()
269 {
270 $cols = array();
271
272 $cols["description"] = array(
273 "txt" => $this->lng->txt("description"),
274 "default" => true
275 );
276
277 foreach ($this->advmd as $field) {
278 $cols["advmd" . $field["id"]] = array(
279 "txt" => $field["title"],
280 "default" => false
281 );
282 }
283
284 return $cols;
285 }
286
291 protected function fillRow($a_set)
292 {
296
297 $has_booking = false;
298 $booking_possible = true;
299 $assign_possible = true;
300 $has_reservations = false;
301
302 $selected = $this->getSelectedColumns();
303
304 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
305
306 if (in_array("description", $selected)) {
307 $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
308 }
309
310 if ($a_set["full_up"]) {
311 $this->tpl->setVariable("NOT_YET", $a_set["full_up"]);
312 $booking_possible = false;
313 $assign_possible = false;
314 } elseif ($a_set["not_yet"]) {
315 $this->tpl->setVariable("NOT_YET", $a_set["not_yet"]);
316 }
317
318 if (!$this->has_schedule) {
319 $cnt = 0;
320 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
321 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
322 $cnt++;
323
324 if ($item["user_id"] == $ilUser->getId()) {
325 $has_booking = true;
326 }
327
328 $has_reservations = true;
329 }
330 }
331
332 $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"] - $cnt);
333 $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
334
335 if ($a_set["nr_items"] <= $cnt || ($this->overall_limit && $this->current_bookings && $this->current_bookings >= $this->overall_limit)) {
336 $booking_possible = false;
337 }
338 if ($has_booking) {
339 $booking_possible = false;
340 }
341 if ($a_set["nr_items"] <= $cnt) {
342 $assign_possible = false;
343 }
344 } elseif (!$this->may_edit) {
345 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
346 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
347 $item["user_id"] == $ilUser->getId()) {
348 $has_booking = true;
349 }
350 }
351 }
352
353 //Actions
354 $items = array();
355
356 $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
357
358 if ($booking_possible) {
359 if (is_object($this->filter['period']['from'])) {
360 $ilCtrl->setParameter($this->parent_obj, 'sseed', $this->filter['period']['from']->get(IL_CAL_DATE));
361 }
362
363 $items[] = $this->ui_factory->button()->shy(
364 $lng->txt('book_book'),
365 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'book')
366 );
367
368 $ilCtrl->setParameter($this->parent_obj, 'sseed', '');
369 }
370
371 // #16663
372 if (!$this->has_schedule && $has_booking) {
373 if (trim($a_set['post_text']) || $a_set['post_file']) {
374 $items[] = $this->ui_factory->button()->shy(
375 $lng->txt('book_post_booking_information'),
376 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'displayPostInfo')
377 );
378 }
379 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', $a_set['booking_object_id']);
380 $items[] = $this->ui_factory->button()->shy($lng->txt('book_set_cancel'), $ilCtrl->getLinkTargetByClass("ilbookingreservationsgui", 'rsvConfirmCancelUser'));
381 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', "");
382 }
383
384 if ($this->may_edit || $has_booking) {
385 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', $a_set['booking_object_id']);
386 $items[] = $this->ui_factory->button()->shy(
387 $lng->txt('book_log'),
388 $ilCtrl->getLinkTargetByClass('ilBookingReservationsGUI', 'log')
389 );
390 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', '');
391 }
392
393 if ($this->may_assign && $assign_possible) {
394 // note: this call is currently super expensive
395 // see #26388, it has been performed even for users without edit permissions before
396 // now the call has been moved here, but still this needs improvement
397 // EDIT: deactivated for now due to performance reasons
398 //if (!empty(ilBookingParticipant::getAssignableParticipants($a_set["booking_object_id"]))) {
399 if (is_object($this->filter['period']['from'])) {
400 $ilCtrl->setParameterByClass(
401 "ilbookingprocessgui",
402 'sseed',
403 $this->filter['period']['from']->get(IL_CAL_DATE)
404 );
405 }
406
407 $items[] = $this->ui_factory->button()->shy(
408 $lng->txt('book_assign_participant'),
409 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'assignParticipants')
410 );
411
412 $ilCtrl->setParameterByClass("ilbookingprocessgui", 'sseed', '');
413 //}
414 }
415
416 if ($a_set['info_file']) {
417 $items[] = $this->ui_factory->button()->shy($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
418 }
419
420 if ($this->may_edit) {
421 $items[] = $this->ui_factory->button()->shy($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
422
423 // #10890
424 if (!$has_reservations) {
425 $items[] = $this->ui_factory->button()->shy($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
426 }
427 }
428
429 if ($this->advmd) {
430 foreach ($this->advmd as $item) {
431 $advmd_id = (int) $item["id"];
432
433 if (!in_array("advmd" . $advmd_id, $selected)) {
434 continue;
435 }
436
437 $val = " ";
438 if (isset($a_set["md_" . $advmd_id . "_presentation"])) {
439 $pb = $a_set["md_" . $advmd_id . "_presentation"]->getList();
440 if ($pb) {
441 $val = $pb;
442 }
443 }
444
445 $this->tpl->setCurrentBlock("advmd_bl");
446 $this->tpl->setVariable("ADVMD_VAL", $val);
447 $this->tpl->parseCurrentBlock();
448 }
449 }
450
451 if (sizeof($items)) {
452 $actions_dropdown = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt('actions'));
453 $this->tpl->setVariable("ACTION_DROPDOWN", $this->ui_renderer->render($actions_dropdown));
454 }
455 }
456}
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
__construct( $a_parent_obj, $a_parent_cmd, $a_ref_id, $a_pool_id, $a_pool_has_schedule, $a_pool_overall_limit, bool $active_management=true)
Constructor.
numericOrdering($a_field)
Should this field be sorted numeric?
getSelectableColumns()
Get selectable columns.
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, $include_seconds=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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46
$cols
Definition: xhr_table.php:11