ILIAS  release_8 Revision v8.24
class.ilBookingObjectsTableGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\UI\Renderer $ui_renderer;
26 protected \ILIAS\UI\Factory $ui_factory;
28 protected ilObjUser $user;
29 protected int $ref_id;
30 protected int $pool_id;
31 protected bool $has_schedule;
32 protected bool $may_edit;
33 protected bool $may_assign;
34 protected ?int $overall_limit = null;
35 protected array $reservations = array();
36 protected int $current_bookings;
37 protected array $advmd;
38 protected array $filter;
40 protected bool $active_management;
41 protected \ilGlobalTemplateInterface $main_tpl;
42
43 public function __construct(
44 object $a_parent_obj,
45 string $a_parent_cmd,
46 int $a_ref_id,
47 int $a_pool_id,
48 bool $a_pool_has_schedule,
49 ?int $a_pool_overall_limit,
50 bool $active_management = true
51 ) {
52 global $DIC;
53 $this->main_tpl = $DIC->ui()->mainTemplate();
54
55 $this->ctrl = $DIC->ctrl();
56 $this->lng = $DIC->language();
57 $this->access = $DIC->access();
58 $this->user = $DIC->user();
59 $ilCtrl = $DIC->ctrl();
60 $lng = $DIC->language();
61 $ilAccess = $DIC->access();
62 $this->ui_factory = $DIC->ui()->factory();
63 $this->ui_renderer = $DIC->ui()->renderer();
64
65 $this->ref_id = $a_ref_id;
66 $this->pool_id = $a_pool_id;
67 $this->has_schedule = $a_pool_has_schedule;
68 $this->overall_limit = $a_pool_overall_limit;
69 $this->active_management = $active_management;
70 $this->may_edit = ($this->active_management &&
71 $ilAccess->checkAccess('write', '', $this->ref_id));
72 $this->may_assign = ($this->active_management &&
73 $ilAccess->checkAccess('write', '', $this->ref_id));
74
75 $this->advmd = ilObjBookingPool::getAdvancedMDFields($this->ref_id);
76
77 $this->setId("bkobj");
78
79 parent::__construct($a_parent_obj, $a_parent_cmd);
80
81 $this->setTitle($lng->txt("book_booking_objects"));
82
83 // $this->setLimit(9999);
84
85 $this->addColumn($this->lng->txt("title"), "title");
86
87 $cols = $this->getSelectableColumns();
88 foreach ($this->getSelectedColumns() as $col) {
89 $this->addColumn($cols[$col]["txt"], $col);
90 }
91
92 if (!$this->has_schedule) {
93 $this->addColumn($this->lng->txt("available"));
94 }
95
96 $this->addColumn($this->lng->txt("actions"));
97
98 $this->setEnableHeader(true);
99 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
100 $this->setRowTemplate("tpl.booking_object_row.html", "Modules/BookingManager");
101
102 $this->initFilter();
103 $this->getItems();
104 }
105
110 {
111 // #16827
112 return $this->record_gui;
113 }
114
115 public function initFilter(): void
116 {
118
119 // title/description
121 "title",
123 false,
124 $lng->txt("title") . "/" . $lng->txt("description")
125 );
126 if ($title !== null) {
127 $this->filter["title"] = $title->getValue();
128 }
129
130 // #18651
131 if ($this->has_schedule) {
132 // booking period
133 $period = $this->addFilterItemByMetaType(
134 "period",
136 false,
137 $lng->txt("book_period")
138 );
139 if ($period !== null) {
140 $this->filter["period"] = $period->getValue();
141 }
142 }
143 }
144
145 public function getItems(): void
146 {
148
149 $data = ilBookingObject::getList($this->pool_id, $this->filter["title"]);
150
151
152 // check schedule availability
153 if ($this->has_schedule) {
154 $now = time();
155 $limit = strtotime("+1year");
156 foreach ($data as $idx => $item) {
157 $schedule = new ilBookingSchedule($item["schedule_id"]);
158 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
159 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
160 : null;
161 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
162 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
163 : null;
164 if (($av_from && $av_from > $limit)) {
165 unset($data[$idx]);
166 }
167 if ($av_from > $now) {
168 $data[$idx]["not_yet"] = ilDatePresentation::formatDate(new ilDate($av_from, IL_CAL_UNIX));
169 }
170 if ($av_to) {
171 // #18658
172 if (!ilBookingReservation::isObjectAvailableInPeriod($item["booking_object_id"], $schedule, $av_from, $av_to)) {
173 $this->lng->loadLanguageModule("dateplaner");
174 $data[$idx]["full_up"] = $this->lng->txt("cal_booked_out");
175 }
176 }
177 }
178 }
179
180 foreach ($data as $idx => $item) {
181 $item_id = $item["booking_object_id"];
182
183 // available for given period?
184 if (isset($this->filter["period"]["from"]) ||
185 isset($this->filter["period"]["to"])) {
186 $from = is_object($this->filter["period"]["from"])
187 ? strtotime($this->filter["period"]["from"]->get(IL_CAL_DATE) . " 00:00:00")
188 : null;
189 $to = is_object($this->filter["period"]["to"])
190 ? strtotime($this->filter["period"]["to"]->get(IL_CAL_DATE) . " 23:59:59")
191 : null;
192
193 $bobj = new ilBookingObject($item_id);
194 $schedule = new ilBookingSchedule($bobj->getScheduleId());
195
196 if (!ilBookingReservation::isObjectAvailableInPeriod($item_id, $schedule, $from, $to)) {
197 unset($data[$idx]);
198 continue;
199 }
200 }
201
202 // cache reservations
203 $item_rsv = ilBookingReservation::getList(array($item_id), 1000, 0, array());
204 $this->reservations[$item_id] = $item_rsv["data"];
205 }
206
207 if (!$this->has_schedule &&
208 $this->overall_limit) {
209 $this->current_bookings = 0;
210 foreach ($this->reservations as $obj_rsv) {
211 foreach ($obj_rsv as $item) {
212 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
213 if ($item["user_id"] == $ilUser->getId()) {
214 $this->current_bookings++;
215 }
216 }
217 }
218 }
219
220 if ($this->current_bookings >= $this->overall_limit) {
221 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_overall_limit_warning"));
222 }
223 }
224 if ($this->advmd) {
225 // advanced metadata
226 $this->record_gui = new ilAdvancedMDRecordGUI(
228 "book",
229 $this->pool_id,
230 "bobj"
231 );
232 $this->record_gui->setTableGUI($this);
233 $this->record_gui->parse();
234
236 $this->ref_id,
237 "book",
238 "bobj",
239 [$this->pool_id],
240 "bobj",
241 $data,
242 "pool_id",
243 "booking_object_id",
244 $this->record_gui->getFilterElements()
245 );
246 }
247
248 $this->setMaxCount(count($data));
249 $this->setData($data);
250 }
251
252 public function numericOrdering(string $a_field): bool
253 {
254 if (str_starts_with($a_field, "md_")) {
255 $md_id = (int) substr($a_field, 3);
256 if ($this->advmd[$md_id]["type"] === ilAdvancedMDFieldDefinition::TYPE_DATE) {
257 return true;
258 }
259 }
260 return false;
261 }
262
263 public function getSelectableColumns(): array
264 {
265 $cols = array();
266
267 $cols["description"] = array(
268 "txt" => $this->lng->txt("description"),
269 "default" => true
270 );
271
272 foreach ($this->advmd as $field) {
273 $cols["advmd" . $field["id"]] = array(
274 "txt" => $field["title"],
275 "default" => false
276 );
277 }
278
279 return $cols;
280 }
281
282 protected function fillRow(array $a_set): void
283 {
285 $ilCtrl = $this->ctrl;
287
288 $has_booking = false;
289 $booking_possible = true;
290 $assign_possible = true;
291 $has_reservations = false;
292
293 $selected = $this->getSelectedColumns();
294
295 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
296
297 if (in_array("description", $selected, true)) {
298 $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"]));
299 }
300
301 if (isset($a_set["full_up"])) {
302 $this->tpl->setVariable("NOT_YET", $a_set["full_up"]);
303 $booking_possible = false;
304 $assign_possible = false;
305 } elseif (isset($a_set["not_yet"])) {
306 $this->tpl->setVariable("NOT_YET", $a_set["not_yet"]);
307 }
308
309 if (!$this->has_schedule) {
310 $cnt = 0;
311 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
312 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
313 $cnt++;
314
315 if ($item["user_id"] == $ilUser->getId()) {
316 $has_booking = true;
317 }
318
319 $has_reservations = true;
320 }
321 }
322
323 $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"] - $cnt);
324 $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
325
326 if ($a_set["nr_items"] <= $cnt || ($this->overall_limit && $this->current_bookings && $this->current_bookings >= $this->overall_limit)) {
327 $booking_possible = false;
328 }
329 if ($has_booking) {
330 $booking_possible = false;
331 }
332 if ($a_set["nr_items"] <= $cnt) {
333 $assign_possible = false;
334 }
335 } elseif (!$this->may_edit) {
336 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
337 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
338 $item["user_id"] == $ilUser->getId()) {
339 $has_booking = true;
340 }
341 }
342 }
343
344 //Actions
345 $items = array();
346
347 $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
348
349 if ($booking_possible) {
350 if (isset($this->filter['period']['from'])) {
351 $ilCtrl->setParameter($this->parent_obj, 'sseed', $this->filter['period']['from']->get(IL_CAL_DATE));
352 }
353
354 $items[] = $this->ui_factory->button()->shy(
355 $lng->txt('book_book'),
356 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'book')
357 );
358
359 $ilCtrl->setParameter($this->parent_obj, 'sseed', '');
360 }
361
362 if ($has_booking || $this->may_edit) {
363 if (trim($a_set['post_text'] ?? "") || $a_set['post_file']) {
364 $items[] = $this->ui_factory->button()->shy(
365 $lng->txt('book_post_booking_information'),
366 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'displayPostInfo')
367 );
368 }
369 }
370
371 // #16663
372 if (!$this->has_schedule && $has_booking) {
373 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', $a_set['booking_object_id']);
374 $items[] = $this->ui_factory->button()->shy($lng->txt('book_set_cancel'), $ilCtrl->getLinkTargetByClass("ilbookingreservationsgui", 'rsvConfirmCancelUser'));
375 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', "");
376 }
377
378 if ($this->may_edit || $has_booking) {
379 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', $a_set['booking_object_id']);
380 $items[] = $this->ui_factory->button()->shy(
381 $lng->txt('book_log'),
382 $ilCtrl->getLinkTargetByClass('ilBookingReservationsGUI', 'log')
383 );
384 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', '');
385 }
386
387 if ($this->may_assign && $assign_possible) {
388 // note: this call is currently super expensive
389 // see #26388, it has been performed even for users without edit permissions before
390 // now the call has been moved here, but still this needs improvement
391 // EDIT: deactivated for now due to performance reasons
392 //if (!empty(ilBookingParticipant::getAssignableParticipants($a_set["booking_object_id"]))) {
393 if (isset($this->filter['period']['from'])) {
394 $ilCtrl->setParameterByClass(
395 "ilbookingprocessgui",
396 'sseed',
397 $this->filter['period']['from']->get(IL_CAL_DATE)
398 );
399 }
400
401 $items[] = $this->ui_factory->button()->shy(
402 $lng->txt('book_assign_participant'),
403 $ilCtrl->getLinkTargetByClass("ilbookingprocessgui", 'assignParticipants')
404 );
405
406 $ilCtrl->setParameterByClass("ilbookingprocessgui", 'sseed', '');
407 //}
408 }
409
410 if ($a_set['info_file']) {
411 $items[] = $this->ui_factory->button()->shy($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
412 }
413
414 if ($this->may_edit) {
415 $items[] = $this->ui_factory->button()->shy($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
416
417 // #10890
418 if (!$has_reservations) {
419 $items[] = $this->ui_factory->button()->shy($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
420 }
421 }
422
423 if ($this->advmd) {
424 foreach ($this->advmd as $item) {
425 $advmd_id = (int) $item["id"];
426
427 if (!in_array("advmd" . $advmd_id, $selected)) {
428 continue;
429 }
430
431 $val = " ";
432 $key = "md_" . $advmd_id . "_presentation";
433 if (isset($a_set[$key])) {
434 $pb = $a_set[$key]->getList();
435 if ($pb) {
436 $val = $pb;
437 }
438 }
439
440 $this->tpl->setCurrentBlock("advmd_bl");
441 $this->tpl->setVariable("ADVMD_VAL", $val);
442 $this->tpl->parseCurrentBlock();
443 }
444 }
445
446 if (count($items)) {
447 $actions_dropdown = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt('actions'));
448 $this->tpl->setVariable("ACTION_DROPDOWN", $this->ui_renderer->render($actions_dropdown));
449 }
450 }
451}
const IL_CAL_DATE
const IL_CAL_UNIX
static queryForRecords(int $adv_rec_obj_ref_id, string $adv_rec_obj_type, string $adv_rec_obj_subtype, array $a_obj_id, string $a_subtype, array $a_records, string $a_obj_id_key, string $a_obj_subid_key, array $a_amet_filter=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAdvMDRecordGUI()
needed for advmd filter handling
numericOrdering(string $a_field)
Should this field be sorted numeric?
fillRow(array $a_set)
Standard Version of Fill Row.
getSelectableColumns()
Get selectable columns.
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id, int $a_pool_id, bool $a_pool_has_schedule, ?int $a_pool_overall_limit, bool $active_management=true)
static isObjectAvailableInPeriod(int $a_obj_id, ilBookingSchedule $a_schedule, ?int $a_from, ?int $a_to)
static getList(array $a_object_ids, int $a_limit=10, int $a_offset=0, array $filter=[])
List all reservations.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
Class for single dates.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getAdvancedMDFields(int $a_ref_id)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
ilLanguage $lng
setMaxCount(int $a_max_count)
set max.
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$cols
Definition: xhr_table.php:11