ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BookingCancellationGUI.php
Go to the documentation of this file.
1 <?php
19 
21 {
22  public const TYPE_CANCEL = 1;
23  public const TYPE_DELETE = 2;
24 
25  private \ilCalendarEntry $entry;
26 
27  private \ilBookingEntry $booking;
28 
29  private int $type;
30 
31  private $parent_object;
32 
33  private bool $has_multiple_bookings = false;
34 
35  private \ILIAS\UI\Factory $ui_factory;
36  private \ILIAS\UI\Renderer $ui_renderer;
37  private \ilCtrlInterface $ctrl;
38 
39  private \ilLanguage $lng;
40 
41 
42  public function __construct(object $parent_object, \ilCalendarEntry $entry, \ilBookingEntry $booking, int $type)
43  {
44  global $DIC;
45 
46  $this->ui_factory = $DIC->ui()->factory();
47  $this->ui_renderer = $DIC->ui()->renderer();
48  $this->ctrl = $DIC->ctrl();
49  $this->lng = $DIC->language();
50 
51  $this->parent_object = $parent_object;
52  $this->entry = $entry;
53  $this->booking = $booking;
54  $this->type = $type;
55 
56  $this->init();
57  }
58 
59  public function renderModal(): \ILIAS\UI\Component\Modal\RoundTrip
60  {
61  $modal_title = $this->getTitle();
62  $components[] = $this->getConfirmationBox();
63  $components[] = $this->getInfoBox();
64  if (!$this->has_multiple_bookings) {
65  $components[] = $this->getBookingInfo();
66  }
67  return $this->ui_factory->modal()->roundtrip(
68  $modal_title,
70  [
71  'bookings' => $this->getInputs()
72  ],
73  $this->ctrl->getLinkTarget(
74  $this->parent_object,
75  $this->type == self::TYPE_CANCEL ? 'cancelBooking' : 'deleteBooking'
76  )
77  )->withCancelButtonLabel($this->lng->txt('close'))
78  ->withSubmitLabel($this->getSubmitLabel());
79  }
80 
81  private function getTitle(): string
82  {
83  switch ($this->type) {
84  case self::TYPE_CANCEL:
85  return $this->lng->txt('cal_cancel_booking');
86  case self::TYPE_DELETE:
87  return $this->lng->txt('cal_ch_delete_booking');
88  }
89  }
90 
91  private function getSubmitLabel(): string
92  {
93  switch ($this->type) {
94  case self::TYPE_CANCEL:
95  return $this->lng->txt('cal_cancel_booking');
96  case self::TYPE_DELETE:
97  return $this->lng->txt('cal_ch_delete_booking');
98  }
99  }
100 
102  {
103  switch ($this->type) {
104  case self::TYPE_CANCEL:
105  return $this->ui_factory->messageBox()->confirmation(
106  $this->lng->txt('cal_ch_cancel_booking_sure')
107  );
108  case self::TYPE_DELETE:
109  return $this->ui_factory->messageBox()->confirmation(
110  $this->lng->txt('cal_ch_delete_booking_sure')
111  );
112  }
113  }
114 
115  private function getInfoBox(): \ILIAS\UI\Component\Component
116  {
117  switch ($this->type) {
118  case self::TYPE_CANCEL:
119  return $this->ui_factory->messageBox()->info(
120  $this->lng->txt('cal_ch_cancel_booking_info')
121  );
122  case self::TYPE_DELETE:
123  return $this->ui_factory->messageBox()->info(
124  $this->lng->txt('cal_ch_delete_booking_info')
125  );
126  }
127  }
128 
130  {
131  switch ($this->type) {
132  case self::TYPE_CANCEL:
133  return $this->ui_factory->button()->primary(
134  $this->lng->txt('cal_cancel_booking'),
135  $this->ctrl->getLinkTarget($this->parent_object, 'cancelBooking')
136  );
137  case self::TYPE_DELETE:
138  return $this->ui_factory->button()->primary(
139  $this->lng->txt('cal_ch_delete_booking'),
140  $this->ctrl->getLinkTarget($this->parent_object, 'deleteBooking')
141  );
142  }
143  }
144 
146  {
147  $user_info = [];
148  foreach ($this->booking->getCurrentBookings($this->entry->getEntryId()) as $booking_user_id) {
149  $user_info[] =
150  $this->getAppointmentTitle() . ': ' .
151  \ilObjUser::_lookupFullname($booking_user_id);
152 
153  }
154  return $this->ui_factory->legacy(implode('<br/', $user_info));
155  }
156 
157  protected function getInputs()
158  {
159  $section_title = '';
160  $inputs = [];
161  if ($this->has_multiple_bookings) {
162  $section_title = $this->getAppointmentTitle();
163  foreach ($this->booking->getCurrentBookings($this->entry->getEntryId()) as $bookuser) {
164  $inputs[(string) $bookuser] =
165  $this->ui_factory->input()->field()->checkbox(
166  \ilObjUser::_lookupFullname($bookuser)
167  )->withValue(true);
168  }
169  } else {
170  $section_title = '';
171  foreach ($this->booking->getCurrentBookings($this->entry->getEntryId()) as $bookuser) {
172  $inputs[(string) $bookuser] =
173  $this->ui_factory->input()->field()->hidden(
174  )->withValue(true);
175  }
176  }
177 
178  return $this->ui_factory->input()->field()->section(
179  $inputs,
180  $section_title
181  );
182  }
183 
184  private function getAppointmentTitle(): string
185  {
186  return
187  $this->entry->getTitle() . ', ' .
188  \ilDatePresentation::formatDate($this->entry->getStart());
189  }
190 
191  private function init(): void
192  {
193  $this->has_multiple_bookings = $this->booking->getCurrentNumberOfBookings($this->entry->getEntryId()) > 1;
194  }
195 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
static _lookupFullname(int $a_user_id)
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$components
__construct(object $parent_object, \ilCalendarEntry $entry, \ilBookingEntry $booking, int $type)
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...