ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBookingScheduleGUI.php
Go to the documentation of this file.
1<?php
2
24use ILIAS\BookingManager\Service as BookingManager;
26use ILIAS\Refinery\Factory as Refinery;
27use ILIAS\UI\Factory as UIFactory;
28use ILIAS\UI\Renderer as UIRenderer;
30
35{
39 protected ilTabsGUI $tabs;
40 protected ilCtrl $ctrl;
41 protected ilLanguage $lng;
42 protected ilHelpGUI $help;
44 protected int $schedule_id;
45 protected int $ref_id;
46 private readonly Refinery $refinery;
47 private readonly UIFactory $ui_factory;
48 private readonly UIRenderer $ui_renderer;
49 private readonly HttpService $http;
50 private readonly BookingManager $booking_manager;
51 private readonly ilToolbarGUI $toolbar;
52 private readonly Factory $data_factory;
53
54 public function __construct(ilObjBookingPoolGUI $a_parent_obj)
55 {
56 global $DIC;
57
58 $this->tpl = $DIC->ui()->mainTemplate();
59 $this->tabs = $DIC->tabs();
60 $this->ctrl = $DIC->ctrl();
61 $this->lng = $DIC->language();
62 $this->access = $DIC->bookingManager()->internal()->domain()->access();
63 $this->help = $DIC['ilHelp'];
64 $this->obj_data_cache = $DIC['ilObjDataCache'];
65 $this->refinery = $DIC->refinery();
66 $this->ui_factory = $DIC->ui()->factory();
67 $this->ui_renderer = $DIC->ui()->renderer();
68 $this->http = new HttpService($DIC->http(), $this->refinery);
69 $this->booking_manager = $DIC->bookingManager();
70 $this->toolbar = $DIC->toolbar();
71 $this->data_factory = new Factory();
72
73 $this->ref_id = $a_parent_obj->getRefId();
74 $this->book_request = $DIC->bookingManager()->internal()->gui()->standardRequest();
75 $this->schedule_id = $this->book_request->getScheduleId();
76
77 if ($this->schedule_id > 0) {
78 $this->access->validateScheduleId($this->schedule_id, ilObject::_lookupObjId($this->ref_id));
79 }
80 }
81
82 public function executeCommand(): void
83 {
84 switch ($this->ctrl->getNextClass($this)) {
85 default:
86 $cmd = $this->ctrl->getCmd('render');
87 if (method_exists($this, $cmd)) {
88 $this->$cmd();
89 }
90 break;
91 }
92 }
93
94 public function executeTableAction(): void
95 {
96 $pool_id = $this->obj_data_cache->lookupObjId($this->ref_id);
97 $schedule_manager = $this->booking_manager->internal()->domain()->schedules($pool_id);
98
99 $this->configureScheduleTable($schedule_manager)->execute($this->getTableActionUrlBuilder());
100 $this->render();
101 }
102
103 public function render(): void
104 {
105 $pool_id = $this->obj_data_cache->lookupObjId($this->ref_id);
106 $schedule_manager = $this->booking_manager->internal()->domain()->schedules($pool_id);
107
108 $this->checkForInfoMessageAboutMissingBookableItems($schedule_manager, $pool_id);
109
110 if ($this->access->canManageSettings($this->ref_id)) {
111 $this->toolbar->addComponent(
112 $this->ui_factory->button()->standard(
113 $this->lng->txt('book_add_schedule'),
114 $this->ctrl->getLinkTarget($this, 'create')
115 )
116 );
117 }
118
119 $this->tpl->setContent(
120 $this->ui_renderer->render(
121 $this->configureScheduleTable($schedule_manager)->getComponents($this->getTableActionUrlBuilder())
122 )
123 );
124 }
125
126 public function create(): void
127 {
128 $this->tabs->clearTargets();
129 $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
130 $this->help->setScreenIdComponent('book');
131 $this->help->setScreenId('schedules');
132 $this->help->setSubScreenId('create');
133 $this->tpl->setContent($this->initForm()->getHTML());
134 }
135
136 public function edit(): void
137 {
138 $this->tabs->clearTargets();
139 $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
140 $this->help->setScreenIdComponent('book');
141 $this->help->setScreenId('schedules');
142 $this->help->setSubScreenId('edit');
143 $this->tpl->setContent($this->initForm('edit', $this->schedule_id)->getHTML());
144 }
145
146 public function initForm(string $a_mode = 'create', ?int $id = null): ilPropertyFormGUI
147 {
148 $this->lng->loadLanguageModule('dateplaner');
149
150 $form_gui = new ilPropertyFormGUI();
151
152 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
153 $title->setRequired(true);
154 $title->setSize(40);
155 $title->setMaxLength(120);
156 $form_gui->addItem($title);
157
158 $schedule = $a_mode === 'edit' && $id !== null ? new ilBookingSchedule($id) : null;
159 $schedule_type = $schedule?->getScheduleType() ?? ilBookingSchedule::SCHEDULE_TYPE_TIME_PERIOD;
160
161 $radio = new ilRadioGroupInputGUI($this->lng->txt('schedule_type'), 'schedule_type');
162 $radio->setValue($schedule_type);
163 $radio->setRequired(true);
164
165 $opt_time_period = new ilRadioOption($this->lng->txt('book_schedule_days'), ilBookingSchedule::SCHEDULE_TYPE_TIME_PERIOD);
166 $definition_slots = new ilScheduleInputGUI('', 'days');
167 $definition_slots->setInfo($this->lng->txt('book_schedule_days_info'));
168 $definition_slots->setRequired(true);
169 $opt_time_period->addSubItem($definition_slots);
170 $radio->addOption($opt_time_period);
171
172 $opt_all_days = new ilRadioOption($this->lng->txt('book_schedule_all_day'), ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY);
173 $definition_all_day = new ilScheduleDaysInputGUI('', 'days_all_day');
174 $definition_all_day->setRequired(true);
175 $opt_all_days->addSubItem($definition_all_day);
176 $radio->addOption($opt_all_days);
177
178 $form_gui->addItem($radio);
179
180 $deadline_opts = new ilRadioGroupInputGUI($this->lng->txt('book_deadline_options'), 'deadline_opts');
181 $deadline_opts->setRequired(true);
182 $form_gui->addItem($deadline_opts);
183
184 $deadline_time = new ilRadioOption($this->lng->txt('book_deadline_hours'), 'hours');
185 $deadline_opts->addOption($deadline_time);
186
187 $deadline = new ilNumberInputGUI($this->lng->txt('book_deadline'), 'deadline');
188 $deadline->setInfo($this->lng->txt('book_deadline_info'));
189 $deadline->setSuffix($this->lng->txt('book_hours'));
190 $deadline->setMinValue(1);
191 $deadline->setSize(3);
192 $deadline->setMaxLength(3);
193 $deadline->setRequired(true);
194 $deadline_time->addSubItem($deadline);
195
196 $deadline_start = new ilRadioOption($this->lng->txt('book_deadline_slot_start'), 'slot_start');
197 $deadline_opts->addOption($deadline_start);
198
199 $deadline_slot = new ilRadioOption($this->lng->txt('book_deadline_slot_end'), 'slot_end');
200 $deadline_opts->addOption($deadline_slot);
201
202 $av = new ilFormSectionHeaderGUI();
203 $av->setTitle($this->lng->txt('obj_activation_list_gui'));
204 $form_gui->addItem($av);
205
206 // #18221
207 $this->lng->loadLanguageModule('rep');
208
209 $from = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_start'), 'from');
210 $from->setShowTime(true);
211 $form_gui->addItem($from);
212
213 $to = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_end'), 'to');
214 $to->setShowTime(true);
215 $form_gui->addItem($to);
216
217 if ($schedule instanceof ilBookingSchedule) {
218 $form_gui->setTitle($this->lng->txt('book_edit_schedule'));
219
220 $item = new ilHiddenInputGUI('schedule_id');
221 $item->setValue($id);
222 $form_gui->addItem($item);
223
224 $title->setValue($schedule->getTitle());
225 $from->setDate($schedule->getAvailabilityFrom());
226 $to->setDate($schedule->getAvailabilityTo());
227
228 if ($schedule->getDeadline() === 0) {
229 $deadline_opts->setValue('slot_start');
230 } elseif ($schedule->getDeadline() > 0) {
231 $deadline->setValue($schedule->getDeadline());
232 $deadline_opts->setValue('hours');
233 } else {
234 $deadline->setValue(0);
235 $deadline_opts->setValue('slot_end');
236 }
237
238 match ($schedule_type) {
239 ilBookingSchedule::SCHEDULE_TYPE_ALL_DAY => $definition_all_day->setValue(
240 $schedule->getDefinitionBySlots()[ilBookingSchedule::ALL_DAY_SLOT]
241 ),
242 default => $definition_slots->setValue($schedule->getDefinitionBySlots()),
243 };
244
245 $form_gui->addCommandButton('update', $this->lng->txt('save'));
246 } else {
247 $form_gui->setTitle($this->lng->txt('book_add_schedule'));
248 $form_gui->addCommandButton('save', $this->lng->txt('save'));
249 $form_gui->addCommandButton('render', $this->lng->txt('cancel'));
250 }
251 $form_gui->setFormAction($this->ctrl->getFormAction($this));
252
253 return $form_gui;
254 }
255
256 public function save(): void
257 {
258 $form = $this->initForm();
259
260 if ($form->checkInput()) {
261 $obj = new ilBookingSchedule();
262 $this->formToObject($form, $obj);
263 $obj->save();
264
265 $this->tpl->setOnScreenMessage(
267 $this->lng->txt('book_schedule_added'),
268 true
269 );
270 $this->ctrl->redirect($this, 'render');
271 return;
272 }
273
274 $form->setValuesByPost();
275 $this->tpl->setContent($form->getHTML());
276 }
277
278 public function update(): void
279 {
280 $form = $this->initForm('edit', $this->schedule_id);
281
282 if ($form->checkInput()) {
283 $obj = new ilBookingSchedule($this->schedule_id);
284 $this->formToObject($form, $obj);
285 $obj->update();
286
287 $this->tpl->setOnScreenMessage(
289 $this->lng->txt('book_schedule_updated'),
290 true
291 );
292 $this->ctrl->redirect($this, 'render');
293 return;
294 }
295
296 $form->setValuesByPost();
297 $this->tpl->setContent($form->getHTML());
298 }
299
300 protected function formToObject(ilPropertyFormGUI $form, ilBookingSchedule $schedule): void
301 {
302 $schedule->setTitle($form->getInput('title'));
303 $schedule->setPoolId($this->obj_data_cache->lookupObjId($this->ref_id));
304 $schedule->setScheduleType($form->getInput('schedule_type'));
305
306 $from = $form->getItemByPostVar('from');
307 if ($from !== null) {
308 $schedule->setAvailabilityFrom($from->getDate());
309 }
310
311 $to = $form->getItemByPostVar('to');
312 if ($to !== null) {
313 $schedule->setAvailabilityTo($to->getDate());
314 }
315
316 match ($form->getInput('deadline_opts')) {
317 'slot_start' => $schedule->setDeadline(0),
318 'hours' => $schedule->setDeadline($form->getInput('deadline')),
319 'slot_end' => $schedule->setDeadline(-1),
320 };
321
322 $days = match ($schedule->getScheduleType()) {
325 };
326 $schedule->setDefinitionBySlots($days);
327 }
328
329 private function configureScheduleTable(ScheduleManager $schedule_manager): ScheduleTable
330 {
331 return new ScheduleTable(
332 $this->ctrl,
333 $this->lng,
334 $this->tpl,
335 $this->ui_factory,
336 $this->ui_renderer,
337 $this->refinery,
338 $this->access,
339 $this->http,
340 $schedule_manager,
341 $this->ref_id
342 );
343 }
344
345 private function checkForInfoMessageAboutMissingBookableItems(ScheduleManager $schedule_manager, int $pool_id): void
346 {
347 $schedule_data = $schedule_manager->getScheduleData();
348
349 if ($schedule_data === [] || ilBookingObject::getList($pool_id) !== []) {
350 return;
351 }
352
353 $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_INFO, $this->lng->txt('book_type_warning'));
354 }
355
357 {
358 return new URLBuilder($this->data_factory->uri(
359 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(self::class, 'executeTableAction')
360 ));
361 }
362}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
@ilCtrl_Calls ilBookingScheduleGUI:
configureScheduleTable(ScheduleManager $schedule_manager)
readonly ilToolbarGUI $toolbar
__construct(ilObjBookingPoolGUI $a_parent_obj)
readonly BookingManager $booking_manager
initForm(string $a_mode='create', ?int $id=null)
checkForInfoMessageAboutMissingBookableItems(ScheduleManager $schedule_manager, int $pool_id)
readonly UIRenderer $ui_renderer
ilGlobalTemplateInterface $tpl
formToObject(ilPropertyFormGUI $form, ilBookingSchedule $schedule)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAvailabilityFrom(?ilDateTime $a_date=null)
setScheduleType(string $a_schedule_type)
setDefinitionBySlots(array $a_def)
setDeadline(int $a_deadline)
Set deadline.
setAvailabilityTo(?ilDateTime $a_date=null)
Class ilCtrl provides processing control methods.
This class represents a date/time property in a property form.
This class represents a section header in a property form.
Help GUI class.
This class represents a hidden form property in a property form.
language handling
This class represents a number property in a property form.
@ilCtrl_Calls ilObjBookingPoolGUI: ilPermissionGUI, ilBookingObjectGUI @ilCtrl_Calls ilObjBookingPool...
class ilObjectDataCache
static _lookupObjId(int $ref_id)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This class represents an option in a radio group.
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 class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26