ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingObjectsTableGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected string $process_class;
26 protected \ILIAS\BookingManager\Access\AccessManager $access;
27 protected \ILIAS\UI\Renderer $ui_renderer;
28 protected \ILIAS\UI\Factory $ui_factory;
29 protected ilObjUser $user;
30 protected int $ref_id;
31 protected int $pool_id;
32 protected bool $has_schedule;
33 protected bool $may_edit;
34 protected bool $may_assign;
35 protected ?int $overall_limit = null;
36 protected array $reservations = array();
37 protected int $current_bookings;
38 protected array $advmd;
39 protected array $filter;
41 protected bool $active_management;
42 protected \ilGlobalTemplateInterface $main_tpl;
43
44 public function __construct(
45 object $a_parent_obj,
46 string $a_parent_cmd,
47 int $a_ref_id,
48 int $a_pool_id,
49 bool $a_pool_has_schedule,
50 ?int $a_pool_overall_limit,
51 bool $active_management = true
52 ) {
53 global $DIC;
54 $this->main_tpl = $DIC->ui()->mainTemplate();
55
56 $this->ctrl = $DIC->ctrl();
57 $this->lng = $DIC->language();
58 $this->access = $DIC->bookingManager()->internal()->domain()->access();
59 $this->user = $DIC->user();
60 $ilCtrl = $DIC->ctrl();
61 $lng = $DIC->language();
62 $ilAccess = $DIC->access();
63 $this->ui_factory = $DIC->ui()->factory();
64 $this->ui_renderer = $DIC->ui()->renderer();
65
66 $this->ref_id = $a_ref_id;
67 $this->pool_id = $a_pool_id;
68 $this->has_schedule = $a_pool_has_schedule;
69 $this->overall_limit = $a_pool_overall_limit;
70 $this->active_management = $active_management;
71 $this->may_edit = ($this->active_management &&
72 $this->access->canManageObjects($this->ref_id));
73 $this->may_assign = ($this->active_management &&
74 $this->access->canManageAllReservations($this->ref_id));
75
76 $this->advmd = ilObjBookingPool::getAdvancedMDFields($this->ref_id);
77
78 $this->setId("bkobj");
79
80 parent::__construct($a_parent_obj, $a_parent_cmd);
81
82 $this->setTitle($lng->txt("book_booking_objects"));
83
84 // $this->setLimit(9999);
85
86 $this->addColumn($this->lng->txt("title"), "title");
87
88 $cols = $this->getSelectableColumns();
89 foreach ($this->getSelectedColumns() as $col) {
90 $this->addColumn($cols[$col]["txt"], $col);
91 }
92
93 if (!$this->has_schedule) {
94 $this->addColumn($this->lng->txt("available"));
95 }
96
97 $this->addColumn($this->lng->txt("actions"));
98
99 $this->setEnableHeader(true);
100 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
101 $this->setRowTemplate("tpl.booking_object_row.html", "components/ILIAS/BookingManager");
102 $this->process_class = $DIC->bookingManager()
103 ->internal()
104 ->gui()
105 ->process()
106 ->getProcessClass($a_pool_has_schedule);
107
108 $this->initFilter();
109 $this->getItems();
110 }
111
116 {
117 // #16827
118 return $this->record_gui;
119 }
120
121 public function initFilter(): void
122 {
124
125 // title/description
127 "title",
129 false,
130 $lng->txt("title") . "/" . $lng->txt("description")
131 );
132 if ($title !== null) {
133 $this->filter["title"] = $title->getValue();
134 }
135
136 // #18651
137 if ($this->has_schedule) {
138 // booking period
139 $period = $this->addFilterItemByMetaType(
140 "period",
142 false,
143 $lng->txt("book_period")
144 );
145 if ($period !== null) {
146 $this->filter["period"] = $period->getValue();
147 }
148 }
149 }
150
151 public function getItems(): void
152 {
153 $ilUser = $this->user;
154
155 $data = ilBookingObject::getList($this->pool_id, $this->filter["title"]);
156 // check schedule availability
157 if ($this->has_schedule) {
158 $now = time();
159 $limit = strtotime("+1year");
160 foreach ($data as $idx => $item) {
161 $schedule = new ilBookingSchedule($item["schedule_id"]);
162 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
163 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
164 : null;
165 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
166 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
167 : null;
168 if (($av_from && $av_from > $limit)) {
169 unset($data[$idx]);
170 }
171 if ($av_from > $now) {
172 $data[$idx]["not_yet"] = ilDatePresentation::formatDate(new ilDate($av_from, IL_CAL_UNIX));
173 }
174 if ($av_to) {
175 // #18658
176 if (!ilBookingReservation::isObjectAvailableInPeriod($item["booking_object_id"], $schedule, $av_from, $av_to)) {
177 $this->lng->loadLanguageModule("dateplaner");
178 $data[$idx]["full_up"] = $this->lng->txt("cal_booked_out");
179 }
180 }
181 }
182 }
183
184 foreach ($data as $idx => $item) {
185 $item_id = $item["booking_object_id"];
186
187 // available for given period?
188 if (isset($this->filter["period"]["from"]) ||
189 isset($this->filter["period"]["to"])) {
190 $from = is_object($this->filter["period"]["from"])
191 ? strtotime($this->filter["period"]["from"]->get(IL_CAL_DATE) . " 00:00:00")
192 : null;
193 $to = is_object($this->filter["period"]["to"])
194 ? strtotime($this->filter["period"]["to"]->get(IL_CAL_DATE) . " 23:59:59")
195 : null;
196
197 $bobj = new ilBookingObject($item_id);
198 $schedule = new ilBookingSchedule($bobj->getScheduleId());
199
200 if (!ilBookingReservation::isObjectAvailableInPeriod($item_id, $schedule, $from, $to)) {
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 $this->current_bookings = 0;
214 foreach ($this->reservations as $obj_rsv) {
215 foreach ($obj_rsv as $item) {
216 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
217 if ($item["user_id"] == $ilUser->getId()) {
218 $this->current_bookings++;
219 }
220 }
221 }
222 }
223
224 if ($this->current_bookings >= $this->overall_limit) {
225 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_overall_limit_warning"));
226 }
227 }
228 if ($this->advmd) {
229 // advanced metadata
230 $this->record_gui = new ilAdvancedMDRecordGUI(
232 "book",
233 $this->pool_id,
234 "bobj"
235 );
236 $this->record_gui->setTableGUI($this);
237 $this->record_gui->parse();
238
240 $this->ref_id,
241 "book",
242 "bobj",
243 [$this->pool_id],
244 "bobj",
245 $data,
246 "pool_id",
247 "booking_object_id",
248 $this->record_gui->getFilterElements()
249 );
250 }
251
252 $this->setMaxCount(count($data));
253 $this->setData($data);
254 }
255
256 public function numericOrdering(string $a_field): bool
257 {
258 if (str_starts_with($a_field, "md_")) {
259 $md_id = (int) substr($a_field, 3);
260 if ($this->advmd[$md_id]["type"] === ilAdvancedMDFieldDefinition::TYPE_DATE) {
261 return true;
262 }
263 }
264 return false;
265 }
266
267 public function getSelectableColumns(): array
268 {
269 $cols = array();
270
271 $cols["description"] = array(
272 "txt" => $this->lng->txt("description"),
273 "default" => true
274 );
275
276 foreach ($this->advmd as $field) {
277 $cols["advmd" . $field["id"]] = array(
278 "txt" => $field["title"],
279 "default" => false
280 );
281 }
282
283 return $cols;
284 }
285
286 protected function fillRow(array $a_set): void
287 {
289 $ilCtrl = $this->ctrl;
290 $ilUser = $this->user;
291
292 $has_booking = false;
293 $booking_possible = $this->access->canManageOwnReservations($this->ref_id);
294 $assign_possible = true;
295 $has_reservations = false;
296
297 $selected = $this->getSelectedColumns();
298
299 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
300
301 if (in_array("description", $selected, true)) {
302 $this->tpl->setVariable("TXT_DESC", nl2br($a_set["description"] ?? ""));
303 }
304
305 if (isset($a_set["full_up"])) {
306 $this->tpl->setVariable("NOT_YET", $a_set["full_up"]);
307 $booking_possible = false;
308 $assign_possible = false;
309 } elseif (isset($a_set["not_yet"])) {
310 $this->tpl->setVariable("NOT_YET", $a_set["not_yet"]);
311 }
312
313 if (!$this->has_schedule) {
314 $cnt = 0;
315 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
316 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED) {
317 $cnt++;
318
319 if ($item["user_id"] == $ilUser->getId()) {
320 $has_booking = true;
321 }
322
323 $has_reservations = true;
324 }
325 }
326
327 $this->tpl->setVariable("VALUE_AVAIL", $a_set["nr_items"] - $cnt);
328 $this->tpl->setVariable("VALUE_AVAIL_ALL", $a_set["nr_items"]);
329
330 if ($a_set["nr_items"] <= $cnt || ($this->overall_limit && $this->current_bookings && $this->current_bookings >= $this->overall_limit)) {
331 $booking_possible = false;
332 }
333 if ($has_booking) {
334 $booking_possible = false;
335 }
336 if ($a_set["nr_items"] <= $cnt) {
337 $assign_possible = false;
338 }
339 } elseif (!$this->may_edit) {
340 foreach ($this->reservations[$a_set["booking_object_id"]] as $item) {
341 if ($item["status"] != ilBookingReservation::STATUS_CANCELLED &&
342 $item["user_id"] == $ilUser->getId()) {
343 $has_booking = true;
344 }
345 }
346 }
347
348 //Actions
349 $items = array();
350
351 $ilCtrl->setParameter($this->parent_obj, 'object_id', $a_set['booking_object_id']);
352
353 if ($booking_possible) {
354 if (isset($this->filter['period']['from'])) {
355 $ilCtrl->setParameter($this->parent_obj, 'sseed', $this->filter['period']['from']->get(IL_CAL_DATE));
356 }
357
358 $items[] = $this->ui_factory->button()->shy(
359 $lng->txt('book_book'),
360 $ilCtrl->getLinkTargetByClass($this->process_class, 'book')
361 );
362
363 $ilCtrl->setParameter($this->parent_obj, 'sseed', '');
364 }
365
366 if ($has_booking || $this->may_edit) {
367 if (trim($a_set['post_text'] ?? "") || $a_set['post_file']) {
368 $items[] = $this->ui_factory->button()->shy(
369 $lng->txt('book_post_booking_information'),
370 $ilCtrl->getLinkTargetByClass($this->process_class, 'displayPostInfo')
371 );
372 }
373 }
374
375 // #16663
376 if (!$this->has_schedule && $has_booking) {
377 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', $a_set['booking_object_id']);
378 $items[] = $this->ui_factory->button()->shy($lng->txt('book_set_cancel'), $ilCtrl->getLinkTargetByClass("ilbookingreservationsgui", 'rsvConfirmCancelUser'));
379 $ilCtrl->setParameterByClass("ilbookingreservationsgui", 'object_id', "");
380 }
381
382 if ($this->may_edit || $has_booking) {
383 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', $a_set['booking_object_id']);
384 $items[] = $this->ui_factory->button()->shy(
385 $lng->txt('book_log'),
386 $ilCtrl->getLinkTargetByClass('ilBookingReservationsGUI', 'log')
387 );
388 $ilCtrl->setParameterByClass('ilBookingReservationsGUI', 'object_id', '');
389 }
390
391 if ($this->may_assign && $assign_possible) {
392 // note: this call is currently super expensive
393 // see #26388, it has been performed even for users without edit permissions before
394 // now the call has been moved here, but still this needs improvement
395 // EDIT: deactivated for now due to performance reasons
396 //if (!empty(ilBookingParticipant::getAssignableParticipants($a_set["booking_object_id"]))) {
397 if (isset($this->filter['period']['from'])) {
398 $ilCtrl->setParameterByClass(
399 $this->process_class,
400 'sseed',
401 $this->filter['period']['from']->get(IL_CAL_DATE)
402 );
403 }
404
405 $items[] = $this->ui_factory->button()->shy(
406 $lng->txt('book_assign_participant'),
407 $ilCtrl->getLinkTargetByClass($this->process_class, 'assignParticipants')
408 );
409
410 $ilCtrl->setParameterByClass($this->process_class, 'sseed', '');
411 //}
412 }
413
414 if ($a_set['obj_info_rid']) {
415 $items[] = $this->ui_factory->button()->shy($lng->txt('book_download_info'), $ilCtrl->getLinkTarget($this->parent_obj, 'deliverInfo'));
416 }
417
418 if ($this->may_edit) {
419 $items[] = $this->ui_factory->button()->shy($lng->txt('edit'), $ilCtrl->getLinkTarget($this->parent_obj, 'edit'));
420
421 // #10890
422 if (!$has_reservations) {
423 $items[] = $this->ui_factory->button()->shy($lng->txt('delete'), $ilCtrl->getLinkTarget($this->parent_obj, 'confirmDelete'));
424 }
425 }
426
427 if ($this->advmd) {
428 foreach ($this->advmd as $item) {
429 $advmd_id = (int) $item["id"];
430
431 if (!in_array("advmd" . $advmd_id, $selected)) {
432 continue;
433 }
434
435 $val = " ";
436 $key = "md_" . $advmd_id . "_presentation";
437 if (isset($a_set[$key])) {
438 $pb = $a_set[$key]->getList();
439 if ($pb) {
440 $val = $pb;
441 }
442 }
443
444 $this->tpl->setCurrentBlock("advmd_bl");
445 $this->tpl->setVariable("ADVMD_VAL", $val);
446 $this->tpl->parseCurrentBlock();
447 }
448 }
449
450 if (count($items)) {
451 $actions_dropdown = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt('actions'));
452 $this->tpl->setVariable("ACTION_DROPDOWN", $this->ui_renderer->render($actions_dropdown));
453 }
454 }
455}
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
ILIAS BookingManager Access AccessManager $access
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, ?ilObjUser $user=null,)
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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26