ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilBookBulkCreationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
20 
25 {
26  protected \ILIAS\BookingManager\Objects\ObjectsManager $objects_manager;
30 
31  public function __construct(
32  InternalDomainService $domain,
33  InternalGUIService $gui,
34  ilObjBookingPool $pool
35  ) {
36  $this->pool = $pool;
37  $this->domain = $domain;
38  $this->gui = $gui;
39  $lng = $domain->lng();
40  $lng->loadLanguageModule("book");
41  $this->objects_manager = $domain
42  ->objects($pool->getId());
43  }
44 
45  public function executeCommand(): void
46  {
47  $ctrl = $this->gui->ctrl();
48 
49  $next_class = $ctrl->getNextClass($this);
50  $cmd = $ctrl->getCmd("showCreationForm");
51 
52  switch ($next_class) {
53  default:
54  if (in_array($cmd, [
55  "showCreationForm",
56  "showConfirmationScreen",
57  "cancelCreation",
58  "createObjects"
59  ])) {
60  $this->$cmd();
61  }
62  }
63  }
64 
65  public function modifyToolbar(ilToolbarGUI $toolbar): void
66  {
67  $lng = $this->domain->lng();
68  $ctrl = $this->gui->ctrl();
69  $components = $this
70  ->gui
71  ->modal($lng->txt("book_bulk_creation"))
72  ->getAsyncTriggerButtonComponents(
73  $lng->txt("book_bulk_creation"),
74  $ctrl->getLinkTarget($this, "showCreationForm", "", true),
75  false
76  );
77  foreach ($components as $type => $c) {
78  if ($type === "signal") {
79  continue;
80  }
81  $toolbar->addComponent($c);
82  }
83  }
84 
85  protected function showCreationForm(): void
86  {
87  $lng = $this->domain->lng();
88  $this->gui
89  ->modal($lng->txt("book_bulk_creation"))
90  ->form($this->getCreationForm())
91  ->send();
92  }
93 
94  protected function getCreationForm(): \ILIAS\Repository\Form\FormAdapterGUI
95  {
96  $lng = $this->domain->lng();
97  $schedule_manager = $this->domain->schedules($this->pool->getId());
98  $schedules = $schedule_manager->getScheduleList();
99  $form = $this
100  ->gui
101  ->form(self::class, "showConfirmationScreen")
102  ->asyncModal()
103  ->section("creation", $lng->txt("book_bulk_data"))
104  ->textarea(
105  "data",
106  $lng->txt("book_title_description_nr"),
107  $lng->txt("book_title_description_nr_info"),
108  )
109  ->required();
110 
111  if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE) {
112  $form->select(
113  "schedule_id",
114  $lng->txt("book_schedule"),
115  $schedules,
116  "",
117  (string) array_key_first($schedules)
118  )
119  ->required();
120  }
121 
122 
123  return $form;
124  }
125 
126  protected function showConfirmationScreen(): void
127  {
128  $form = $this->getCreationForm();
129  $lng = $this->domain->lng();
130  if (!$form->isValid()) {
131  $this->gui->modal($lng->txt("book_bulk_creation"))
132  ->form($form)
133  ->send();
134  }
135 
136  $schedule_id = 0;
137  if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE) {
138  $schedule_id = (int) $form->getData("schedule_id");
139  }
140  $this->gui->modal($lng->txt("book_bulk_creation"))
141  ->legacy($this->renderConfirmation(
142  $form->getData("data"),
143  $schedule_id
144  ))
145  ->send();
146  }
147 
148  protected function renderConfirmation(string $data, int $schedule_id = 0): string
149  {
150  $lng = $this->domain->lng();
151  $ctrl = $this->gui->ctrl();
152 
153  $f = $this->gui->ui()->factory();
154  $r = $this->gui->ui()->renderer();
155  $button1 = $f->button()->standard(
156  $lng->txt("book_create_objects"),
157  "#"
158  )->withAdditionalOnLoadCode(static function (string $id) {
159  return <<<EOT
160  globalThis.book_bulk_button = document.getElementById("$id");
161  book_bulk_button.addEventListener("click", (event) => {
162  book_bulk_button.closest(".c-modal").querySelector(".modal-body").querySelector("form").submit();
163  });
164 EOT;
165  });
166  $button2 = $f->button()->standard(
167  $lng->txt("cancel"),
168  $ctrl->getLinkTarget($this, "cancelCreation")
169  );
170 
171  $mbox = $f->messageBox()->confirmation(
172  $lng->txt("book_bulk_confirmation")
173  )->withButtons([$button1]);
174 
175  $ctrl->setParameter($this, "schedule_id", $schedule_id);
176  $table = new ilBookingBulkCreationTableGUI(
177  $this,
178  "renderConfirmation",
179  $data,
180  $this->pool->getId()
181  );
182 
183  return $r->render($mbox) .
184  $table->getHTML();
185  }
186 
187  protected function createObjects(): void
188  {
189  $main_tpl = $this->gui->mainTemplate();
190  $ctrl = $this->gui->ctrl();
191  $lng = $this->domain->lng();
192  $request = $this->gui->standardRequest();
193 
194  $data = $request->getBulkCreationData();
195  $schedule_id = 0;
196  if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE) {
197  $schedule_id = $request->getScheduleId();
198  }
199  $arr = $this->objects_manager->createObjectsFromBulkInputString($data, $schedule_id);
200  $main_tpl->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
201  $ctrl->returnToParent($this);
202  }
203 
204  protected function cancelCreation(): void
205  {
206  $ctrl = $this->gui->ctrl();
207  $ctrl->returnToParent($this);
208  }
209 }
Interface Observer Contains several chained tasks and infos about them.
addComponent(\ILIAS\UI\Component\Component $a_comp)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:9
ILIAS BookingManager Objects ObjectsManager $objects_manager
renderConfirmation(string $data, int $schedule_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$components
__construct(InternalDomainService $domain, InternalGUIService $gui, ilObjBookingPool $pool)
modifyToolbar(ilToolbarGUI $toolbar)
Author: Alexander Killing killing@leifos.de
legacy()
expected output: > ILIAS shows the rendered Component.
Definition: legacy.php:13
form( $class_path, string $cmd, string $submit_caption="")
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
global $lng
Definition: privfeed.php:32
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:97
$r