ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingProcessWithoutScheduleGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\BookingManager\Access\AccessManager $access;
26 protected \ILIAS\BookingManager\Reservations\ReservationManager $reservation;
27 protected \ILIAS\BookingManager\BookingProcess\ProcessUtilGUI $util_gui;
28 protected \ILIAS\BookingManager\InternalRepoService $repo;
29 protected \ILIAS\BookingManager\BookingProcess\BookingProcessManager $process;
30 protected \ILIAS\HTTP\Services $http;
31 protected \ILIAS\BookingManager\InternalGUIService $gui;
32 protected array $raw_post_data;
33 protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
35 protected int $booking_object_id;
36 protected int $user_id_to_book;
37 protected int $user_id_assigner;
39 protected int $context_obj_id;
40 protected ilCtrl $ctrl;
42 protected ilLanguage $lng;
44 protected ilObjUser $user;
45 protected int $book_obj_id;
46 protected array $rsv_ids = [];
47
48 public function __construct(
51 int $context_obj_id = 0
52 ) {
53 global $DIC;
54
55 $this->ctrl = $DIC->ctrl();
56 $this->tpl = $DIC["tpl"];
57 $this->lng = $DIC->language();
58 $this->tabs_gui = $DIC->tabs();
59 $this->user = $DIC->user();
60 $this->help = $DIC->bookingManager()->internal()
61 ->gui()->bookingHelp($pool);
62 $this->http = $DIC->http();
63
64 $this->context_obj_id = $context_obj_id;
65
66 $this->book_obj_id = $booking_object_id;
67
68 $this->pool = $pool;
69
70 $this->book_request = $DIC->bookingManager()
71 ->internal()
72 ->gui()
73 ->standardRequest();
74
75 $this->gui = $DIC->bookingManager()
76 ->internal()
77 ->gui();
78
79 $this->repo = $DIC->bookingManager()
80 ->internal()
81 ->repo();
82
83 $this->rsv_ids = $this->book_request->getReservationIdsFromString();
84
85 $this->raw_post_data = $DIC->http()->request()->getParsedBody();
86
87 $this->user_id_assigner = $this->user->getId();
88 if ($this->book_request->getBookedUser() > 0) {
89 $this->user_id_to_book = $this->book_request->getBookedUser();
90 } else {
91 $this->user_id_to_book = $this->user_id_assigner; // by default user books his own booking objects.
92 }
93 $this->ctrl->saveParameter($this, ["bkusr", "returnCmd"]);
94
95 $this->process = $DIC->bookingManager()->internal()->domain()->process();
96 $this->reservation = $DIC->bookingManager()->internal()->domain()->reservations();
97 $this->util_gui = $DIC->bookingManager()->internal()->gui()->process()->ProcessUtilGUI(
98 $this->pool,
99 $this
100 );
101 $this->access = $DIC->bookingManager()->internal()->domain()->access();
102 }
103
104 public function executeCommand(): void
105 {
107
108 $next_class = $ctrl->getNextClass($this);
109 $cmd = $ctrl->getCmd("show");
110 switch ($next_class) {
111 default:
112 if (in_array($cmd, array(
113 "book",
114 "back",
115 "assignParticipants",
116 "bookMultipleParticipants",
117 "saveMultipleBookings",
118 "confirmedBooking",
119 "displayPostInfo",
120 "deliverPostFile",
121 "redirectToParticipantsList",
122 "saveMessage"
123 ))) {
124 $this->$cmd();
125 }
126 }
127 }
128
129 protected function showNoPermission(): void
130 {
131 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_permission"), true);
132 $this->back();
133 }
134
135 //
136 // Step 1
137 //
138
144 public function book(): void // ok
145 {
147
148 $this->tabs_gui->clearTargets();
149 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'back'));
150
151 $this->util_gui->setHelpId("book");
152
153 $obj = new ilBookingObject($this->book_obj_id);
154
155 $this->lng->loadLanguageModule("dateplaner");
156 $this->ctrl->setParameter($this, 'object_id', $obj->getId());
157 $this->ctrl->setParameter($this, 'returnCmd', "back");
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
163 if (!$this->access->canManageReservationForUser($this->book_request->getRefId(), $this->user_id_to_book)) {
164 return;
165 }
166
167 if ($this->pool->usesMessages()) {
168 $this->showMessageForm();
169 } else {
170 $this->showConfirmation();
171 }
172 }
173
174 protected function getMessageForm(): \ILIAS\Repository\Form\FormAdapterGUI
175 {
176 $obj = new ilBookingObject($this->book_obj_id);
177 return $this->gui->form([self::class], "saveMessage", $this->lng->txt("book_book"))
178 ->section("main", $this->lng->txt("book_booking") . ": " . $obj->getTitle())
179 ->textarea(
180 "message",
181 $this->lng->txt("book_message"),
182 $this->lng->txt("book_message_info")
183 );
184 }
185
186 protected function showMessageForm(): void
187 {
188 $this->tpl->setContent($this->getMessageForm()->render());
189 }
190
191 protected function saveMessage(): void
192 {
193 $this->ctrl->saveParameter($this, ['object_id', 'returnCmd', 'bkusr']);
194 $form = $this->getMessageForm();
195 if (!$form->isValid()) {
196 $this->tabs_gui->clearTargets();
197 $this->tabs_gui->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'back'));
198 $this->tpl->setContent($form->render());
199 return;
200 }
201 $this->confirmedBooking($form->getData("message"));
202 }
203
204 protected function showConfirmation(): void
205 {
207
208 $obj = new ilBookingObject($this->book_obj_id);
209
210 $cgui = new ilConfirmationGUI();
211 $cgui->setHeaderText($this->lng->txt("book_confirm_booking_no_schedule"));
212
213 $cgui->setFormAction($this->ctrl->getFormAction($this));
214 $cgui->setCancel($this->lng->txt("cancel"), "back");
215 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedBooking");
216
217 $cgui->addItem("object_id", $obj->getId(), $obj->getTitle());
218
219 $tpl->setContent($cgui->getHTML());
220 }
221
222 // Table to assign participants to an object.
223 public function assignParticipants(): void
224 {
225 $this->util_gui->assignParticipants($this->book_obj_id);
226 }
227
231 public function bookMultipleParticipants(): void
232 {
233 $participants = $this->book_request->getParticipants();
234 if (count($participants) === 0) {
235 $this->util_gui->back();
236 return;
237 }
238
239 $this->tabs_gui->clearTargets();
240 $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, 'assignparticipants'));
241
242 $conf = new ilConfirmationGUI();
243 $conf->setFormAction($this->ctrl->getFormAction($this));
244
245 //add user list as items.
246 foreach ($participants as $id) {
247 if (!$this->access->canManageReservationForUser($this->pool->getRefId(), $id)) {
248 $this->showNoPermission();
249 return;
250 }
252 $conf->addItem("participants[]", $id, $name);
253 }
254
255 $available = ilBookingReservation::numAvailableFromObjectNoSchedule($this->book_obj_id);
256 if (count($participants) > $available) {
257 $obj = new ilBookingObject($this->book_obj_id);
258 $this->tpl->setOnScreenMessage("failure", sprintf(
259 $this->lng->txt('book_limit_objects_available'),
260 count($participants),
261 $obj->getTitle(),
262 $available
263 ), true);
264 $this->ctrl->redirect($this, "redirectToParticipantsList");
265 } else {
266 $conf->setHeaderText($this->lng->txt('book_confirm_booking_for_users'));
267 $conf->addHiddenItem("object_id", $this->book_obj_id);
268 $conf->setConfirm($this->lng->txt("assign"), "saveMultipleBookings");
269 }
270
271 $conf->setCancel($this->lng->txt("cancel"), 'redirectToParticipantsList');
272 $this->tpl->setContent($conf->getHTML());
273 }
274
275 public function redirectToParticipantsList(): void
276 {
277 $this->ctrl->redirect($this, 'assignParticipants');
278 }
279
284 public function saveMultipleBookings(): void
285 {
286 $participants = $this->book_request->getParticipants();
287 $object_id = $this->book_request->getObjectId();
288 if (count($participants) > 0 && $object_id > 0) {
289 $this->book_obj_id = $object_id;
290 } else {
291 $this->util_gui->back();
292 }
293 $rsv_ids = array();
294 foreach ($participants as $id) {
295 if (!$this->access->canManageReservationForUser($this->pool->getRefId(), $id)) {
296 $this->showNoPermission();
297 return;
298 }
299 $this->user_id_to_book = $id;
300 $rsv_ids[] = $this->process->bookSingle(
301 $this->book_obj_id,
302 $this->user_id_to_book,
303 $this->user_id_assigner,
304 $this->context_obj_id
305 );
306 }
307
308 if (count($rsv_ids)) {
309 $this->tpl->setOnScreenMessage('success', "booking_multiple_succesfully");
310 } else {
311 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('book_reservation_failed_overbooked'), true);
312 }
313 $this->util_gui->back();
314 }
315
316
317 //
318 // Step 2: Confirmation
319 //
320
321 // Book object - either of type or specific - for given dates
322 public function confirmedBooking($message = ""): bool
323 {
324 $success = false;
325 $rsv_ids = array();
326
327 if ($this->book_obj_id > 0) {
328 $object_id = $this->book_obj_id;
329 if ($object_id) {
331 count(ilBookingReservation::getObjectReservationForUser($object_id, $this->user_id_to_book)) === 0) { // #18304
332 $rsv_ids[] = $this->process->bookSingle(
333 $object_id,
334 $this->user_id_to_book,
335 $this->user_id_assigner,
336 $this->context_obj_id,
337 null,
338 null,
339 null,
341 );
342 $success = $object_id;
343 } else {
344 // #11852
345 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('book_reservation_failed_overbooked'), true);
346 $this->ctrl->redirect($this, 'back');
347 }
348 }
349 }
350
351 if ($success) {
352 $this->util_gui->handleBookingSuccess($success, "displayPostInfo", $rsv_ids);
353 } else {
354 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('book_reservation_failed'), true);
355 $this->ctrl->redirect($this, 'book');
356 }
357 return true;
358 }
359
360 public function displayPostInfo(): void
361 {
362 $this->util_gui->displayPostInfo(
363 $this->book_obj_id,
364 $this->user_id_assigner,
365 "deliverPostFile"
366 );
367 }
368
369 public function deliverPostFile(): void
370 {
371 $this->util_gui->deliverPostFile(
372 $this->book_obj_id,
373 $this->user_id_assigner
374 );
375 }
376
377 public function back(): void
378 {
379 $this->ctrl->redirectByClass(\ilObjBookingPoolGUI::class, 'render');
380 }
381}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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...
saveMultipleBookings()
Save multiple users reservations for one booking pool object.
ILIAS BookingManager BookingProcess ProcessUtilGUI $util_gui
ILIAS BookingManager Reservations ReservationManager $reservation
__construct(ilObjBookingPool $pool, int $booking_object_id, int $context_obj_id=0)
book()
Triggered from object list week view for booking a single object / confirmation for.
ILIAS BookingManager BookingProcess BookingProcessManager $process
bookMultipleParticipants()
Create reservations for a bunch of booking pool participants.
ILIAS BookingManager StandardGUIRequest $book_request
ILIAS BookingManager InternalRepoService $repo
ILIAS BookingManager Access AccessManager $access
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
static isObjectAvailableNoSchedule(int $a_obj_id)
static numAvailableFromObjectNoSchedule(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupFullname(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
$message
Definition: xapiexit.php:31