ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookableItemWithoutScheduleTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
28{
29 public const string ID = 'bkbiwos';
30
34 protected function getColumns(): array
35 {
36 $column_factory = $this->ui_factory->table()->column();
37 return [
38 'availability' => $column_factory->text($this->lng->txt('book_table_col_availability'))->withIsSortable(true),
39 'title' => $column_factory->text($this->lng->txt('title'))->withIsSortable(true),
40 'description' => $column_factory->text($this->lng->txt('description'))->withIsSortable(true),
41 ];
42 }
43
47 protected function getFilterInputs(): array
48 {
49 $bookable_items = [];
50 foreach (ilBookingObject::getList($this->pool->getId()) as $item) {
51 $bookable_items[(int) $item['booking_object_id']] = (string) $item['title'];
52 }
53
54 $field_factory = $this->ui_factory->input()->field();
55 return [
56 'title' => $field_factory->text($this->lng->txt('title')),
57 'description' => $field_factory->text($this->lng->txt('description')),
58 'objects' => $field_factory->multiSelect($this->lng->txt('book_filter_objects'), $bookable_items),
59 ];
60 }
61
65 protected function loadRecords(mixed $filter_data): array
66 {
67 $filter_data = is_array($filter_data) ? $filter_data : [];
68
69 $title_filter = trim((string) ($filter_data['title'] ?? '')) ?: null;
70 $description_filter = trim((string) ($filter_data['description'] ?? '')) ?: null;
71 $object_ids_filter = ($filter_data['objects'] ?? []) !== []
72 ? array_map('intval', $filter_data['objects'])
73 : null;
74
75 $rows = [];
76 foreach ($this->loadFilteredBookingObjects($title_filter, $description_filter, $object_ids_filter) as $item) {
77 $object_id = (int) $item['booking_object_id'];
79 $user_has_booking = false;
80 $user_has_active_booking = false;
81
82 foreach ($this->getReservationsForObject($object_id) as $reservation) {
83 $user_id = (int) $reservation['user_id'];
84 if ($user_id !== $this->user->getId()) {
85 continue;
86 }
87
88 $user_has_booking = true;
89
90 if ($reservation['status'] === ilBookingReservation::STATUS_CANCELLED) {
91 continue;
92 }
93
94 $user_has_active_booking = true;
95 break;
96 }
97
98 $rows[] = [
99 'row_id' => (string) $object_id,
100 'booking_object_id' => $object_id,
101 'title' => (string) $item['title'],
102 'description' => (string) ($item['description'] ?? ''),
103 'nr_items' => (int) $item['nr_items'],
104 'available' => $available,
105 'is_available' => $available > 0,
106 'has_user_booking' => $user_has_booking,
107 'has_user_active_booking' => $user_has_active_booking,
108 'has_reservations' => $this->hasActiveReservations($object_id),
109 'post_text' => (string) ($item['post_text'] ?? ''),
110 ];
111 }
112
113 return $rows;
114 }
115
119 protected function buildRowCells(array $record): array
120 {
121 return [
122 'availability' => $this->buildAvailabilityCell((int) $record['available'], (int) $record['nr_items']),
123 'title' => (string) $record['title'],
124 'description' => nl2br((string) $record['description']),
125 ];
126 }
127
128 private function hasActiveReservations(int $object_id): bool
129 {
130 return array_any(
131 $this->getReservationsForObject($object_id),
132 static fn(array $reservation): bool => $reservation['status'] !== ilBookingReservation::STATUS_CANCELLED
133 );
134 }
135}
loadFilteredBookingObjects(?string $title_filter, ?string $description_filter, ?array $object_ids_filter)
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...
static numAvailableFromObjectNoSchedule(int $a_obj_id)
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28