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