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