ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingObjectGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\BookingManager\Objects\ObjectsManager $objects_manager;
27 protected \ILIAS\BookingManager\Schedule\ScheduleManager $schedule_manager;
30 protected \ILIAS\BookingManager\InternalGUIService $gui;
31 protected \ILIAS\BookingManager\Access\AccessManager $access;
32 protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
33 protected ilCtrl $ctrl;
35 protected ilLanguage $lng;
36 protected ilTabsGUI $tabs;
39 protected ilObjUser $user;
40 protected bool $pool_has_schedule;
41 protected ?int $pool_overall_limit;
42 protected bool $pool_uses_preferences = false;
43 // Is management of objects (create/edit/delete) activated?
44 protected bool $management = true;
45 // Context object id (e.g. course with booking service activated)
46 protected int $context_obj_id;
47 protected int $object_id;
48 protected string $seed;
49 protected string $sseed;
51 protected array $rsv_ids = [];
53 protected int $ref_id;
54
55 public function __construct(
56 ilObjBookingPoolGUI $a_parent_obj,
57 string $seed,
58 string $sseed,
60 int $context_obj_id = 0
61 ) {
62 global $DIC;
63
64 $this->ctrl = $DIC->ctrl();
65 $this->tpl = $DIC["tpl"];
66 $this->lng = $DIC->language();
67 $this->access = $DIC->bookingManager()->internal()->domain()->access();
68 $this->tabs = $DIC->tabs();
69 $this->help = $help;
70 $this->obj_data_cache = $DIC["ilObjDataCache"];
71 $this->user = $DIC->user();
72
74 $pool = $a_parent_obj->getObject();
75 $this->pool = $pool;
76
77 $this->book_request = $DIC
78 ->bookingManager()
79 ->internal()
80 ->gui()
81 ->standardRequest();
82 $this->gui = $DIC->bookingManager()->internal()->gui();
83 $this->schedule_manager = $DIC
84 ->bookingManager()
85 ->internal()
86 ->domain()
87 ->schedules($this->pool->getId());
88
89 $this->seed = $seed;
90 $this->sseed = $sseed;
91
92 $this->context_obj_id = $context_obj_id;
93
94 $this->pool_gui = $a_parent_obj;
95 $this->bulk_creation_gui = $this->gui->objects()
96 ->ilBookBulkCreationGUI($this->pool);
97
98 $this->pool_has_schedule =
99 ($a_parent_obj->getObject()->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE);
100 $this->pool_uses_preferences =
101 ($a_parent_obj->getObject()->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES);
102 $this->pool_overall_limit = $this->pool_has_schedule
103 ? null
104 : $a_parent_obj->getObject()->getOverallLimit();
105
106 $this->object_id = $this->book_request->getObjectId();
107 $this->ref_id = $this->book_request->getRefId();
108 $this->ctrl->saveParameter($this, "object_id");
109
110 $this->rsv_ids = array_map('intval', $this->book_request->getReservationIdsFromString());
111 $this->objects_manager = $DIC->bookingManager()->internal()->domain()->objects($this->pool->getId());
112
113 $this->access->validateBookingObjId(
114 $this->object_id,
115 (int) $this->pool_gui->getObject()?->getId()
116 );
117 }
118
119 public function activateManagement(bool $a_val): void
120 {
121 $this->management = $a_val;
122 }
123
127 public function isManagementActivated(): bool
128 {
129 return $this->management;
130 }
131
132 protected function getPoolRefId(): int
133 {
134 return $this->pool_gui->getRefId();
135 }
136
137 protected function getPoolObjId(): int
138 {
139 return $this->pool_gui->getObject()->getId();
140 }
141
145 protected function hasPoolSchedule(): bool
146 {
147 return ($this->pool_gui->getObject()->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE);
148 }
149
153 protected function getPoolOverallLimit(): ?int
154 {
155 return $this->hasPoolSchedule()
156 ? null
157 : $this->pool_gui->getObject()->getOverallLimit();
158 }
159
163 public function executeCommand(): void
164 {
165 $ilCtrl = $this->ctrl;
166
167 $next_class = $ilCtrl->getNextClass($this);
168
169 switch ($next_class) {
170 case "ilpropertyformgui":
171 // only case is currently adv metadata internal link in info settings, see #24497
172 $form = $this->initForm();
173 $this->ctrl->forwardCommand($form);
174 break;
175
176 case "ilbookingprocesswithschedulegui":
177 if (!$this->pool_uses_preferences) {
178 $ilCtrl->setReturn($this, "render");
179 } else {
180 $ilCtrl->setReturn($this, "returnToPreferences");
181 }
183 $pool = $this->pool_gui->getObject();
184 $process_gui = $this->gui->process()->ilBookingProcessWithScheduleGUI(
185 $pool,
186 $this->object_id,
187 $this->context_obj_id,
188 $this->seed ?? $this->sseed
189 );
190 $this->ctrl->forwardCommand($process_gui);
191 break;
192
193 case "ilbookingprocesswithoutschedulegui":
194 if (!$this->pool_uses_preferences) {
195 $ilCtrl->setReturn($this, "render");
196 } else {
197 $ilCtrl->setReturn($this, "returnToPreferences");
198 }
200 $pool = $this->pool_gui->getObject();
201 $process_gui = $this->gui->process()->ilBookingProcessWithoutScheduleGUI(
202 $pool,
203 $this->object_id,
204 $this->context_obj_id
205 );
206 $this->ctrl->forwardCommand($process_gui);
207 break;
208
209 case strtolower(ilBookBulkCreationGUI::class):
210 $this->ctrl->setReturn($this, "");
211 $this->ctrl->forwardCommand($this->bulk_creation_gui);
212 break;
213
214 default:
215 $cmd = $ilCtrl->getCmd("render");
216 $this->$cmd();
217 break;
218 }
219 }
220
221 protected function showNoScheduleMessage(): void
222 {
223 $this->pool_gui->showNoScheduleMessage();
224 }
225
226 protected function returnToPreferences(): void
227 {
228 $this->ctrl->redirectByClass("ilBookingPreferencesGUI");
229 }
230
235 public function render(): void
236 {
237 $this->showNoScheduleMessage();
238
239 $tpl = $this->tpl;
240 $ilCtrl = $this->ctrl;
242
243 $bar = "";
244
245 if ($this->isManagementActivated() && $this->access->canManageObjects($this->getPoolRefId())) {
246 $bar = new ilToolbarGUI();
247 $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
248
249 // bulk creation
250 $this->bulk_creation_gui->modifyToolbar($bar);
251
252 if ($this->hasPoolSchedule()) {
253 $bar->addSeparator();
254 $list_link = $this->ctrl->getLinkTarget($this, "");
255 $week_link = $this->ctrl->getLinkTargetByClass("ilBookingProcessWithScheduleGUI", "week");
256 $mode_control = $this->gui->ui()->factory()->viewControl()->mode([
257 $this->lng->txt("book_list") => $list_link,
258 $this->lng->txt("book_week") => $week_link
259 ], $this->lng->txt("book_view"));
260 $bar->addComponent($mode_control);
261 }
262 $bar = $bar->getHTML();
263 }
264
265 $tpl->setPermanentLink('book', $this->getPoolRefId());
266
267 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
268 $tpl->setContent($bar . $table->getHTML());
269 }
270
271 public function applyFilter(): void
272 {
273 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
274 $table->resetOffset();
275 $table->writeFilterToSession();
276 $this->render();
277 }
278
279 public function resetFilter(): void
280 {
281 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
282 $table->resetOffset();
283 $table->resetFilter();
284 $this->render();
285 }
286
290 public function create(?ilPropertyFormGUI $a_form = null): void
291 {
292 if (!$this->access->canManageObjects($this->ref_id)) {
293 return;
294 }
295
296 $ilCtrl = $this->ctrl;
299 $ilTabs = $this->tabs;
300
301 $ilTabs->clearTargets();
302 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
303
304 $this->setHelpId('create');
305
306 if (!$a_form) {
307 $a_form = $this->initForm();
308 }
309 $tpl->setContent($a_form->getHTML());
310 }
311
315 public function edit(?ilPropertyFormGUI $a_form = null): void
316 {
317 if (!$this->access->canManageObjects($this->ref_id)) {
318 return;
319 }
320
322 $ilCtrl = $this->ctrl;
323 $ilTabs = $this->tabs;
325
326 $ilTabs->clearTargets();
327 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
328
329 $this->setHelpId('edit');
330
331 if (!$a_form) {
332 $a_form = $this->initForm('edit', $this->object_id);
333 }
334 $tpl->setContent($a_form->getHTML());
335 }
336
337 protected function setHelpId(string $a_id): void
338 {
339 $this->help->setHelpId($a_id);
340 }
341
345 public function initForm(
346 string $a_mode = "create",
347 ?int $id = null
349 $lng = $this->lng;
350 $ilCtrl = $this->ctrl;
351 $ilObjDataCache = $this->obj_data_cache;
352
353 $form_gui = new ilPropertyFormGUI();
354
355 $title = new ilTextInputGUI($lng->txt("title"), "title");
356 $title->setRequired(true);
357 $title->setSize(40);
358 $title->setMaxLength(120);
359 $form_gui->addItem($title);
360
361 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
362 $desc->setCols(70);
363 $desc->setRows(15);
364 $desc->setMaxNumOfChars(1000);
365 $form_gui->addItem($desc);
366
367 $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
368 $file->setAllowDeletion(true);
369 $form_gui->addItem($file);
370
371 $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
372 $nr->setRequired(true);
373 $nr->setSize(3);
374 $nr->setMaxLength(3);
375 $nr->setSuffix($lng->txt("book_booking_objects"));
376 $form_gui->addItem($nr);
377
378 if ($this->hasPoolSchedule()) {
379 $options = array();
380 foreach ($this->schedule_manager->getScheduleList() as $schedule_id => $schedule_title) {
381 $options[$schedule_id] = $schedule_title;
382 }
383 $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
384 $schedule->setRequired(true);
385 $schedule->setOptions($options);
386 $form_gui->addItem($schedule);
387 }
388
390 $post->setTitle($lng->txt("book_post_booking_information"));
391 $form_gui->addItem($post);
392
393 $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
394 $pdesc->setCols(70);
395 $pdesc->setRows(15);
396 $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
397 $form_gui->addItem($pdesc);
398
399 $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
400 $pfile->setAllowDeletion(true);
401 $form_gui->addItem($pfile);
402
403 // #18214 - should also work for new objects
404 $this->record_gui = new ilAdvancedMDRecordGUI(
406 "book",
407 $this->getPoolObjId(),
408 "bobj",
409 (int) $id
410 );
411 $this->record_gui->setPropertyForm($form_gui);
412 $this->record_gui->parse();
413
414 if ($a_mode === "edit") {
415 $form_gui->setTitle($lng->txt("book_edit_object"));
416
417 $item = new ilHiddenInputGUI('object_id');
418 $item->setValue($id);
419 $form_gui->addItem($item);
420
421 $obj = new ilBookingObject($id);
422 $title->setValue($obj->getTitle());
423 $desc->setValue($obj->getDescription());
424 $nr->setValue($obj->getNrOfItems());
425 $pdesc->setValue($obj->getPostText());
426 $file->setValue($this->objects_manager->getObjectInfoFilename($id));
427 $pfile->setValue($this->objects_manager->getBookingInfoFilename($id));
428
429 if (isset($schedule)) {
430 $schedule->setValue($obj->getScheduleId());
431 }
432
433 $form_gui->addCommandButton("update", $lng->txt("save"));
434 } else {
435 $form_gui->setTitle($lng->txt("book_add_object"));
436 $form_gui->addCommandButton("save", $lng->txt("save"));
437 $form_gui->addCommandButton("render", $lng->txt("cancel"));
438 }
439 $form_gui->setFormAction($ilCtrl->getFormAction($this));
440
441 return $form_gui;
442 }
443
444 public function save(): void
445 {
446 if (!$this->access->canManageObjects($this->ref_id)) {
447 return;
448 }
449
450 $ilCtrl = $this->ctrl;
452
453 $form = $this->initForm();
454 if ($form->checkInput()) {
455 $valid = true;
456 if ($this->record_gui &&
457 !$this->record_gui->importEditFormPostValues()) {
458 $valid = false;
459 }
460 if ($valid) {
461 $obj = new ilBookingObject();
462 $obj->setPoolId($this->getPoolObjId());
463 $obj->setTitle($form->getInput("title"));
464 $obj->setDescription($form->getInput("desc"));
465 $obj->setNrOfItems($form->getInput("items"));
466 $obj->setPostText($form->getInput("post_text"));
467
468 if ($this->hasPoolSchedule()) {
469 $obj->setScheduleId($form->getInput("schedule"));
470 }
471
472 $obj->save();
473
474 $file = $form->getItemByPostVar("file");
475 if ($_FILES["file"]["tmp_name"]) {
476 $this->objects_manager->importObjectInfoFromLegacyUpload($obj->getId(), $_FILES["file"]);
477 } elseif ($file !== null && $file->getDeletionFlag()) {
478 $this->objects_manager->deleteObjectInfo($obj->getId());
479 }
480
481 $pfile = $form->getItemByPostVar("post_file");
482 if ($_FILES["post_file"]["tmp_name"]) {
483 $this->objects_manager->importBookingInfoFromLegacyUpload($obj->getId(), $_FILES["post_file"]);
484 } elseif ($pfile !== null && $pfile->getDeletionFlag()) {
485 $this->objects_manager->deleteBookingInfo($obj->getId());
486 }
487
488 $obj->update();
489
490 if ($this->record_gui) {
491 $this->record_gui->writeEditForm(null, $obj->getId());
492 }
493
494 $this->tpl->setOnScreenMessage('success', $lng->txt("book_object_added"), true);
495 $ilCtrl->redirect($this, "render");
496 }
497 }
498
499 $form->setValuesByPost();
500 $this->create($form);
501 }
502
503 public function update(): void
504 {
505 if (!$this->access->canManageObjects($this->ref_id)) {
506 return;
507 }
508
510 $ilCtrl = $this->ctrl;
511
512 $form = $this->initForm('edit', $this->object_id);
513 if ($form->checkInput()) {
514 $valid = true;
515 if ($this->record_gui &&
516 !$this->record_gui->importEditFormPostValues()) {
517 $valid = false;
518 }
519
520 if ($valid) {
521 $obj = new ilBookingObject($this->object_id);
522 $obj->setTitle($form->getInput("title"));
523 $obj->setDescription($form->getInput("desc"));
524 $obj->setNrOfItems($form->getInput("items"));
525 $obj->setPostText($form->getInput("post_text"));
526
527 $file = $form->getItemByPostVar("file");
528 if ($_FILES["file"]["tmp_name"]) {
529 $this->objects_manager->importObjectInfoFromLegacyUpload($obj->getId(), $_FILES["file"]);
530 } elseif ($file !== null && $file->getDeletionFlag()) {
531 $this->objects_manager->deleteObjectInfo($obj->getId());
532 }
533
534 $pfile = $form->getItemByPostVar("post_file");
535 if ($_FILES["post_file"]["tmp_name"]) {
536 $this->objects_manager->importBookingInfoFromLegacyUpload($obj->getId(), $_FILES["post_file"]);
537 } elseif ($pfile !== null && $pfile->getDeletionFlag()) {
538 $this->objects_manager->deleteBookingInfo($obj->getId());
539 }
540
541 if ($this->hasPoolSchedule()) {
542 $obj->setScheduleId($form->getInput("schedule"));
543 }
544
545 $obj->update();
546
547 if ($this->record_gui) {
548 $this->record_gui->writeEditForm();
549 }
550
551 $this->tpl->setOnScreenMessage('success', $lng->txt("book_object_updated"), true);
552 $ilCtrl->redirect($this, "edit");
553 }
554 }
555
556 $form->setValuesByPost();
557 $this->edit($form);
558 }
559
560 public function confirmDelete(): void
561 {
562 if (!$this->access->canManageObjects($this->ref_id)) {
563 return;
564 }
565
566 $ilCtrl = $this->ctrl;
568 $tpl = $this->tpl;
569 $ilTabs = $this->tabs;
570
571 $ilTabs->clearTargets();
572 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
573
574 $conf = new ilConfirmationGUI();
575 $conf->setFormAction($ilCtrl->getFormAction($this));
576 $conf->setHeaderText($lng->txt('book_confirm_delete'));
577
578 $type = new ilBookingObject($this->object_id);
579 $conf->addItem('object_id', $this->object_id, $type->getTitle());
580 $conf->setConfirm($lng->txt('delete'), 'delete');
581 $conf->setCancel($lng->txt('cancel'), 'render');
582
583 $tpl->setContent($conf->getHTML());
584 }
585
586 public function delete(): void
587 {
588 if (!$this->access->canManageObjects($this->ref_id)) {
589 return;
590 }
591
592 $ilCtrl = $this->ctrl;
594
595 $obj = new ilBookingObject($this->object_id);
596 $obj->deleteReservationsAndCalEntries($this->object_id);
597 $obj->delete();
598
599 $this->tpl->setOnScreenMessage('success', $lng->txt('book_object_deleted'), true);
600 $ilCtrl->setParameter($this, 'object_id', "");
601 $ilCtrl->redirect($this, 'render');
602 }
603
604
605 public function deliverInfo(): void
606 {
607 $id = $this->object_id;
608 if (!$id) {
609 return;
610 }
611
612 $this->objects_manager->deliverObjectInfo($id);
613 }
614}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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...
ILIAS BookingManager StandardGUIRequest $book_request
ilBookBulkCreationGUI $bulk_creation_gui
isManagementActivated()
Is management activated?
hasPoolSchedule()
Has booking pool a schedule?
getPoolOverallLimit()
Get booking pool overall limit.
ilAdvancedMDRecordGUI $record_gui
ilObjBookingPoolGUI $pool_gui
ilObjectDataCache $obj_data_cache
edit(?ilPropertyFormGUI $a_form=null)
Render edit form.
ILIAS BookingManager Objects ObjectsManager $objects_manager
initForm(string $a_mode="create", ?int $id=null)
Build property form.
ilGlobalTemplateInterface $tpl
ilBookingHelpAdapter $help
ILIAS BookingManager Access AccessManager $access
render()
Render list of booking objects uses ilBookingObjectsTableGUI.
ILIAS BookingManager Schedule ScheduleManager $schedule_manager
create(?ilPropertyFormGUI $a_form=null)
Render creation form.
ILIAS BookingManager InternalGUIService $gui
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
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
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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...
clearTargets()
clear all targets
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...
$valid
setPermanentLink(string $a_type, ?int $a_id, string $a_append="", string $a_target="", string $a_title="")
Generates and sets a permanent ilias link.
setContent(string $a_html)
Sets content for standard template.
$post
Definition: ltitoken.php:46
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26