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