ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookingsWithScheduleTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use DateTimeImmutable;
24use Generator;
32use ilDateTime;
33
35{
36 public const string ID = 'bkbws';
37
41 private array $schedule_cache = [];
42
43 public function getRows(
44 DataRowBuilder $row_builder,
45 array $visible_column_ids,
47 Order $order,
48 mixed $additional_viewcontrol_data,
49 mixed $filter_data,
50 mixed $additional_parameters
51 ): Generator {
52 $records = $this->limitRecords($range, $this->sortRecords($order, $this->loadRecords($filter_data)));
53
54 foreach ($records as $record) {
55 $user_id = $record['user_id'];
56
57 $record['date_to']++;
58
59 $date_from = new DateTimeImmutable("@{$record['date_from']}");
60 $time_slot = $this->isAllDayBooking($record)
61 ? $this->lng->txt('book_all_day')
63 new ilDateTime($record['date_from'], IL_CAL_UNIX),
64 new ilDateTime($record['date_to'], IL_CAL_UNIX),
65 true
66 );
67
68 yield $this->getTableActions()->onDataRow(
69 $row_builder->buildDataRow(
70 (string) $record['booking_reservation_id'],
71 [
72 'title' => (string) $record['title'],
73 'status' => $record['status'] === ilBookingReservation::STATUS_CANCELLED
74 ? $this->lng->txt('book_reservation_status_5')
75 : '',
76 'date' => $date_from,
77 'week' => $date_from,
78 'weekday' => $date_from,
79 'time_slot' => $time_slot,
80 'unit_count' => 1,
81 'message' => (string) ($record['message'] ?? ''),
82 'user' => $this->getUserComponent($user_id)
83 ]
84 ),
85 $record
86 );
87 }
88 }
89
90 protected function getColumns(): array
91 {
92 $columns = [
93 'title' => $this->column_factory->text($this->lng->txt('title')),
94 'status' => $this->column_factory->text($this->lng->txt('status')),
95 'date' => $this->column_factory->date(
96 $this->lng->txt('date'),
97 new DateFormat([
104 ])
105 ),
106 'week' => $this->column_factory->date($this->lng->txt('week'), new DateFormat([DateFormat::WEEK]))
107 ->withIsOptional(true, true),
108 'weekday' => $this->column_factory->date($this->lng->txt('cal_weekday'), new DateFormat([DateFormat::WEEKDAY_SHORT]))
109 ->withIsOptional(true, true),
110 'time_slot' => $this->column_factory->text($this->lng->txt('book_schedule_slot')),
111 'unit_count' => $this->column_factory->number($this->lng->txt('book_no_of_objects')),
112 'message' => $this->column_factory->text($this->lng->txt('book_message'))->withIsSortable(false),
113 'user' => $this->column_factory->link($this->lng->txt('user'))
114 ];
115
116 if (!$this->booking_pool->usesMessages()) {
117 unset($columns['message']);
118 }
119
120 return $columns;
121 }
122
123 protected function getFilterInputs(): array
124 {
125 $txt_user = $this->lng->txt('user');
126 if (
127 $this->access->canManageAllReservations($this->booking_pool->getRefId())
128 || $this->access->canReadPublicLog($this->booking_pool->getRefId())
129 ) {
130 $user_input = $this->input_factory->select($txt_user, $this->getUsers());
131 } else {
132 $user_input = $this->input_factory
133 ->select($txt_user, $this->getUsers($this->user->getId()))
134 ->withValue($this->user->getId())
135 ->withDisabled(true);
136 }
137
138 return [
139 'object' => $this->input_factory->select(
140 $this->lng->txt('object'),
141 array_column($this->booking_items, 'title', 'booking_object_id')
142 ),
143 'object_title_or_description' => $this->input_factory->text($this->lng->txt('book_object_title_or_description')),
144 'period' => $this->input_factory->duration($this->lng->txt('book_filter_period'))
145 ->withUseTime(true)
146 ->withFormat($this->user->getDateTimeFormat()),
147 'time_slot' => $this->input_factory->select($this->lng->txt('book_schedule_slot'), $this->getTimeSlots()),
148 'past_bookings' => $this->input_factory->select(
149 $this->lng->txt('book_show_past_bookings'),
150 [1 => $this->lng->txt('book_past_bookings'), 2 => $this->lng->txt('book_present_bookings')]
151 ),
152 'status' => $this->input_factory->select($this->lng->txt('status'), $this->getStatuses()),
153 'user' => $user_input
154 ];
155 }
156
160 protected function getTimeSlots(): array
161 {
162 $time_slots = [];
163
164 foreach ($this->bookings as $booking) {
165 $time_slot = $this->getBookingTimeSlotFilterLabel($booking);
166 $time_slots[$time_slot] ??= $time_slot;
167 }
168
169 return $time_slots;
170 }
171
172 protected function getBookingTimeSlotFilterLabel(array $booking): string
173 {
174 return $this->isAllDayBooking($booking)
175 ? $this->lng->txt('book_all_day')
176 : parent::getBookingTimeSlotFilterLabel($booking);
177 }
178
179 private function isAllDayBooking(array $booking): bool
180 {
181 $object_id = (int) $booking['object_id'];
182 $schedule_id = (int) ($this->booking_items[$object_id]['schedule_id'] ?? 0);
183
184 return
185 $schedule_id !== 0
186 && $this->getSchedule($schedule_id)->getScheduleType() === ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY;
187 }
188
189 private function getSchedule(int $schedule_id): ilBookingSchedule
190 {
191 return $this->schedule_cache[$schedule_id] ??= new ilBookingSchedule($schedule_id);
192 }
193}
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:28
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for date presentation.
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
buildDataRow(string $id, array $record)