ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBookingProcessWithScheduleGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\BookingManager\Access\AccessManager $access;
26 protected ilLogger $log;
27 protected \ILIAS\BookingManager\BookingProcess\ObjectSelectionManager $object_selection;
28 protected \ILIAS\BookingManager\Objects\ObjectsManager $object_manager;
29 protected \ILIAS\BookingManager\Reservations\ReservationManager $reservation;
30 protected \ILIAS\BookingManager\BookingProcess\ProcessUtilGUI $util_gui;
31 protected \ILIAS\BookingManager\InternalRepoService $repo;
32 protected \ILIAS\BookingManager\BookingProcess\BookingProcessManager $process;
33 protected \ILIAS\HTTP\Services $http;
34 protected \ILIAS\BookingManager\InternalGUIService $gui;
35 protected array $raw_post_data;
36 protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
38 protected int $booking_object_id;
39 protected int $user_id_to_book;
40 protected int $user_id_assigner;
41 protected string $seed;
43 protected int $context_obj_id;
44 protected ilCtrl $ctrl;
46 protected ilLanguage $lng;
48 protected ilObjUser $user;
49 protected int $book_obj_id;
50 protected array $rsv_ids = [];
51 protected ?string $origin_cmd = null;
52
53 public function __construct(
56 string $seed = "",
57 int $context_obj_id = 0
58 ) {
59 global $DIC;
60
61 $this->ctrl = $DIC->ctrl();
62 $this->tpl = $DIC["tpl"];
63 $this->lng = $DIC->language();
64 $this->tabs_gui = $DIC->tabs();
65 $this->user = $DIC->user();
66 $this->http = $DIC->http();
67
68 $this->context_obj_id = $context_obj_id;
69
70 $this->book_obj_id = $booking_object_id;
71
72 $this->pool = $pool;
73
74 $this->seed = $seed;
75 $internal_service = $DIC->bookingManager()->internal();
76 $this->gui = $internal_service->gui();
77 $domain = $internal_service->domain();
78 $this->book_request = $this->gui->standardRequest();
79 $this->help = $this->gui->bookingHelp($pool);
80 $this->log = $domain->log();
81
82 $this->repo = $internal_service->repo();
83
84 $this->object_manager = $domain->objects($pool->getId());
85 $this->object_selection = $domain->objectSelection($pool->getId());
86
87 $this->rsv_ids = $this->book_request->getReservationIdsFromString();
88
89 $this->raw_post_data = $DIC->http()->request()->getParsedBody();
90
91 $this->user_id_assigner = $this->user->getId();
92 if ($this->book_request->getBookedUser() > 0) {
93 $this->user_id_to_book = $this->book_request->getBookedUser();
94 } else {
95 $this->user_id_to_book = $this->user_id_assigner; // by default user books his own booking objects.
96 }
97 $this->ctrl->saveParameter($this, ["bkusr", "returnCmd"]);
98 $this->ctrl->setParameter($this, "seed", $this->seed);
99
100 $this->process = $DIC->bookingManager()->internal()->domain()->process();
101 $this->reservation = $DIC->bookingManager()->internal()->domain()->reservations();
102 $this->util_gui = $DIC->bookingManager()->internal()->gui()->process()->ProcessUtilGUI(
103 $this->pool,
104 $this
105 );
106 $this->access = $DIC->bookingManager()->internal()->domain()->access();
107 }
108
109 public function executeCommand(): void
110 {
112
113 $next_class = $ctrl->getNextClass($this);
114 $cmd = $ctrl->getCmd("show");
115 switch ($next_class) {
116 default:
117 if (in_array($cmd, array("book", "back", "week",
118 "assignParticipants",
119 "bookMultipleParticipants",
120 "saveMultipleBookings",
121 "showNumberForm",
122 "processNumberForm",
123 "checkAvailability",
124 "displayPostInfo",
125 "bookAvailableItems",
126 "deliverPostFile",
127 "selectObjects",
128 "redirectToParticipantsList"
129 ))) {
130 $this->$cmd();
131 }
132 }
133 }
134
135 protected function showNoPermission(): void
136 {
137 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_permission"), true);
138 $this->back();
139 }
140
141 //
142 // Step 0 / week view
143 //
144
148 public function week(): void // ok
149 {
151 $this->log->debug("Step 0, week");
152
153 //$this->tabs_gui->clearTargets();
154 //$this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'back'));
155
156 $this->util_gui->setHelpId("week");
157 $this->ctrl->setParameter($this, 'returnCmd', "week");
158
159 if ($this->user_id_to_book !== $this->user_id_assigner) {
160 $this->ctrl->setParameter($this, 'bkusr', $this->user_id_to_book);
161 }
162 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
163
164 $week_gui = new \ILIAS\BookingManager\BookingProcess\WeekGUI(
165 $this,
166 "week",
167 $this->object_selection->getSelectedObjects(),
168 $this->pool->getId(),
169 $this->seed,
170 $user_settings->getWeekStart()
171 );
172 $tpl->setContent($week_gui->getHTML());
173
174 $book_week = $this->lng->txt('book_week');
175 $mode_control = $this->gui->ui()->factory()->viewControl()->mode(
176 [
177 $this->lng->txt('book_table') => $this->ctrl->getLinkTargetByClass(ilObjBookingPoolGUI::class, 'render'),
178 $book_week => $this->ctrl->getLinkTarget($this, 'week')
179 ],
180 $this->lng->txt('book_view')
181 )->withActive($book_week);
182 $this->gui->toolbar()->addComponent($mode_control);
183
184 $list_gui = new \ILIAS\BookingManager\BookingProcess\ObjectSelectionListGUI(
185 $this->pool->getId(),
186 $this->ctrl->getFormAction($this, "selectObjects")
187 );
188 $tpl->setRightContent($list_gui->render());
189 }
190
191 protected function selectObjects(): void
192 {
193 $this->log->debug("selectObjects");
194 $obj_ids = $this->book_request->getObjectIds();
195 $this->object_selection->setSelectedObjects($obj_ids);
196 $this->ctrl->redirect($this, "week");
197 }
198
199
200 //
201 // Step 1
202 //
203
204
210 public function book(): void // ok
211 {
212 $this->log->debug("Step 1, book");
214
215 $this->tabs_gui->clearTargets();
216 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'back'));
217
218 $this->util_gui->setHelpId("book");
219
220 $obj = new ilBookingObject($this->book_obj_id);
221
222 $this->lng->loadLanguageModule("dateplaner");
223 $this->ctrl->setParameter($this, 'object_id', $obj->getId());
224 $this->ctrl->setParameter($this, 'returnCmd', 'week');
225
226 if ($this->user_id_to_book !== $this->user_id_assigner) {
227 $this->ctrl->setParameter($this, 'bkusr', $this->user_id_to_book);
228 }
229
230 if (!$this->access->canManageReservationForUser($this->book_request->getRefId(), $this->user_id_to_book)) {
231 return;
232 }
233
234 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
235
236 $week_gui = new \ILIAS\BookingManager\BookingProcess\WeekGUI(
237 $this,
238 "book",
239 [$obj->getId()],
240 $this->pool->getId(),
241 $this->seed,
242 $user_settings->getWeekStart()
243 );
244 $tpl->setContent($week_gui->getHTML());
245 }
246
247 // Table to assign participants to an object.
248 public function assignParticipants(): void
249 {
250 $this->util_gui->assignParticipants($this->book_obj_id);
251 }
252
253 public function showNumberForm(): void
254 {
255 $this->log->debug("showNumberForm");
256 $object_id = $this->book_obj_id;
257 $from = $this->book_request->getSlotFrom();
258 $to = $this->book_request->getSlotTo() - 1;
259 $this->tabs_gui->clearTargets();
260 $this->tabs_gui->setBackTarget(
261 $this->lng->txt('book_back_to_list'),
262 $this->ctrl->getLinkTarget($this, 'back')
263 );
264 $form = $this->getNumberForm($from, $to);
265 $this->gui->modal($this->getBookgingObjectTitle())
266 ->form($form)
267 ->send();
268 }
269
270 protected function getBookgingObjectTitle(): string
271 {
272 return (new ilBookingObject($this->book_obj_id))->getTitle();
273 }
274
275
280 protected function getNumberForm(
281 int $from,
282 int $to
283 ): \ILIAS\Repository\Form\FormAdapterGUI {
284 $counter = $this->reservation->getAvailableNr($this->book_request->getObjectId(), $from, $to);
286 new ilDateTime($from, IL_CAL_UNIX),
287 new ilDateTime($to, IL_CAL_UNIX)
288 );
289 $this->ctrl->setParameter($this, "slot", $from . "_" . $to);
290 $form = $this->gui->form([self::class], "processNumberForm")
291 ->asyncModal()
292 ->section(
293 "props",
294 $this->lng->txt("book_confirm_booking_schedule_number_of_objects"),
295 $this->lng->txt("book_confirm_booking_schedule_number_of_objects_info")
296 )
297 ->number("nr", $period, "", 1, 1, $counter)
298 ->radio("recurrence", $this->lng->txt("book_recurrence"), "", "0")
299 ->radioOption("0", $this->lng->txt("book_no_recurrence"))
300 ->radioOption("1", $this->lng->txt("book_book_recurrence"))
301 ->hidden("origin_cmd", $this->book_request->getOriginCmd());
302 if ($this->pool->usesMessages()) {
303 $form = $form->textarea(
304 "message",
305 $this->lng->txt("book_message"),
306 $this->lng->txt("book_message_info")
307 );
308 }
309 return $form;
310 }
311
312 public function processNumberForm(): void
313 {
314 $this->log->debug("processNumberForm");
315 //get the user who will get the booking.
316 if ($this->book_request->getBookedUser() > 0) {
317 $this->user_id_to_book = $this->book_request->getBookedUser();
318 }
319 $slot = $this->book_request->getSlot();
320 $from = $this->book_request->getSlotFrom();
321 $to = $this->book_request->getSlotTo();
322 $obj_id = $this->book_request->getObjectId();
323
324 if ($this->user_id_assigner !== $this->user_id_to_book) {
325 $this->ctrl->setParameterByClass(self::class, "bkusr", $this->user_id_to_book);
326 }
327 $this->ctrl->setParameterByClass(self::class, "slot", $slot);
328
329 // form not valid -> show again
330 $form = $this->getNumberForm($from, $to);
331 if (!$form->isValid()) {
332 $this->gui->modal($this->getBookgingObjectTitle())
333 ->form($form)
334 ->send();
335 }
336
337 $origin_cmd = $form->getData("origin_cmd");
338 if (is_string($origin_cmd) && $origin_cmd !== "") {
339 $this->origin_cmd = $origin_cmd;
340 }
341
342 $message = $this->pool->usesMessages()
343 ? $form->getData("message")
344 : "";
345
346 // recurrence? -> show recurrence form
347 $recurrence = $form->getData("recurrence");
348 if ($recurrence === "1") {
349 if ($this->pool->usesMessages()) {
350 $this->ctrl->setParameterByClass(
351 self::class,
352 "message",
353 rawurlencode($message)
354 );
355 }
356 $this->ctrl->setParameterByClass(self::class, "object_id", $this->book_request->getObjectId());
357 $this->ctrl->setParameterByClass(self::class, "nr", (int) $form->getData("nr"));
358 $form = $this->getRecurrenceForm();
359 $this->gui->modal($this->getBookgingObjectTitle())
360 ->form($form)
361 ->send();
362 }
363 $this->checkAvailability(
364 false,
365 $form->getData("nr"),
367 );
368 }
369
370
371 protected function getRecurrenceForm(): \ILIAS\Repository\Form\FormAdapterGUI
372 {
373 $this->lng->loadLanguageModule("dateplaner");
374 $today = new ilDate(time(), IL_CAL_UNIX);
375 $form = $this->gui->form([self::class], "checkAvailability")
376 ->section(
377 "props",
378 $this->lng->txt("book_confirm_booking_schedule_number_of_objects"),
379 $this->lng->txt("book_confirm_booking_schedule_number_of_objects_info")
380 )
381 ->switch("recurrence", $this->lng->txt("cal_recurrences"), "", "1")
382 ->group("1", $this->lng->txt("cal_weekly"))
383 ->date("until1", $this->lng->txt("cal_repeat_until"), "", $today)
384 ->group("2", $this->lng->txt("r_14"))
385 ->date("until2", $this->lng->txt("cal_repeat_until"), "", $today)
386 ->group("4", $this->lng->txt("r_4_weeks"))
387 ->date("until4", $this->lng->txt("cal_repeat_until"), "", $today)
388 ->end();
389 return $form;
390 }
391
392 public function checkAvailability(
393 bool $incl_recurrence = true,
394 int $nr = 0,
395 string $message = ""
396 ): void {
397 $this->log->debug("checkAvailability");
398 $obj_id = $this->book_request->getObjectId();
399 $from = $this->book_request->getSlotFrom();
400 $to = $this->book_request->getSlotTo();
401 if ($nr === 0) {
402 $nr = $this->book_request->getNr();
403 }
404 if ($message === "" && $this->pool->usesMessages()) {
405 $message = $this->book_request->getMessage();
406 }
407 $recurrence = 0;
408 $until_ts = 0;
409 if ($incl_recurrence) {
410 $form = $this->getRecurrenceForm();
411 // recurrence form not valid -> show again
412 if (!$form->isValid()) {
413 $this->gui->modal($this->getBookgingObjectTitle())
414 ->form($form)
415 ->send();
416 }
417
418 $recurrence = (int) $form->getData("recurrence"); // 1, 2 or 4
419 $until = $form->getData("until" . $recurrence);
420 $until_ts = $until->get(IL_CAL_UNIX);
421 }
422
423 $this->ctrl->saveParameter($this, ["object_id", "slot", "nr"]);
424 if ($this->pool->usesMessages()) {
425 $this->ctrl->setParameter(
426 $this,
427 "message",
428 rawurlencode($message)
429 );
430 }
431 $this->ctrl->setParameter($this, "recurrence", $recurrence);
432 $this->ctrl->setParameter($this, "until", $until_ts);
433 $book_available_target = $this->getBookAvailableTarget(
434 $obj_id,
435 $this->book_request->getSlot(),
436 $recurrence,
437 $nr,
438 $until_ts
439 );
440
441 if ($incl_recurrence) {
442
443 $missing = $this->process->getRecurrenceMissingAvailability(
444 $obj_id,
445 $from,
446 $to,
447 $recurrence,
448 $nr,
449 $until
450 );
451
452 // anything missing? -> send missing message
453 if (count($missing) > 0) {
454 $html = $this->getMissingAvailabilityMessage($missing);
455 $this->gui->modal($this->getBookgingObjectTitle())
456 ->legacy($html)
457 ->button(
458 $this->lng->txt("book_book_available"),
459 $book_available_target,
460 false
461 )
462 ->send();
463 }
464 }
465 $this->gui->send("<script>window.location.href = '" . $book_available_target . "';</script>");
466 }
467
468 protected function getMissingAvailabilityMessage(array $missing): string
469 {
470 $f = $this->gui->ui()->factory();
471 $box = $f->messageBox()->failure($this->lng->txt("book_missing_availability"));
472 $items = array_map(function ($i) {
473 $from = ilDatePresentation::formatDate(new ilDateTime($i["from"], IL_CAL_UNIX));
475 return $from . " - " . $to . " : " . str_replace("$1", $i["missing"], $this->lng->txt("book_missing_items"));
476 }, $missing);
477
478 $list = $f->listing()->unordered($items);
479 return $this->gui->ui()->renderer()->render([$box, $list]);
480 }
481
482 protected function bookAvailableItems(?int $recurrence = null, ?ilDateTime $until = null): void
483 {
484 if (!$this->access->canManageReservationForUser($this->pool->getRefId(), $this->user_id_to_book)) {
485 $this->showNoPermission();
486 return;
487 }
488 $this->log->debug("bookAvailableItems");
489 $obj_id = $this->book_request->getObjectId();
490 $from = $this->book_request->getSlotFrom();
491 $to = $this->book_request->getSlotTo();
492 $nr = $this->book_request->getNr();
493 $message = $this->pool->usesMessages()
494 ? $this->book_request->getMessage()
495 : "";
496 if (is_null($recurrence)) {
497 $recurrence = (int) $this->book_request->getRecurrence();
498 }
499 if (is_null($until)) {
500 if ($this->book_request->getUntil() > 0) {
501 $until = new ilDateTime($this->book_request->getUntil(), IL_CAL_UNIX);
502 }
503 }
504
505 $booked = $this->process->bookAvailableObjects(
506 $obj_id,
507 $this->user_id_to_book,
508 $this->user_id_assigner,
509 $this->context_obj_id,
510 $from,
511 $to,
512 $recurrence,
513 $nr,
514 $until,
516 );
517 if ($booked !== []) {
518 $this->util_gui->handleBookingSuccess($obj_id, 'displayPostInfo', $booked);
519 return;
520 }
521
522 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('book_reservation_failed'), true);
523 $this->util_gui->back();
524 }
525
526 protected function getBookAvailableTarget(
527 int $obj_id,
528 string $slot,
529 int $recurrence,
530 int $nr,
531 int $until
532 ): string {
533 $this->ctrl->setParameter($this, "obj_id", $obj_id);
534 $this->ctrl->setParameter($this, "slot", $slot);
535 $this->ctrl->setParameter($this, "recurrence", $recurrence);
536 $this->ctrl->setParameter($this, "nr", $nr);
537 $this->ctrl->setParameter($this, "until", $until);
538 if (is_string($this->origin_cmd) && $this->origin_cmd !== "") {
539 $this->ctrl->setParameter($this, "origin_cmd", $this->origin_cmd);
540 }
541 return $this->ctrl->getLinkTarget($this, "bookAvailableItems");
542 }
543
544 public function displayPostInfo(): void
545 {
546 $this->util_gui->displayPostInfo(
547 $this->book_obj_id,
548 $this->user_id_assigner,
549 "deliverPostFile"
550 );
551 }
552
553 public function deliverPostFile(): void
554 {
555 $this->util_gui->deliverPostFile(
556 $this->book_obj_id,
557 $this->user_id_assigner
558 );
559 }
560
561 public function back(): void
562 {
563 $this->util_gui->back();
564 }
565}
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS BookingManager StandardGUIRequest $book_request
ILIAS BookingManager Access AccessManager $access
ILIAS BookingManager InternalGUIService $gui
bookAvailableItems(?int $recurrence=null, ?ilDateTime $until=null)
ILIAS BookingManager BookingProcess BookingProcessManager $process
__construct(ilObjBookingPool $pool, int $booking_object_id, string $seed="", int $context_obj_id=0)
checkAvailability(bool $incl_recurrence=true, int $nr=0, string $message="")
ILIAS BookingManager InternalRepoService $repo
ILIAS BookingManager Objects ObjectsManager $object_manager
book()
Triggered from object list week view for booking a single object / confirmation for.
ILIAS BookingManager BookingProcess ObjectSelectionManager $object_selection
ILIAS BookingManager BookingProcess ProcessUtilGUI $util_gui
ILIAS BookingManager Reservations ReservationManager $reservation
getBookAvailableTarget(int $obj_id, string $slot, int $recurrence, int $nr, int $until)
static _getInstanceByUserId(int $a_user_id)
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
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
Class for single dates.
language handling
Component logger with individual log levels by component id.
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...
setRightContent(string $a_html)
Sets content of right column.
setContent(string $a_html)
Sets content for standard template.
static http()
Fetches the global http state from ILIAS.
getObjectId()
Get the object ID of the object that contains the questions.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26