ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBookingReservationsGUI.php
Go to the documentation of this file.
1<?php
2
30
32{
33 public const string DEFAULT_CMD = 'log';
34
38 protected UIServices $ui;
40 protected array $raw_post_data;
43 protected ?int $context_obj_id;
44 protected ilCtrl $ctrl;
46 protected ilLanguage $lng;
48 protected ilObjUser $user;
50 protected int $ref_id;
51 protected int $book_obj_id;
52 protected string $reservation_id; // see BookingReservationDBRepo, obj_user_(slot)_context
53 protected int $booked_user;
55
57 {
58 global $DIC;
59
60 $this->tpl = $DIC->ui()->mainTemplate();
61 $this->pool = $pool;
62 $this->ctrl = $DIC->ctrl();
63 $this->ref_id = $pool->getRefId();
64 $this->lng = $DIC->language();
65 $this->access = $DIC->bookingManager()->internal()->domain()->access();
66 $this->tabs_gui = $DIC->tabs();
67 $this->help = $help;
68 $this->user = $DIC->user();
69 $this->book_request = $DIC->bookingManager()->internal()->gui()->standardRequest();
70 $this->service = $DIC->bookingManager()->internal();
71 $this->ui = $DIC->ui();
72 $this->toolbar = $DIC->toolbar();
73 $this->ui_service = $DIC->uiservice();
74
75 $this->book_obj_id = $this->book_request->getObjectId();
76
77 $this->context_obj_id = $context_obj_id;
78
79 $this->booked_user = $this->book_request->getBookedUser();
80 if ($this->booked_user === 0) {
81 $this->booked_user = $DIC->user()->getId();
82 }
83 $this->reservation_id = $this->book_request->getReservationId();
84
85 $this->ctrl->saveParameter($this, ['object_id', 'bkusr']);
86
87 if ($this->book_request->getObjectId() > 0 && ilBookingObject::lookupPoolId($this->book_request->getObjectId()) !== $this->pool->getId()) {
88 throw new ilException('Booking Object ID does not match Booking Pool.');
89 }
90
91 $this->raw_post_data = $DIC->http()->request()->getParsedBody();
92 $this->util_gui = $DIC
93 ->bookingManager()
94 ->internal()
95 ->gui()
96 ->process()
97 ->ProcessUtilGUI($this->pool, $this);
98 }
99
100 protected function getLogReservationIds(): array
101 {
102 $reservation_ids = $this->book_request->getReservationIds();
103 if ($reservation_ids !== []) {
104 return $reservation_ids;
105 }
106
107 return $this->reservation_id > 0 ? [$this->reservation_id] : [];
108 }
109
110 public function executeCommand(): void
111 {
112 $cmd = $this->ctrl->getCmd(self::DEFAULT_CMD);
113 if ($cmd === '') {
114 $cmd = self::DEFAULT_CMD;
115 }
116
117 $cmds = [
119 'executeTableAction',
120 'changeStatusObject',
121 'back',
122 'confirmResetRun',
123 'resetRun',
124 'displayPostInfo',
125 'deliverPostFile'
126 ];
127 if (in_array($cmd, $cmds, true)) {
128 $this->$cmd();
129 }
130 }
131
132 protected function setHelpId(string $a_id): void
133 {
134 $this->help->setHelpId($a_id);
135 }
136
137 private function getBookingsTable(): BookingsTable
138 {
139 global $DIC;
140
142 $booking_table_class = $this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE
143 ? BookingsWithScheduleTable::class
144 : BookingsWithoutScheduleTable::class;
145
146 return new $booking_table_class(
147 $this->ui->factory(),
148 $this->ui->renderer(),
149 $this->access,
150 $this->tpl,
151 $DIC->refinery(),
152 $this->lng,
153 new HttpService($DIC->http(), $DIC->refinery()),
154 $this->user,
155 $DIC->bookingManager()->internal()->repo()->reservation(),
156 $this->ctrl,
157 $DIC->uiService(),
158 $this->service->domain()->bookingSettings()->getByObjId($this->pool->getId()),
159 $this->pool
160 );
161 }
162
164 {
165 return new URLBuilder((new Factory())->uri(
166 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(self::class, 'executeTableAction')
167 ));
168 }
169
170 private function presetBookingsFilterFromRequest(): void
171 {
172 $object_id = $this->book_request->getObjectId();
173 if ($object_id <= 0) {
174 return;
175 }
176
177 $filter_id = $this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE
178 ? BookingsWithScheduleTable::ID . '_filter'
179 : BookingsWithoutScheduleTable::ID . '_filter';
180
181 $gateway = new ilUIFilterServiceSessionGateway();
182 $gateway->writeValue($filter_id, 'object', (string) $object_id);
183 $gateway->writeActivated($filter_id, true);
184 }
185
186 public function log(): void
187 {
189
190 $bookings_table = $this->getBookingsTable();
191 $this->tpl->setContent(
192 $this->ui->renderer()->render(
193 $bookings_table->getComponents($this->getTableActionUrlBuilder())
194 )
195 );
196
197 $reservations_table = new ilBookingReservationsTableGUI(
198 $this,
199 'log',
200 $this->ref_id,
201 $this->pool,
202 $this->access->canManageAllReservations($this->ref_id) || $this->pool->hasPublicLog(),
203 $this->ui_service->filter()->getData($bookings_table->getFilter()) ?? [],
204 null,
205 $this->context_obj_id !== null ? [$this->context_obj_id] : null
206 );
207 $reservations_table->getExportMode() > 0 && $reservations_table->exportData($reservations_table->getExportMode(), true);
208 }
209
210 public function executeTableAction(): void
211 {
212 $this->getBookingsTable()->execute($this->getTableActionUrlBuilder());
213 $this->ctrl->redirectByClass(self::class, 'log');
214 }
215
216 public function changeStatusObject(): void
217 {
218 $rsv_ids = $this->book_request->getReservationIds();
219 if ($rsv_ids === []) {
220 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
221 $this->log();
222 }
223
224 if ($this->access->canManageAllReservations($this->ref_id)) {
225 ilBookingReservation::changeStatus($rsv_ids, $this->book_request->getStatus());
226 }
227
228 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
229 $this->log();
230 }
231
232 protected function back(): void
233 {
234 $this->ctrl->redirect($this, 'log');
235 }
236
237 protected function showRerunPreferenceAssignment(): void
238 {
239 if (
240 !$this->access->canManageAllReservations($this->ref_id)
241 || $this->pool->getScheduleType() !== ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES
242 ) {
243 return;
244 }
245
246 if ($this->service->domain()->preferences($this->pool)->hasRun()) {
247 $this->toolbar->addComponent($this->ui->factory()->button()->standard(
248 $this->lng->txt('book_rerun_assignments'),
249 $this->ctrl->getLinkTarget($this, 'confirmResetRun')
250 ));
251 }
252 }
253
254 protected function confirmResetRun(): void
255 {
256 if (!$this->access->canManageAllReservations($this->ref_id)) {
257 return;
258 }
259
260 $this->tabs_gui->activateTab('log');
261 $mess = $this->ui->factory()->messageBox()->confirmation($this->lng->txt('book_rerun_confirmation'))->withButtons(
262 [
263 $this->ui->factory()->button()->standard($this->lng->txt('book_rerun_assignments'), $this->ctrl->getLinkTarget($this, 'resetRun')),
264 $this->ui->factory()->button()->standard($this->lng->txt('cancel'), $this->ctrl->getLinkTarget($this, 'log'))
265 ]
266 );
267 $this->tpl->setContent($this->ui->renderer()->render($mess));
268 }
269
270 protected function resetRun(): void
271 {
272 if (!$this->access->canManageAllReservations($this->ref_id)) {
273 return;
274 }
275
276 if (
277 $this->pool->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES
278 && $this->access->canManageAllReservations($this->pool->getRefId())
279 ) {
280 $pref_manager = $this->service->domain()->preferences($this->pool);
281 $repo = $this->service->repo()->preferences();
282 $pref_manager->resetRun();
283 $pref_manager->storeBookings($repo->getPreferences($this->pool->getId()));
284 }
285 $this->ctrl->redirect($this, 'log');
286 }
287
288 public function displayPostInfo(): void
289 {
290 $this->ctrl->saveParameter($this, 'object_id');
291 $this->util_gui->displayPostInfo($this->book_obj_id, 0, 'deliverPostFile');
292 }
293
294 public function deliverPostFile(): void
295 {
296 $this->util_gui->deliverPostFile($this->book_obj_id, $this->user->getId());
297 }
298}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupPoolId(int $object_id)
static changeStatus(array $a_ids, int $a_status)
Batch update reservation status.
__construct(ilObjBookingPool $pool, ilBookingHelpAdapter $help, ?int $context_obj_id=null)
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Filter service.
global $DIC
Definition: shib_login.php:26