ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBookingObjectGUI.php
Go to the documentation of this file.
1<?php
2
30use ILIAS\Data\Factory as DataFactory;
31use ILIAS\Refinery\Factory as Refinery;
36
42{
50 protected ilCtrl $ctrl;
52 protected ilLanguage $lng;
53 protected ilTabsGUI $tabs;
55 protected ilObjUser $user;
59 protected Refinery $refinery;
60 protected HttpService $http;
62 protected DataFactory $data_factory;
64 protected bool $pool_has_schedule;
65 protected ?int $pool_overall_limit;
66 protected bool $pool_uses_preferences = false;
67 // Is management of objects (create/edit/delete) activated?
68 protected bool $management = true;
69 protected int $object_id;
70 protected array $rsv_ids = [];
72 protected int $ref_id;
73
74 public function __construct(
75 protected ilObjBookingPoolGUI $a_parent_obj,
76 protected string $seed,
77 protected string $sseed,
78 protected ilBookingHelpAdapter $help,
79 // Context object id (e.g. course with booking service activated)
80 protected int $context_obj_id = 0
81 ) {
82 global $DIC;
83
84 $this->ctrl = $DIC->ctrl();
85 $this->tpl = $DIC->ui()->mainTemplate();
86 $this->lng = $DIC->language();
87 $this->access = $DIC
88 ->bookingManager()
89 ->internal()
90 ->domain()
91 ->access();
92 $this->tabs = $DIC->tabs();
93 $this->obj_data_cache = $DIC['ilObjDataCache'];
94 $this->user = $DIC->user();
95 $this->ui_factory = $DIC->ui()->factory();
96 $this->ui_renderer = $DIC->ui()->renderer();
97 $this->ui_service = $DIC->uiService();
98 $this->refinery = $DIC->refinery();
99 $this->http = new HttpService($DIC->http(), $this->refinery);
100 $this->process_manager = $DIC->bookingManager()->internal()->domain()->process();
101 $this->data_factory = new DataFactory();
102
104 $pool = $a_parent_obj->getObject();
105 $this->pool = $pool;
106
107 $this->book_request = $DIC
108 ->bookingManager()
109 ->internal()
110 ->gui()
111 ->standardRequest();
112 $this->gui = $DIC->bookingManager()->internal()->gui();
113 $this->schedule_manager = $DIC
114 ->bookingManager()
115 ->internal()
116 ->domain()
117 ->schedules($this->pool->getId());
118 $this->settings = $DIC
119 ->bookingManager()
120 ->internal()
121 ->domain()
122 ->bookingSettings()
123 ->getByObjId($this->pool->getId());
124
125 $this->bulk_creation_gui = $this->gui->objects()->ilBookBulkCreationGUI($this->pool);
126
127 $schedule_type = $a_parent_obj->getObject()->getScheduleType();
128 $this->pool_has_schedule = $schedule_type === ilObjBookingPool::TYPE_FIX_SCHEDULE;
129 $this->pool_uses_preferences = $schedule_type === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES;
130 $this->pool_overall_limit = !$this->pool_has_schedule ? $a_parent_obj->getObject()->getOverallLimit() : null;
131
132 $this->object_id = $this->book_request->getObjectId();
133 $this->ref_id = $this->book_request->getRefId();
134 $this->ctrl->saveParameter($this, 'object_id');
135
136 $this->rsv_ids = array_map('intval', $this->book_request->getReservationIdsFromString());
137 $this->objects_manager = $DIC
138 ->bookingManager()
139 ->internal()
140 ->domain()
141 ->objects($this->pool->getId());
142
143 $this->access->validateBookingObjId($this->object_id, (int) $a_parent_obj->getObject()?->getId());
144 }
145
146 public function activateManagement(bool $a_val): void
147 {
148 $this->management = $a_val;
149 }
150
151 public function isManagementActivated(): bool
152 {
153 return $this->management;
154 }
155
156 protected function getPoolRefId(): int
157 {
158 return $this->a_parent_obj->getRefId();
159 }
160
161 protected function getPoolObjId(): int
162 {
163 return $this->pool->getId();
164 }
165
166 protected function hasPoolSchedule(): bool
167 {
169 }
170
171 protected function getPoolOverallLimit(): ?int
172 {
174 }
175
179 public function executeCommand(): void
180 {
181 switch (strtolower($this->ctrl->getNextClass($this))) {
182 case strtolower(ilPropertyFormGUI::class):
183 // only case is currently adv metadata internal link in info settings, see #24497
184 $this->ctrl->forwardCommand($this->initForm());
185 break;
186
187 case strtolower(ilBookingProcessWithScheduleGUI::class):
188 $this->ctrl->setReturn($this, $this->pool_uses_preferences ? 'returnToPreferences' : 'render');
189 $process_gui = $this->gui->process()->ilBookingProcessWithScheduleGUI(
190 $this->pool,
191 $this->object_id,
192 $this->context_obj_id,
193 $this->seed ?? $this->sseed
194 );
195 $this->ctrl->forwardCommand($process_gui);
196 break;
197
198 case strtolower(ilBookingProcessWithoutScheduleGUI::class):
199 $this->ctrl->setReturn($this, $this->pool_uses_preferences ? 'returnToPreferences' : 'render');
200 $process_gui = $this->gui->process()->ilBookingProcessWithoutScheduleGUI(
201 $this->pool,
202 $this->object_id,
203 $this->context_obj_id
204 );
205 $this->ctrl->forwardCommand($process_gui);
206 break;
207
208 case strtolower(ilBookBulkCreationGUI::class):
209 $this->ctrl->setReturn($this, '');
210 $this->ctrl->forwardCommand($this->bulk_creation_gui);
211 break;
212
213 default:
214 $cmd = $this->ctrl->getCmd('render');
215 $this->$cmd();
216 break;
217 }
218 }
219
220 protected function returnToPreferences(): void
221 {
222 $this->ctrl->redirectByClass(ilBookingPreferencesGUI::class);
223 }
224
225 public function render(?Modal $modal = null): void
226 {
227 $this->a_parent_obj->showNoScheduleMessage();
228
229 $bar = '';
230
231 if ($this->isManagementActivated()) {
232 $bar = new ilToolbarGUI();
233 if ($this->access->canManageObjects($this->getPoolRefId())) {
234 $bar->addButton($this->lng->txt('book_add_object'), $this->ctrl->getLinkTarget($this, 'create'));
235
236 // bulk creation
237 $this->bulk_creation_gui->modifyToolbar($bar);
238 }
239
240 if ($bar->getItems() !== []) {
241 $bar->addSeparator();
242 }
243
244 if ($this->hasPoolSchedule()) {
245 $mode_control = $this->gui->ui()->factory()->viewControl()->mode(
246 [
247 $this->lng->txt('book_table') => $this->ctrl->getLinkTarget($this, ''),
248 $this->lng->txt('book_week') => $this->ctrl->getLinkTargetByClass(ilBookingProcessWithScheduleGUI::class, 'week')
249 ],
250 $this->lng->txt('book_view')
251 );
252 $bar->addComponent($mode_control);
253 }
254
255 $bar = $bar->getHTML();
256 }
257
259 if ($modal !== null) {
260 $components[] = $modal;
261 }
262
263 $this->tpl->setPermanentLink('book', $this->getPoolRefId());
264 $this->tpl->setContent($bar . $this->ui_renderer->render($components));
265 }
266
267 private function getTable(): BookableItemTable
268 {
269 if ($this->hasPoolSchedule()) {
271 $this->ui_factory,
272 $this->ui_renderer,
273 $this->lng,
274 $this->http,
275 $this->ui_service,
276 $this->ctrl,
277 $this->tpl,
278 $this->refinery,
279 $this->access,
280 $this->pool,
281 $this->process_manager,
282 $this->settings,
283 $this->user,
284 $this->getPoolRefId(),
285 $this->isManagementActivated(),
286 $this->context_obj_id,
287 );
288 }
289
291 $this->ui_factory,
292 $this->ui_renderer,
293 $this->lng,
294 $this->http,
295 $this->ui_service,
296 $this->ctrl,
297 $this->tpl,
298 $this->refinery,
299 $this->access,
300 $this->pool,
301 $this->process_manager,
302 $this->settings,
303 $this->user,
304 $this->getPoolRefId(),
305 $this->isManagementActivated(),
306 $this->context_obj_id,
307 );
308 }
309
310 private function getTableComponents(): array
311 {
312 return $this->getTable()->getComponents($this->getURLBuilder());
313 }
314
315 public function executeTableAction(): void
316 {
317 $modal = $this->getTable()->execute($this->getURLBuilder());
318 if ($modal !== null) {
319 $this->render($modal);
320 return;
321 }
322 $this->ctrl->redirectByClass(self::class, 'render');
323 }
324
325 private function getURLBuilder(): URLBuilder
326 {
327 return new URLBuilder(
328 $this->data_factory->uri(ILIAS_HTTP_PATH . "/{$this->ctrl->getLinkTarget($this, 'executeTableAction')}")
329 );
330 }
331
332 public function create(?ilPropertyFormGUI $a_form = null): void
333 {
334 if (!$this->access->canManageObjects($this->ref_id)) {
335 return;
336 }
337
338 $this->tabs->clearTargets();
339 $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
340
341 $this->setHelpId('create');
342
343 $a_form ??= $this->initForm();
344 $this->tpl->setContent($a_form->getHTML());
345 }
346
347 public function edit(?ilPropertyFormGUI $a_form = null): void
348 {
349 if (!$this->access->canManageObjects($this->ref_id)) {
350 return;
351 }
352
353 $this->tabs->clearTargets();
354 $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
355
356 $this->setHelpId('edit');
357
358 $a_form ??= $this->initForm('edit', $this->object_id);
359 $this->tpl->setContent($a_form->getHTML());
360 }
361
362 protected function setHelpId(string $a_id): void
363 {
364 $this->help->setHelpId($a_id);
365 }
366
367 public function initForm(string $a_mode = 'create', ?int $id = null): ilPropertyFormGUI
368 {
369 $form_gui = new ilPropertyFormGUI();
370
371 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
372 $title->setRequired(true);
373 $title->setSize(40);
374 $title->setMaxLength(120);
375 $form_gui->addItem($title);
376
377 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
378 $desc->setCols(70);
379 $desc->setRows(15);
380 $desc->setMaxNumOfChars(1000);
381 $form_gui->addItem($desc);
382
383 $file = new ilFileInputGUI($this->lng->txt('book_additional_info_file'), 'file');
384 $file->setAllowDeletion(true);
385 $form_gui->addItem($file);
386
387 $nr = new ilNumberInputGUI($this->lng->txt('booking_nr_of_items'), 'items');
388 $nr->setRequired(true);
389 $nr->setSize(3);
390 $nr->setMaxLength(3);
391 $nr->setSuffix($this->lng->txt('book_booking_objects'));
392 $form_gui->addItem($nr);
393
394 $schedule = null;
395 if ($this->hasPoolSchedule()) {
396 $options = array_map(
397 static fn(string $schedule_title): string => $schedule_title,
398 $this->schedule_manager->getScheduleList()
399 );
400 $schedule = new ilSelectInputGUI($this->lng->txt('book_schedule'), 'schedule');
401 $schedule->setRequired(true);
402 $schedule->setOptions($options);
403 $form_gui->addItem($schedule);
404 }
405
406 $post = new ilFormSectionHeaderGUI();
407 $post->setTitle($this->lng->txt('book_post_booking_information'));
408 $form_gui->addItem($post);
409
410 $pdesc = new ilTextAreaInputGUI($this->lng->txt('book_post_booking_text'), 'post_text');
411 $pdesc->setCols(70);
412 $pdesc->setRows(15);
413 $pdesc->setInfo($this->lng->txt('book_post_booking_text_info'));
414 $form_gui->addItem($pdesc);
415
416 $pfile = new ilFileInputGUI($this->lng->txt('book_post_booking_file'), 'post_file');
417 $pfile->setAllowDeletion(true);
418 $form_gui->addItem($pfile);
419
420 // #18214 - should also work for new objects
421 $this->record_gui = new ilAdvancedMDRecordGUI(
423 'book',
424 $this->getPoolObjId(),
425 'bobj',
426 (int) $id
427 );
428 $this->record_gui->setPropertyForm($form_gui);
429 $this->record_gui->parse();
430
431 if ($a_mode === 'edit') {
432 $form_gui->setTitle($this->lng->txt('book_edit_object'));
433
434 $item = new ilHiddenInputGUI('object_id');
435 $item->setValue($id);
436 $form_gui->addItem($item);
437
438 $obj = new ilBookingObject($id);
439 $title->setValue($obj->getTitle());
440 $desc->setValue($obj->getDescription());
441 $nr->setValue($obj->getNrOfItems());
442 $pdesc->setValue($obj->getPostText());
443 $file->setValue($this->objects_manager->getObjectInfoFilename($id));
444 $pfile->setValue($this->objects_manager->getBookingInfoFilename($id));
445
446 $schedule?->setValue($obj->getScheduleId());
447
448 $form_gui->addCommandButton('update', $this->lng->txt('save'));
449 } else {
450 $form_gui->setTitle($this->lng->txt('book_add_object'));
451 $form_gui->addCommandButton('save', $this->lng->txt('save'));
452 $form_gui->addCommandButton('render', $this->lng->txt('cancel'));
453 }
454
455 $form_gui->setFormAction($this->ctrl->getFormAction($this));
456 return $form_gui;
457 }
458
459 public function save(): void
460 {
461 $this->handleForm(true);
462 }
463
464 public function update(): void
465 {
466 $this->handleForm(false);
467 }
468
469 private function handleForm(bool $create): void
470 {
471 if (!$this->access->canManageObjects($this->ref_id)) {
472 return;
473 }
474
475 $form = $create ? $this->initForm() : $this->initForm('edit', $this->object_id);
476
477 if (
478 $form->checkInput()
479 && (
480 !$this->record_gui instanceof ilAdvancedMDRecordGUI
481 || $this->record_gui->importEditFormPostValues()
482 )
483 ) {
484 $obj = new ilBookingObject($this->object_id);
485 $obj->setTitle($form->getInput('title'));
486 $obj->setDescription($form->getInput('desc'));
487 $obj->setNrOfItems($form->getInput('items'));
488 $obj->setPostText($form->getInput('post_text'));
489
490 if ($this->hasPoolSchedule()) {
491 $obj->setScheduleId($form->getInput('schedule'));
492 }
493
494 if ($create) {
495 $obj->setPoolId($this->getPoolObjId());
496 $obj->save();
497 } else {
498 $obj->update();
499 }
500
501 if ($_FILES['file']['tmp_name']) {
502 $this->objects_manager->importObjectInfoFromLegacyUpload($obj->getId(), $_FILES['file']);
503 } elseif ($form->getItemByPostVar('file')?->getDeletionFlag()) {
504 $this->objects_manager->deleteObjectInfo($obj->getId());
505 }
506
507 if ($_FILES['post_file']['tmp_name']) {
508 $this->objects_manager->importBookingInfoFromLegacyUpload($obj->getId(), $_FILES['post_file']);
509 } elseif ($form->getItemByPostVar('post_file')?->getDeletionFlag()) {
510 $this->objects_manager->deleteBookingInfo($obj->getId());
511 }
512
513 $obj->update();
514
515 $create
516 ? $this->record_gui?->writeEditForm(null, $obj->getId())
517 : $this->record_gui?->writeEditForm();
518
519 $this->tpl->setOnScreenMessage(
520 'success',
521 $this->lng->txt($create ? 'book_object_added' : 'book_object_updated'),
522 true
523 );
524 $this->ctrl->redirect($this, $create ? 'render' : 'edit');
525 }
526
527 $form->setValuesByPost();
528 $create ? $this->create($form) : $this->edit($form);
529 }
530
531 public function confirmDelete(): void
532 {
533 if (!$this->access->canManageObjects($this->ref_id)) {
534 return;
535 }
536
537 $this->tabs->clearTargets();
538 $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
539
540 $conf = new ilConfirmationGUI();
541 $conf->setFormAction($this->ctrl->getFormAction($this));
542 $conf->setHeaderText($this->lng->txt('book_confirm_delete'));
543
544 $type = new ilBookingObject($this->object_id);
545 $conf->addItem('object_id', $this->object_id, $type->getTitle());
546 $conf->setConfirm($this->lng->txt('delete'), 'delete');
547 $conf->setCancel($this->lng->txt('cancel'), 'render');
548
549 $this->tpl->setContent($conf->getHTML());
550 }
551
552 public function delete(): void
553 {
554 if (!$this->access->canManageObjects($this->ref_id)) {
555 return;
556 }
557
558 $obj = new ilBookingObject($this->object_id);
559 $obj->deleteReservationsAndCalEntries($this->object_id);
560 $obj->delete();
561
562 $this->tpl->setOnScreenMessage('success', $this->lng->txt('book_object_deleted'), true);
563 $this->ctrl->setParameter($this, 'object_id', '');
564 $this->ctrl->redirect($this, 'render');
565 }
566
567 public function deliverInfo(): void
568 {
569 if (!$this->object_id) {
570 return;
571 }
572
573 $this->objects_manager->deliverObjectInfo($this->object_id);
574 }
575}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
importEditFormPostValues()
Load edit form values from post.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ilCtrl_Calls ilBookingObjectGUI: ilPropertyFormGUI, ilBookingProcessWithScheduleGUI,...
ScheduleManager $schedule_manager
StandardGUIRequest $book_request
ilBookBulkCreationGUI $bulk_creation_gui
BookingProcessManager $process_manager
ilAdvancedMDRecordGUI $record_gui
render(?Modal $modal=null)
initForm(string $a_mode='create', ?int $id=null)
ilObjectDataCache $obj_data_cache
edit(?ilPropertyFormGUI $a_form=null)
ilGlobalTemplateInterface $tpl
create(?ilPropertyFormGUI $a_form=null)
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...
Class ilCtrl provides processing control methods.
This class represents a file property in a property form.
This class represents a section header in a property form.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
class ilObjectDataCache
This class represents a property form user interface.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
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...
Filter service.
This describes commonalities between the different modals.
Definition: Modal.php:35
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26