ILIAS  release_8 Revision v8.24
class.ilBookingObjectGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
26 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
30 protected ilTabsGUI $tabs;
33 protected ilObjUser $user;
34 protected bool $pool_has_schedule;
35 protected ?int $pool_overall_limit;
36 protected bool $pool_uses_preferences = false;
37 // Is management of objects (create/edit/delete) activated?
38 protected bool $management = true;
39 // Context object id (e.g. course with booking service activated)
40 protected int $context_obj_id;
41 protected int $object_id;
42 protected string $seed;
43 protected string $sseed;
45 protected array $rsv_ids = [];
47 protected int $ref_id;
48
49 public function __construct(
50 ilObjBookingPoolGUI $a_parent_obj,
51 string $seed,
52 string $sseed,
54 int $context_obj_id = 0
55 ) {
56 global $DIC;
57
58 $this->ctrl = $DIC->ctrl();
59 $this->tpl = $DIC["tpl"];
60 $this->lng = $DIC->language();
61 $this->access = $DIC->access();
62 $this->tabs = $DIC->tabs();
63 $this->help = $help;
64 $this->obj_data_cache = $DIC["ilObjDataCache"];
65 $this->user = $DIC->user();
66
67 $this->book_request = $DIC->bookingManager()
68 ->internal()
69 ->gui()
70 ->standardRequest();
71
72
73 $this->seed = $seed;
74 $this->sseed = $sseed;
75
76 $this->context_obj_id = $context_obj_id;
77
78 $this->pool_gui = $a_parent_obj;
79 $this->pool_has_schedule =
80 ($a_parent_obj->getObject()->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE);
81 $this->pool_uses_preferences =
82 ($a_parent_obj->getObject()->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES);
83 $this->pool_overall_limit = $this->pool_has_schedule
84 ? null
85 : $a_parent_obj->getObject()->getOverallLimit();
86
87 $this->object_id = $this->book_request->getObjectId();
88 $this->ref_id = $this->book_request->getRefId();
89 $this->ctrl->saveParameter($this, "object_id");
90
91 if ($this->object_id > 0 && ilBookingObject::lookupPoolId($this->object_id) !== $this->pool_gui->getObject()->getId()) {
92 throw new ilPermissionException("Booking object pool id does not match pool id.");
93 }
94
95 $this->rsv_ids = array_map('intval', $this->book_request->getReservationIdsFromString());
96 }
97
98 public function activateManagement(bool $a_val): void
99 {
100 $this->management = $a_val;
101 }
102
106 public function isManagementActivated(): bool
107 {
108 return $this->management;
109 }
110
111 protected function getPoolRefId(): int
112 {
113 return $this->pool_gui->getRefId();
114 }
115
116 protected function getPoolObjId(): int
117 {
118 return $this->pool_gui->getObject()->getId();
119 }
120
124 protected function hasPoolSchedule(): bool
125 {
126 return ($this->pool_gui->getObject()->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE);
127 }
128
132 protected function getPoolOverallLimit(): ?int
133 {
134 return $this->hasPoolSchedule()
135 ? null
136 : $this->pool_gui->getObject()->getOverallLimit();
137 }
138
142 public function executeCommand(): void
143 {
144 $ilCtrl = $this->ctrl;
145
146 $next_class = $ilCtrl->getNextClass($this);
147
148 switch ($next_class) {
149
150 case "ilpropertyformgui":
151 // only case is currently adv metadata internal link in info settings, see #24497
152 $form = $this->initForm();
153 $this->ctrl->forwardCommand($form);
154 break;
155
156 case "ilbookingprocessgui":
157 if (!$this->pool_uses_preferences) {
158 $ilCtrl->setReturn($this, "render");
159 } else {
160 $ilCtrl->setReturn($this, "returnToPreferences");
161 }
163 $pool = $this->pool_gui->getObject();
164 $process_gui = new ilBookingProcessGUI(
165 $pool,
166 $this->object_id,
167 $this->help,
168 $this->seed,
169 $this->sseed,
170 $this->context_obj_id
171 );
172 $this->ctrl->forwardCommand($process_gui);
173 break;
174
175 default:
176 $cmd = $ilCtrl->getCmd("render");
177 $this->$cmd();
178 break;
179 }
180 }
181
182 protected function showNoScheduleMessage(): void
183 {
184 $this->pool_gui->showNoScheduleMessage();
185 }
186
187 protected function returnToPreferences(): void
188 {
189 $this->ctrl->redirectByClass("ilBookingPreferencesGUI");
190 }
191
196 public function render(): void
197 {
198 $this->showNoScheduleMessage();
199
200 $tpl = $this->tpl;
201 $ilCtrl = $this->ctrl;
203 $ilAccess = $this->access;
204
205 $bar = "";
206
207 if ($this->isManagementActivated() && $ilAccess->checkAccess('write', '', $this->getPoolRefId())) {
208 $bar = new ilToolbarGUI();
209 $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
210 $bar = $bar->getHTML();
211 }
212
213 $tpl->setPermanentLink('book', $this->getPoolRefId());
214
215 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
216 $tpl->setContent($bar . $table->getHTML());
217 }
218
219 public function applyFilter(): void
220 {
221 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
222 $table->resetOffset();
223 $table->writeFilterToSession();
224 $this->render();
225 }
226
227 public function resetFilter(): void
228 {
229 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
230 $table->resetOffset();
231 $table->resetFilter();
232 $this->render();
233 }
234
238 public function create(ilPropertyFormGUI $a_form = null): void
239 {
240 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
241 return;
242 }
243
244 $ilCtrl = $this->ctrl;
247 $ilTabs = $this->tabs;
248
249 $ilTabs->clearTargets();
250 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
251
252 $this->setHelpId('create');
253
254 if (!$a_form) {
255 $a_form = $this->initForm();
256 }
257 $tpl->setContent($a_form->getHTML());
258 }
259
263 public function edit(ilPropertyFormGUI $a_form = null): void
264 {
265 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
266 return;
267 }
268
270 $ilCtrl = $this->ctrl;
271 $ilTabs = $this->tabs;
273
274 $ilTabs->clearTargets();
275 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
276
277 $this->setHelpId('edit');
278
279 if (!$a_form) {
280 $a_form = $this->initForm('edit', $this->object_id);
281 }
282 $tpl->setContent($a_form->getHTML());
283 }
284
285 protected function setHelpId(string $a_id): void
286 {
287 $this->help->setHelpId($a_id);
288 }
289
293 public function initForm(
294 string $a_mode = "create",
295 int $id = null
297 $lng = $this->lng;
298 $ilCtrl = $this->ctrl;
299 $ilObjDataCache = $this->obj_data_cache;
300
301 $form_gui = new ilPropertyFormGUI();
302
303 $title = new ilTextInputGUI($lng->txt("title"), "title");
304 $title->setRequired(true);
305 $title->setSize(40);
306 $title->setMaxLength(120);
307 $form_gui->addItem($title);
308
309 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
310 $desc->setCols(70);
311 $desc->setRows(15);
312 $desc->setMaxNumOfChars(1000);
313 $form_gui->addItem($desc);
314
315 $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
316 $file->setAllowDeletion(true);
317 $form_gui->addItem($file);
318
319 $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
320 $nr->setRequired(true);
321 $nr->setSize(3);
322 $nr->setMaxLength(3);
323 $nr->setSuffix($lng->txt("book_booking_objects"));
324 $form_gui->addItem($nr);
325
326 if ($this->hasPoolSchedule()) {
327 $options = array();
328 foreach (ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->getPoolRefId())) as $schedule) {
329 $options[$schedule["booking_schedule_id"]] = $schedule["title"];
330 }
331 $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
332 $schedule->setRequired(true);
333 $schedule->setOptions($options);
334 $form_gui->addItem($schedule);
335 }
336
338 $post->setTitle($lng->txt("book_post_booking_information"));
339 $form_gui->addItem($post);
340
341 $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
342 $pdesc->setCols(70);
343 $pdesc->setRows(15);
344 $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
345 $form_gui->addItem($pdesc);
346
347 $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
348 $pfile->setAllowDeletion(true);
349 $form_gui->addItem($pfile);
350
351 // #18214 - should also work for new objects
352 $this->record_gui = new ilAdvancedMDRecordGUI(
354 "book",
355 $this->getPoolObjId(),
356 "bobj",
357 (int) $id
358 );
359 $this->record_gui->setPropertyForm($form_gui);
360 $this->record_gui->parse();
361
362 if ($a_mode === "edit") {
363 $form_gui->setTitle($lng->txt("book_edit_object"));
364
365 $item = new ilHiddenInputGUI('object_id');
366 $item->setValue($id);
367 $form_gui->addItem($item);
368
369 $obj = new ilBookingObject($id);
370 $title->setValue($obj->getTitle());
371 $desc->setValue($obj->getDescription());
372 $nr->setValue($obj->getNrOfItems());
373 $pdesc->setValue($obj->getPostText());
374 $file->setValue($obj->getFile());
375 $pfile->setValue($obj->getPostFile());
376
377 if (isset($schedule)) {
378 $schedule->setValue($obj->getScheduleId());
379 }
380
381 $form_gui->addCommandButton("update", $lng->txt("save"));
382 } else {
383 $form_gui->setTitle($lng->txt("book_add_object"));
384 $form_gui->addCommandButton("save", $lng->txt("save"));
385 $form_gui->addCommandButton("render", $lng->txt("cancel"));
386 }
387 $form_gui->setFormAction($ilCtrl->getFormAction($this));
388
389 return $form_gui;
390 }
391
392 public function save(): void
393 {
394 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
395 return;
396 }
397
398 $ilCtrl = $this->ctrl;
400
401 $form = $this->initForm();
402 if ($form->checkInput()) {
403 $valid = true;
404 if ($this->record_gui &&
405 !$this->record_gui->importEditFormPostValues()) {
406 $valid = false;
407 }
408 if ($valid) {
409 $obj = new ilBookingObject();
410 $obj->setPoolId($this->getPoolObjId());
411 $obj->setTitle($form->getInput("title"));
412 $obj->setDescription($form->getInput("desc"));
413 $obj->setNrOfItems($form->getInput("items"));
414 $obj->setPostText($form->getInput("post_text"));
415
416 if ($this->hasPoolSchedule()) {
417 $obj->setScheduleId($form->getInput("schedule"));
418 }
419
420 $obj->save();
421
422 $file = $form->getItemByPostVar("file");
423 if ($_FILES["file"]["tmp_name"]) {
424 $obj->uploadFile($_FILES["file"]);
425 } elseif ($file !== null && $file->getDeletionFlag()) {
426 $obj->deleteFile();
427 }
428
429 $pfile = $form->getItemByPostVar("post_file");
430 if ($_FILES["post_file"]["tmp_name"]) {
431 $obj->uploadPostFile($_FILES["post_file"]);
432 } elseif ($pfile !== null && $pfile->getDeletionFlag()) {
433 $obj->deletePostFile();
434 }
435
436 $obj->update();
437
438 if ($this->record_gui) {
439 $this->record_gui->writeEditForm(null, $obj->getId());
440 }
441
442 $this->tpl->setOnScreenMessage('success', $lng->txt("book_object_added"), true);
443 $ilCtrl->redirect($this, "render");
444 }
445 }
446
447 $form->setValuesByPost();
448 $this->create($form);
449 }
450
451 public function update(): void
452 {
453 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
454 return;
455 }
456
458 $ilCtrl = $this->ctrl;
459
460 $form = $this->initForm('edit', $this->object_id);
461 if ($form->checkInput()) {
462 $valid = true;
463 if ($this->record_gui &&
464 !$this->record_gui->importEditFormPostValues()) {
465 $valid = false;
466 }
467
468 if ($valid) {
469 $obj = new ilBookingObject($this->object_id);
470 $obj->setTitle($form->getInput("title"));
471 $obj->setDescription($form->getInput("desc"));
472 $obj->setNrOfItems($form->getInput("items"));
473 $obj->setPostText($form->getInput("post_text"));
474
475 $file = $form->getItemByPostVar("file");
476 if ($_FILES["file"]["tmp_name"]) {
477 $obj->uploadFile($_FILES["file"]);
478 } elseif ($file !== null && $file->getDeletionFlag()) {
479 $obj->deleteFile();
480 }
481
482 $pfile = $form->getItemByPostVar("post_file");
483 if ($_FILES["post_file"]["tmp_name"]) {
484 $obj->uploadPostFile($_FILES["post_file"]);
485 } elseif ($pfile !== null && $pfile->getDeletionFlag()) {
486 $obj->deletePostFile();
487 }
488
489 if ($this->hasPoolSchedule()) {
490 $obj->setScheduleId($form->getInput("schedule"));
491 }
492
493 $obj->update();
494
495 if ($this->record_gui) {
496 $this->record_gui->writeEditForm();
497 }
498
499 $this->tpl->setOnScreenMessage('success', $lng->txt("book_object_updated"), true);
500 $ilCtrl->redirect($this, "render");
501 }
502 }
503
504 $form->setValuesByPost();
505 $this->edit($form);
506 }
507
508 public function confirmDelete(): void
509 {
510 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
511 return;
512 }
513
514 $ilCtrl = $this->ctrl;
517 $ilTabs = $this->tabs;
518
519 $ilTabs->clearTargets();
520 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
521
522 $conf = new ilConfirmationGUI();
523 $conf->setFormAction($ilCtrl->getFormAction($this));
524 $conf->setHeaderText($lng->txt('book_confirm_delete'));
525
526 $type = new ilBookingObject($this->object_id);
527 $conf->addItem('object_id', $this->object_id, $type->getTitle());
528 $conf->setConfirm($lng->txt('delete'), 'delete');
529 $conf->setCancel($lng->txt('cancel'), 'render');
530
531 $tpl->setContent($conf->getHTML());
532 }
533
534 public function delete(): void
535 {
536 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
537 return;
538 }
539
540 $ilCtrl = $this->ctrl;
542
543 $obj = new ilBookingObject($this->object_id);
544 $obj->deleteReservationsAndCalEntries($this->object_id);
545 $obj->delete();
546
547 $this->tpl->setOnScreenMessage('success', $lng->txt('book_object_deleted'), true);
548 $ilCtrl->setParameter($this, 'object_id', "");
549 $ilCtrl->redirect($this, 'render');
550 }
551
552
553 public function deliverInfo(): void
554 {
555 $id = $this->object_id;
556 if (!$id) {
557 return;
558 }
559
560 $obj = new ilBookingObject($id);
561 $file = $obj->getFileFullPath();
562 if ($file) {
563 ilFileDelivery::deliverFileLegacy($file, $obj->getFile());
564 }
565 }
566}
$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
edit(ilPropertyFormGUI $a_form=null)
Render edit form.
isManagementActivated()
Is management activated?
hasPoolSchedule()
Has booking pool a schedule?
getPoolOverallLimit()
Get booking pool overall limit.
initForm(string $a_mode="create", int $id=null)
Build property form.
ilAdvancedMDRecordGUI $record_gui
ilObjBookingPoolGUI $pool_gui
ilObjectDataCache $obj_data_cache
ilGlobalTemplateInterface $tpl
ilBookingHelpAdapter $help
render()
Render list of booking objects uses ilBookingObjectsTableGUI.
__construct(ilObjBookingPoolGUI $a_parent_obj, string $seed, string $sseed, ilBookingHelpAdapter $help, int $context_obj_id=0)
create(ilPropertyFormGUI $a_form=null)
Render creation form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupPoolId(int $object_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...
static getList(int $a_pool_id)
Get list of booking objects for given pool.
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
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
This class represents a file property in a property form.
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...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
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 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
global $DIC
Definition: feed.php:28
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...
setContent(string $a_html)
Sets content for standard template.
setPermanentLink(string $a_type, ?int $a_id, string $a_append="", string $a_target="", string $a_title="")
Generates and sets a permanent ilias link.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$post
Definition: ltitoken.php:49
$type
$lng