ILIAS  release_8 Revision v8.24
class.ilBookingGatewayGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
30 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
32 protected \ilGlobalTemplateInterface $main_tpl;
34 protected ilTabsGUI $tabs;
35 protected int $obj_id;
36 protected int $ref_id;
38 protected int $current_pool_ref_id;
39 protected ?ilObjBookingPool $pool = null;
41 protected int $main_host_ref_id = 0;
42 // Have any pools been already selected?
43 protected bool $pools_selected = false;
44 protected string $seed;
45 protected string $sseed;
47 protected string $return_to = "";
49
50 public function __construct(
52 int $main_host_ref_id = 0
53 ) {
54 global $DIC;
55
56 $this->ctrl = $DIC->ctrl();
57 $this->lng = $DIC->language();
58 $this->main_tpl = $DIC->ui()->mainTemplate();
59 $this->parent_gui = $parent_gui;
60 $this->tabs = $DIC->tabs();
61 $this->book_request = $DIC->bookingManager()
62 ->internal()
63 ->gui()
64 ->standardRequest();
65
66 $this->lng->loadLanguageModule("book");
67
68 // current parent context (e.g. session in course)
69 $this->obj_id = $parent_gui->getObject()->getId();
70 $this->ref_id = $parent_gui->getObject()->getRefId();
71
72 $this->main_host_ref_id = ($main_host_ref_id === 0)
73 ? $this->ref_id
75
76
77 $this->seed = $this->book_request->getSeed();
78 $this->sseed = $this->book_request->getSSeed();
79
80 $this->toolbar = $DIC->toolbar();
81
82 $this->use_book_repo = new ilObjUseBookDBRepository($DIC->database());
83
84 $req_return_to = $this->book_request->getReturnTo();
85 if (in_array($req_return_to, ["ilbookingobjectservicegui", "ilbookingreservationsgui"])) {
86 $this->return_to = $req_return_to;
87 }
88
89 // get current settings
91 new BookingManager\getObjectSettingsCommand($this->obj_id),
92 $this->use_book_repo
93 );
94 $this->current_settings = $handler->handle()->getSettings();
95
96 $this->initPool();
97
98 if (is_object($this->pool)) {
99 $this->help = new ilBookingHelpAdapter($this->pool, $DIC["ilHelp"]);
100 $DIC["ilHelp"]->setScreenIdComponent("book");
101 }
102 }
103
112 protected function initPool(): void
113 {
115
116 $ctrl->saveParameter($this, "pool_ref_id");
117 $pool_ref_id = $this->book_request->getPoolRefId();
118
119 $book_ref_ids = $this->use_book_repo->getUsedBookingPools(ilObject::_lookupObjId($this->main_host_ref_id), false);
120
121 $this->pools_selected = (count($book_ref_ids) > 0);
122
123 if (!in_array($pool_ref_id, $book_ref_ids)) {
124 if (count($book_ref_ids) > 0) {
125 $pool_ref_id = current($book_ref_ids);
126 } else {
127 $pool_ref_id = 0;
128 }
129 }
130 $this->current_pool_ref_id = $pool_ref_id;
131 if ($this->current_pool_ref_id > 0) {
132 $this->pool = new ilObjBookingPool($this->current_pool_ref_id);
133 $ctrl->setParameter($this, "pool_ref_id", $this->current_pool_ref_id);
134 }
135 }
136
141 public function executeCommand(): void
142 {
144
145 $next_class = $ctrl->getNextClass($this);
146 $cmd = $ctrl->getCmd("show");
147
148 switch ($next_class) {
149 case "ilpropertyformgui":
150 $form = $this->initSettingsForm();
151 $ctrl->setReturn($this, 'settings');
152 $ctrl->forwardCommand($form);
153 break;
154
155 case "ilbookingobjectservicegui":
156 $this->setSubTabs("book_obj");
157 $this->showPoolSelector("ilbookingobjectservicegui");
158 $book_ser_gui = new ilBookingObjectServiceGUI(
159 $this->ref_id,
160 $this->current_pool_ref_id,
161 $this->use_book_repo,
162 $this->seed,
163 $this->sseed,
164 $this->help
165 );
166 $ctrl->forwardCommand($book_ser_gui);
167 break;
168
169 case "ilbookingreservationsgui":
170 $this->showPoolSelector("ilbookingreservationsgui");
171 $this->setSubTabs("reservations");
172 $res_gui = new ilBookingReservationsGUI($this->pool, $this->help, $this->obj_id);
173 $this->ctrl->forwardCommand($res_gui);
174 break;
175
176
177 default:
178 if (in_array($cmd, array("show", "settings", "saveSettings", "selectPool"))) {
179 $this->$cmd();
180 }
181 }
182 }
183
184 protected function showPoolSelector(
185 string $return_to
186 ): void {
187 //
188 $options = [];
189 foreach ($this->use_book_repo->getUsedBookingPools(ilObject::_lookupObjectId($this->main_host_ref_id), false) as $ref_id) {
191 }
192
193 $this->ctrl->setParameter($this, "return_to", $return_to);
194 if (count($options) > 0) {
195 $si = new ilSelectInputGUI("", "pool_ref_id");
196 $si->setOptions($options);
197 $si->setValue($this->current_pool_ref_id);
198 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
199 $this->toolbar->addInputItem($si, false);
200 $this->toolbar->addFormButton($this->lng->txt("book_select_pool"), "selectPool");
201 }
202 }
203
204 protected function selectPool(): void
205 {
206 if ($this->return_to !== "") {
207 $this->ctrl->redirectByClass($this->return_to);
208 }
209 }
210
211 protected function setSubTabs(
212 string $active
213 ): void {
214 $tabs = $this->tabs;
215 $ctrl = $this->ctrl;
217
218 if ($this->pools_selected) {
219 $tabs->addSubTab(
220 "book_obj",
221 $lng->txt("book_booking_objects"),
222 $ctrl->getLinkTargetByClass("ilbookingobjectservicegui", "")
223 );
224 $tabs->addSubTab(
225 "reservations",
226 $lng->txt("book_log"),
227 $ctrl->getLinkTargetByClass("ilbookingreservationsgui", "")
228 );
229 }
230 if ($this->ref_id === $this->main_host_ref_id) {
231 $tabs->addSubTab(
232 "settings",
233 $lng->txt("settings"),
234 $ctrl->getLinkTarget($this, "settings")
235 );
236 }
237
238 $tabs->activateSubTab($active);
239 }
240
241 protected function show(): void
242 {
243 $ctrl = $this->ctrl;
244 if ($this->pools_selected) {
245 $ctrl->redirectByClass("ilbookingobjectservicegui");
246 } elseif ($this->ref_id === $this->main_host_ref_id) {
247 $ctrl->redirect($this, "settings");
248 }
249
250 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("book_no_pools_selected"));
251 }
252
253 //
254 // Settings
255 //
256
257 protected function settings(): void
258 {
259 $this->setSubTabs("settings");
260 $main_tpl = $this->main_tpl;
261 $form = $this->initSettingsForm();
262 $main_tpl->setContent($form->getHTML());
263 }
264
266 {
267 $ctrl = $this->ctrl;
269
270 $form = new ilPropertyFormGUI();
271
272 // booking tools
273 $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objs_book"), "booking_obj_ids", true);
274 $repo->getExplorerGUI()->setSelectableTypes(["book"]);
275 $repo->getExplorerGUI()->setTypeWhiteList(
276 ["book", "root", "cat", "grp", "fold", "crs"]
277 );
278 $form->addItem($repo);
279 $repo->setValue($this->current_settings->getUsedBookingObjectIds());
280
281 $form->addCommandButton("saveSettings", $lng->txt("save"));
282
283 $form->setTitle($lng->txt("book_pool_selection"));
284 $form->setFormAction($ctrl->getFormAction($this));
285
286 return $form;
287 }
288
289 public function saveSettings(): void
290 {
291 $ctrl = $this->ctrl;
293 $main_tpl = $this->main_tpl;
294
295 $form = $this->initSettingsForm();
296 if ($form->checkInput()) {
297 $b_ids = $form->getInput("booking_obj_ids");
298 $b_ids = is_array($b_ids)
299 ? array_map(static function ($i) {
300 return (int) $i;
301 }, $b_ids)
302 : [];
303
304 if (!$this->checkBookingPoolsForSchedules($b_ids)) {
305 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_all_pools_need_schedules"));
306 $form->setValuesByPost();
307 $main_tpl->setContent($form->getHTML());
308 return;
309 }
310
312 $this->obj_id,
313 $b_ids
314 ));
315
316 $repo = $this->use_book_repo;
317 $handler = new BookingManager\saveObjectSettingsCommandHandler($cmd, $repo);
318 $handler->handle();
319
320 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
321 $ctrl->redirect($this, "");
322 } else {
323 $form->setValuesByPost();
324 $main_tpl->setContent($form->getHTML());
325 }
326 }
327
332 protected function checkBookingPoolsForSchedules(array $ids): bool
333 {
334 foreach ($ids as $pool_ref_id) {
336 return false;
337 }
338 }
339 return true;
340 }
341}
This class is used for integration of the booking manager as a service into other repository objects,...
ilBookingHelpAdapter $help
checkBookingPoolsForSchedules(array $ids)
Check if all pools have schedules.
ilObjBookingServiceSettings $current_settings
ilObjUseBookDBRepository $use_book_repo
showPoolSelector(string $return_to)
ilGlobalTemplateInterface $main_tpl
BookingManager StandardGUIRequest $book_request
__construct(ilObjectGUI $parent_gui, int $main_host_ref_id=0)
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...
static hasExistingSchedules(int $a_pool_id)
Check if given pool has any defined schedules.
Class ilCtrl provides processing control methods.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
setReturn(object $a_gui_obj, string $a_cmd=null)
@inheritDoc
saveParameter(object $a_gui_obj, $a_parameter)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
forwardCommand(object $a_gui_object)
@inheritDoc
language handling
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 ilObjectGUI Basic methods of all Output classes.
static _lookupObjectId(int $ref_id)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
activateSubTab(string $a_id)
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lng