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