ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingGatewayGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
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
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($this->pool, $this->help, $this->obj_id);
178 $this->ctrl->forwardCommand($res_gui);
179 break;
180
181
182 default:
183 if (in_array($cmd, array("show", "settings", "saveSettings", "selectPool"))) {
184 $this->$cmd();
185 }
186 }
187 }
188
189 protected function showPoolSelector(
190 string $return_to
191 ): void {
192 //
193 $options = [];
194 foreach ($this->use_book_repo->getUsedBookingPools(ilObject::_lookupObjectId($this->main_host_ref_id), false) as $ref_id) {
196 }
197
198 $this->ctrl->setParameter($this, "return_to", $return_to);
199 if (count($options) > 0) {
200 $si = new ilSelectInputGUI("", "pool_ref_id");
201 $si->setOptions($options);
202 $si->setValue($this->current_pool_ref_id);
203 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
204 $this->toolbar->addInputItem($si, false);
205 $this->toolbar->addFormButton($this->lng->txt("book_select_pool"), "selectPool");
206 }
207 }
208
209 protected function selectPool(): void
210 {
211 if ($this->return_to !== "") {
212 $this->ctrl->redirectByClass($this->return_to);
213 }
214 }
215
216 protected function setSubTabs(
217 string $active
218 ): void {
219 $tabs = $this->tabs;
220 $ctrl = $this->ctrl;
222
223 if ($this->pools_selected) {
224 $tabs->addSubTab(
225 "book_obj",
226 $lng->txt("book_booking_objects"),
227 $ctrl->getLinkTargetByClass("ilbookingobjectservicegui", "")
228 );
229 $tabs->addSubTab(
230 "reservations",
231 $lng->txt("book_log"),
232 $ctrl->getLinkTargetByClass("ilbookingreservationsgui", "")
233 );
234 }
235 if ($this->ref_id === $this->main_host_ref_id) {
236 $tabs->addSubTab(
237 "settings",
238 $lng->txt("settings"),
239 $ctrl->getLinkTarget($this, "settings")
240 );
241 }
242
243 $tabs->activateSubTab($active);
244 }
245
246 protected function show(): void
247 {
248 $ctrl = $this->ctrl;
249 if ($this->pools_selected) {
250 $ctrl->redirectByClass("ilbookingobjectservicegui");
251 } elseif ($this->ref_id === $this->main_host_ref_id) {
252 $ctrl->redirect($this, "settings");
253 }
254
255 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("book_no_pools_selected"));
256 }
257
258 //
259 // Settings
260 //
261
262 protected function settings(): void
263 {
264 $this->setSubTabs("settings");
265 $main_tpl = $this->main_tpl;
266 $form = $this->initSettingsForm();
267 $main_tpl->setContent($form->getHTML());
268 }
269
271 {
272 $ctrl = $this->ctrl;
274
275 $form = new ilPropertyFormGUI();
276
277 // booking tools
278 $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objs_book"), "booking_obj_ids", true);
279 $repo->getExplorerGUI()->setSelectableTypes(["book"]);
280 $repo->getExplorerGUI()->setTypeWhiteList(
281 ["book", "root", "cat", "grp", "fold", "crs"]
282 );
283 $form->addItem($repo);
284 $repo->setValue($this->current_settings->getUsedBookingObjectIds());
285
286 $form->addCommandButton("saveSettings", $lng->txt("save"));
287
288 $form->setTitle($lng->txt("book_pool_selection"));
289 $form->setFormAction($ctrl->getFormAction($this));
290
291 return $form;
292 }
293
294 public function saveSettings(): void
295 {
296 $ctrl = $this->ctrl;
298 $main_tpl = $this->main_tpl;
299
300 $form = $this->initSettingsForm();
301 if ($form->checkInput()) {
302 $b_ids = $form->getInput("booking_obj_ids");
303 $b_ids = is_array($b_ids)
304 ? array_map(static function ($i) {
305 return (int) $i;
306 }, $b_ids)
307 : [];
308
309 if (!$this->checkBookingPoolsForSchedules($b_ids)) {
310 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_all_pools_need_schedules"));
311 $form->setValuesByPost();
312 $main_tpl->setContent($form->getHTML());
313 return;
314 }
315
317 $this->obj_id,
318 $b_ids
319 ));
320
321 $repo = $this->use_book_repo;
323 $handler->handle();
324
325 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
326 $ctrl->redirect($this, "");
327 } else {
328 $form->setValuesByPost();
329 $main_tpl->setContent($form->getHTML());
330 }
331 }
332
337 protected function checkBookingPoolsForSchedules(array $ids): bool
338 {
339 foreach ($ids as $pool_ref_id) {
340 $schedule_manager = $this->domain->schedules(ilObject::_lookupObjectId($pool_ref_id));
341 if (!$schedule_manager->hasSchedules()) {
342 return false;
343 }
344 }
345 return true;
346 }
347}
Author: Alexander Killing killing@leifos.de
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...
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 _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:29
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26