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