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