ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
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
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();
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) {
86 return $this->lng->txt('cal_cancel_booking');
88 return $this->lng->txt('cal_ch_delete_booking');
89 }
90 }
91
92 private function getSubmitLabel(): string
93 {
94 switch ($this->type) {
96 return $this->lng->txt('cal_cancel_booking');
98 return $this->lng->txt('cal_ch_delete_booking');
99 }
100 }
101
103 {
104 switch ($this->type) {
106 return $this->ui_factory->messageBox()->confirmation(
107 $this->lng->txt('cal_ch_cancel_booking_sure')
108 );
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) {
120 return $this->ui_factory->messageBox()->info(
121 $this->lng->txt('cal_ch_cancel_booking_info')
122 );
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) {
134 return $this->ui_factory->button()->primary(
135 $this->lng->txt('cal_cancel_booking'),
136 $this->ctrl->getLinkTarget($this->parent_object, 'cancelBooking')
137 );
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(
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}
$components
__construct(object $parent_object, \ilCalendarEntry $entry, \ilBookingEntry $booking, int $type)
Definition: UI.php:24
Booking definition.
Model for a calendar entry.
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)
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...
Definition: Bulky.php:21
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26