ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $bar = $this->gui->toolbar();
175 $list_link = $this->ctrl->getLinkTargetByClass("ilObjBookingPoolGUI", "render");
176 $week_link = $this->ctrl->getLinkTargetByClass("ilBookingProcessWithScheduleGUI", "week");
177 $mode_control = $this->gui->ui()->factory()->viewControl()->mode([
178 $this->lng->txt("book_list") => $list_link,
179 $this->lng->txt("book_week") => $week_link
180 ], $this->lng->txt("book_view"))->withActive($this->lng->txt("book_week"));
181 $bar->addComponent($mode_control);
182
183 $list_gui = new \ILIAS\BookingManager\BookingProcess\ObjectSelectionListGUI(
184 $this->pool->getId(),
185 $this->ctrl->getFormAction($this, "selectObjects")
186 );
187 $tpl->setRightContent($list_gui->render());
188 }
189
190 protected function selectObjects(): void
191 {
192 $this->log->debug("selectObjects");
193 $obj_ids = $this->book_request->getObjectIds();
194 $this->object_selection->setSelectedObjects($obj_ids);
195 $this->ctrl->redirect($this, "week");
196 }
197
198
199 //
200 // Step 1
201 //
202
203
209 public function book(): void // ok
210 {
211 $this->log->debug("Step 1, book");
213
214 $this->tabs_gui->clearTargets();
215 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'back'));
216
217 $this->util_gui->setHelpId("book");
218
219 $obj = new ilBookingObject($this->book_obj_id);
220
221 $this->lng->loadLanguageModule("dateplaner");
222 $this->ctrl->setParameter($this, 'object_id', $obj->getId());
223 $this->ctrl->setParameter($this, 'returnCmd', 'week');
224
225 if ($this->user_id_to_book !== $this->user_id_assigner) {
226 $this->ctrl->setParameter($this, 'bkusr', $this->user_id_to_book);
227 }
228
229 if (!$this->access->canManageReservationForUser($this->book_request->getRefId(), $this->user_id_to_book)) {
230 return;
231 }
232
233 $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
234
235 $week_gui = new \ILIAS\BookingManager\BookingProcess\WeekGUI(
236 $this,
237 "book",
238 [$obj->getId()],
239 $this->pool->getId(),
240 $this->seed,
241 $user_settings->getWeekStart()
242 );
243 $tpl->setContent($week_gui->getHTML());
244 }
245
246 // Table to assign participants to an object.
247 public function assignParticipants(): void
248 {
249 $this->util_gui->assignParticipants($this->book_obj_id);
250 }
251
252 public function showNumberForm(): void
253 {
254 $this->log->debug("showNumberForm");
255 $object_id = $this->book_obj_id;
256 $from = $this->book_request->getSlotFrom();
257 $to = $this->book_request->getSlotTo() - 1;
258 $this->tabs_gui->clearTargets();
259 $this->tabs_gui->setBackTarget(
260 $this->lng->txt('book_back_to_list'),
261 $this->ctrl->getLinkTarget($this, 'back')
262 );
263 $form = $this->getNumberForm($from, $to);
264 $this->gui->modal($this->getBookgingObjectTitle())
265 ->form($form)
266 ->send();
267 }
268
269 protected function getBookgingObjectTitle(): string
270 {
271 return (new ilBookingObject($this->book_obj_id))->getTitle();
272 }
273
274
279 protected function getNumberForm(
280 int $from,
281 int $to
282 ): \ILIAS\Repository\Form\FormAdapterGUI {
283 $counter = $this->reservation->getAvailableNr($this->book_request->getObjectId(), $from, $to);
285 new ilDateTime($from, IL_CAL_UNIX),
286 new ilDateTime($to, IL_CAL_UNIX)
287 );
288 $this->ctrl->setParameter($this, "slot", $from . "_" . $to);
289 $form = $this->gui->form([self::class], "processNumberForm")
290 ->asyncModal()
291 ->section(
292 "props",
293 $this->lng->txt("book_confirm_booking_schedule_number_of_objects"),
294 $this->lng->txt("book_confirm_booking_schedule_number_of_objects_info")
295 )
296 ->number("nr", $period, "", 1, 1, $counter)
297 ->radio("recurrence", $this->lng->txt("book_recurrence"), "", "0")
298 ->radioOption("0", $this->lng->txt("book_no_recurrence"))
299 ->radioOption("1", $this->lng->txt("book_book_recurrence"))
300 ->hidden("origin_cmd", $this->book_request->getOriginCmd());
301 if ($this->pool->usesMessages()) {
302 $form = $form->textarea(
303 "message",
304 $this->lng->txt("book_message"),
305 $this->lng->txt("book_message_info")
306 );
307 }
308 return $form;
309 }
310
311 public function processNumberForm(): void
312 {
313 $this->log->debug("processNumberForm");
314 //get the user who will get the booking.
315 if ($this->book_request->getBookedUser() > 0) {
316 $this->user_id_to_book = $this->book_request->getBookedUser();
317 }
318 $slot = $this->book_request->getSlot();
319 $from = $this->book_request->getSlotFrom();
320 $to = $this->book_request->getSlotTo();
321 $obj_id = $this->book_request->getObjectId();
322
323 if ($this->user_id_assigner !== $this->user_id_to_book) {
324 $this->ctrl->setParameterByClass(self::class, "bkusr", $this->user_id_to_book);
325 }
326 $this->ctrl->setParameterByClass(self::class, "slot", $slot);
327
328 // form not valid -> show again
329 $form = $this->getNumberForm($from, $to);
330 if (!$form->isValid()) {
331 $this->gui->modal($this->getBookgingObjectTitle())
332 ->form($form)
333 ->send();
334 }
335
336 $origin_cmd = $form->getData("origin_cmd");
337 if (is_string($origin_cmd) && $origin_cmd !== "") {
338 $this->origin_cmd = $origin_cmd;
339 }
340
341 $message = $this->pool->usesMessages()
342 ? $form->getData("message")
343 : "";
344
345 // recurrence? -> show recurrence form
346 $recurrence = $form->getData("recurrence");
347 if ($recurrence === "1") {
348 if ($this->pool->usesMessages()) {
349 $this->ctrl->setParameterByClass(
350 self::class,
351 "message",
352 rawurlencode($message)
353 );
354 }
355 $this->ctrl->setParameterByClass(self::class, "object_id", $this->book_request->getObjectId());
356 $this->ctrl->setParameterByClass(self::class, "nr", (int) $form->getData("nr"));
357 $form = $this->getRecurrenceForm();
358 $this->gui->modal($this->getBookgingObjectTitle())
359 ->form($form)
360 ->send();
361 }
362 $this->checkAvailability(
363 false,
364 $form->getData("nr"),
365 $message
366 );
367 }
368
369
370 protected function getRecurrenceForm(): \ILIAS\Repository\Form\FormAdapterGUI
371 {
372 $this->lng->loadLanguageModule("dateplaner");
373 $today = new ilDate(time(), IL_CAL_UNIX);
374 $form = $this->gui->form([self::class], "checkAvailability")
375 ->section(
376 "props",
377 $this->lng->txt("book_confirm_booking_schedule_number_of_objects"),
378 $this->lng->txt("book_confirm_booking_schedule_number_of_objects_info")
379 )
380 ->switch("recurrence", $this->lng->txt("cal_recurrences"), "", "1")
381 ->group("1", $this->lng->txt("cal_weekly"))
382 ->date("until1", $this->lng->txt("cal_repeat_until"), "", $today)
383 ->group("2", $this->lng->txt("r_14"))
384 ->date("until2", $this->lng->txt("cal_repeat_until"), "", $today)
385 ->group("4", $this->lng->txt("r_4_weeks"))
386 ->date("until4", $this->lng->txt("cal_repeat_until"), "", $today)
387 ->end();
388 return $form;
389 }
390
391 public function checkAvailability(
392 bool $incl_recurrence = true,
393 int $nr = 0,
394 string $message = ""
395 ): void {
396 $this->log->debug("checkAvailability");
397 $obj_id = $this->book_request->getObjectId();
398 $from = $this->book_request->getSlotFrom();
399 $to = $this->book_request->getSlotTo();
400 if ($nr === 0) {
401 $nr = $this->book_request->getNr();
402 }
403 if ($message === "" && $this->pool->usesMessages()) {
404 $message = $this->book_request->getMessage();
405 }
406 $recurrence = 0;
407 $until_ts = 0;
408 if ($incl_recurrence) {
409 $form = $this->getRecurrenceForm();
410 // recurrence form not valid -> show again
411 if (!$form->isValid()) {
412 $this->gui->modal($this->getBookgingObjectTitle())
413 ->form($form)
414 ->send();
415 }
416
417 $recurrence = (int) $form->getData("recurrence"); // 1, 2 or 4
418 $until = $form->getData("until" . $recurrence);
419 $until_ts = $until->get(IL_CAL_UNIX);
420 }
421
422 $this->ctrl->saveParameter($this, ["object_id", "slot", "nr"]);
423 if ($this->pool->usesMessages()) {
424 $this->ctrl->setParameter(
425 $this,
426 "message",
427 rawurlencode($message)
428 );
429 }
430 $this->ctrl->setParameter($this, "recurrence", $recurrence);
431 $this->ctrl->setParameter($this, "until", $until_ts);
432 $book_available_target = $this->getBookAvailableTarget(
433 $obj_id,
434 $this->book_request->getSlot(),
435 $recurrence,
436 $nr,
437 $until_ts
438 );
439
440 if ($incl_recurrence) {
441
442 $missing = $this->process->getRecurrenceMissingAvailability(
443 $obj_id,
444 $from,
445 $to,
446 $recurrence,
447 $nr,
448 $until
449 );
450
451 // anything missing? -> send missing message
452 if (count($missing) > 0) {
453 $html = $this->getMissingAvailabilityMessage($missing);
454 $this->gui->modal($this->getBookgingObjectTitle())
455 ->legacy($html)
456 ->button(
457 $this->lng->txt("book_book_available"),
458 $book_available_target,
459 false
460 )
461 ->send();
462 }
463 }
464 $this->gui->send("<script>window.location.href = '" . $book_available_target . "';</script>");
465 }
466
467 protected function getMissingAvailabilityMessage(array $missing): string
468 {
469 $f = $this->gui->ui()->factory();
470 $box = $f->messageBox()->failure($this->lng->txt("book_missing_availability"));
471 $items = array_map(function ($i) {
472 $from = ilDatePresentation::formatDate(new ilDateTime($i["from"], IL_CAL_UNIX));
474 return $from . " - " . $to . " : " . str_replace("$1", $i["missing"], $this->lng->txt("book_missing_items"));
475 }, $missing);
476
477 $list = $f->listing()->unordered($items);
478 return $this->gui->ui()->renderer()->render([$box, $list]);
479 }
480
481 protected function bookAvailableItems(?int $recurrence = null, ?ilDateTime $until = null): void
482 {
483 if (!$this->access->canManageReservationForUser($this->pool->getRefId(), $this->user_id_to_book)) {
484 $this->showNoPermission();
485 return;
486 }
487 $this->log->debug("bookAvailableItems");
488 $obj_id = $this->book_request->getObjectId();
489 $from = $this->book_request->getSlotFrom();
490 $to = $this->book_request->getSlotTo();
491 $nr = $this->book_request->getNr();
492 $message = $this->pool->usesMessages()
493 ? $this->book_request->getMessage()
494 : "";
495 if (is_null($recurrence)) {
496 $recurrence = (int) $this->book_request->getRecurrence();
497 }
498 if (is_null($until)) {
499 if ($this->book_request->getUntil() > 0) {
500 $until = new ilDateTime($this->book_request->getUntil(), IL_CAL_UNIX);
501 }
502 }
503
504 $booked = $this->process->bookAvailableObjects(
505 $obj_id,
506 $this->user_id_to_book,
507 $this->user_id_assigner,
508 $this->context_obj_id,
509 $from,
510 $to,
511 $recurrence,
512 $nr,
513 $until,
514 $message
515 );
516 if (count($booked) > 0) {
517 $this->util_gui->handleBookingSuccess($obj_id, "displayPostInfo", $booked);
518 } else {
519 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('book_reservation_failed'), true);
520 $this->util_gui->back();
521 }
522 }
523
524 protected function getBookAvailableTarget(
525 int $obj_id,
526 string $slot,
527 int $recurrence,
528 int $nr,
529 int $until
530 ): string {
531 $this->ctrl->setParameter($this, "obj_id", $obj_id);
532 $this->ctrl->setParameter($this, "slot", $slot);
533 $this->ctrl->setParameter($this, "recurrence", $recurrence);
534 $this->ctrl->setParameter($this, "nr", $nr);
535 $this->ctrl->setParameter($this, "until", $until);
536 if (is_string($this->origin_cmd) && $this->origin_cmd !== "") {
537 $this->ctrl->setParameter($this, "origin_cmd", $this->origin_cmd);
538 }
539 return $this->ctrl->getLinkTarget($this, "bookAvailableItems");
540 }
541
542 public function displayPostInfo(): void
543 {
544 $this->util_gui->displayPostInfo(
545 $this->book_obj_id,
546 $this->user_id_assigner,
547 "deliverPostFile"
548 );
549 }
550
551 public function deliverPostFile(): void
552 {
553 $this->util_gui->deliverPostFile(
554 $this->book_obj_id,
555 $this->user_id_assigner
556 );
557 }
558
559 public function back(): void
560 {
561 $this->util_gui->back();
562 }
563}
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.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$counter