ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBookingGatewayGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
16{
20 protected $ctrl;
21
25 protected $lng;
26
30 protected $main_tpl;
31
35 protected $parent_gui;
36
40 protected $tabs;
41
45 protected $obj_id;
46
50 protected $ref_id;
51
56
61
65 protected $pool = null;
66
70 protected $toolbar;
71
75 protected $main_host_ref_id = 0;
76
81 protected $pools_selected = false;
82
87 {
88 global $DIC;
89
90 $this->ctrl = $DIC->ctrl();
91 $this->lng = $DIC->language();
92 $this->main_tpl = $DIC->ui()->mainTemplate();
93 $this->parent_gui = $parent_gui;
94 $this->tabs = $DIC->tabs();
95
96 $this->lng->loadLanguageModule("book");
97
98 // current parent context (e.g. session in course)
99 $this->obj_id = (int) $parent_gui->object->getId();
100 $this->ref_id = (int) $parent_gui->object->getRefId();
101
102 $this->main_host_ref_id = ($main_host_ref_id == 0)
103 ? $this->ref_id
105
106
107 $this->seed = ilUtil::stripSlashes($_GET['seed']);
108 $this->sseed = ilUtil::stripSlashes($_GET['sseed']);
109
110 $this->toolbar = $DIC->toolbar();
111
112 $this->use_book_repo = new ilObjUseBookDBRepository($DIC->database());
113
114 if (in_array($_REQUEST["return_to"], ["ilbookingobjectservicegui", "ilbookingreservationsgui"])) {
115 $this->return_to = $_REQUEST["return_to"];
116 }
117
118 // get current settings
120 new BookingManager\getObjectSettingsCommand($this->obj_id),
121 $this->use_book_repo
122 );
123 $this->current_settings = $handler->handle()->getSettings();
124
125 $this->initPool();
126
127 if (is_object($this->pool)) {
128 $this->help = new ilBookingHelpAdapter($this->pool, $DIC["ilHelp"]);
129 $DIC["ilHelp"]->setScreenIdComponent("book");
130 }
131 }
132
143 protected function initPool()
144 {
146
147 $ctrl->saveParameter($this, "pool_ref_id");
148 $pool_ref_id = ($_POST["pool_ref_id"] > 0)
149 ? (int) $_POST["pool_ref_id"]
150 : (int) $_GET["pool_ref_id"];
151
152 $book_ref_ids = $this->use_book_repo->getUsedBookingPools(ilObject::_lookupObjId($this->main_host_ref_id));
153
154 $this->pools_selected = (count($book_ref_ids) > 0);
155
156 if (!in_array($pool_ref_id, $book_ref_ids)) {
157 if (count($book_ref_ids) > 0) {
158 $pool_ref_id = current($book_ref_ids);
159 } else {
160 $pool_ref_id = 0;
161 }
162 }
163 $this->current_pool_ref_id = $pool_ref_id;
164 if ($this->current_pool_ref_id > 0) {
165 $this->pool = new ilObjBookingPool($this->current_pool_ref_id);
166 $ctrl->setParameter($this, "pool_ref_id", $this->current_pool_ref_id);
167 }
168 }
169
174 public function executeCommand()
175 {
177
178 $next_class = $ctrl->getNextClass($this);
179 $cmd = $ctrl->getCmd("show");
180
181 switch ($next_class) {
182 case "ilpropertyformgui":
183 $form = $this->initSettingsForm();
184 $ctrl->setReturn($this, 'settings');
185 $ctrl->forwardCommand($form);
186 break;
187
188 case "ilbookingobjectservicegui":
189 $this->setSubTabs("book_obj");
190 $this->showPoolSelector("ilbookingobjectservicegui");
191 $book_ser_gui = new ilBookingObjectServiceGUI(
192 $this->ref_id,
193 $this->current_pool_ref_id,
194 $this->use_book_repo,
195 $this->seed,
196 $this->sseed,
197 $this->help
198 );
199 $ctrl->forwardCommand($book_ser_gui);
200 break;
201
202 case "ilbookingreservationsgui":
203 $this->showPoolSelector("ilbookingreservationsgui");
204 $this->setSubTabs("reservations");
205 $res_gui = new ilBookingReservationsGUI($this->pool, $this->help, $this->obj_id);
206 $this->ctrl->forwardCommand($res_gui);
207 break;
208
209
210 default:
211 if (in_array($cmd, array("show", "settings", "saveSettings", "selectPool"))) {
212 $this->$cmd();
213 }
214 }
215 }
216
220 protected function showPoolSelector($return_to)
221 {
222 //
223 $options = [];
224 foreach ($this->use_book_repo->getUsedBookingPools(ilObject::_lookupObjectId($this->main_host_ref_id)) as $ref_id) {
226 }
227
228 $this->ctrl->setParameter($this, "return_to", $return_to);
229 if (count($options) > 0) {
230 $si = new ilSelectInputGUI("", "pool_ref_id");
231 $si->setOptions($options);
232 $si->setValue($this->current_pool_ref_id);
233 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
234 $this->toolbar->addInputItem($si, false);
235 $this->toolbar->addFormButton($this->lng->txt("book_select_pool"), "selectPool");
236 }
237 }
238
242 protected function selectPool()
243 {
244 if ($this->return_to != "") {
245 $this->ctrl->redirectByClass($this->return_to);
246 }
247 }
248
254 protected function setSubTabs($active)
255 {
259
260 if ($this->pools_selected) {
261 $tabs->addSubTab(
262 "book_obj",
263 $lng->txt("book_objects_list"),
264 $ctrl->getLinkTargetByClass("ilbookingobjectservicegui", "")
265 );
266 $tabs->addSubTab(
267 "reservations",
268 $lng->txt("book_log"),
269 $ctrl->getLinkTargetByClass("ilbookingreservationsgui", "")
270 );
271 }
272 if ($this->ref_id == $this->main_host_ref_id) {
273 $tabs->addSubTab(
274 "settings",
275 $lng->txt("settings"),
276 $ctrl->getLinkTarget($this, "settings")
277 );
278 }
279
280 $tabs->activateSubTab($active);
281 }
282
283
287 protected function show()
288 {
290 if ($this->pools_selected) {
291 $ctrl->redirectByClass("ilbookingobjectservicegui");
292 } elseif ($this->ref_id == $this->main_host_ref_id) {
293 $ctrl->redirect($this, "settings");
294 }
295
296 ilUtil::sendFailure($this->lng->txt("book_no_pools_selected"));
297 }
298
299 //
300 // Settings
301 //
302
306 protected function settings()
307 {
308 $this->setSubTabs("settings");
310 $form = $this->initSettingsForm();
311 $main_tpl->setContent($form->getHTML());
312 }
313
317 public function initSettingsForm()
318 {
321
322 $form = new ilPropertyFormGUI();
323
324 // booking tools
325 $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objs_book"), "booking_obj_ids", true);
326 $repo->getExplorerGUI()->setSelectableTypes(["book"]);
327 $repo->getExplorerGUI()->setTypeWhiteList(
328 ["book", "root", "cat", "grp", "fold", "crs"]
329 );
330 $form->addItem($repo);
331 $repo->setValue($this->current_settings->getUsedBookingObjectIds());
332
333 $form->addCommandButton("saveSettings", $lng->txt("save"));
334
335 $form->setTitle($lng->txt("book_pool_selection"));
336 $form->setFormAction($ctrl->getFormAction($this));
337
338 return $form;
339 }
340
344 public function saveSettings()
345 {
349
350 $form = $this->initSettingsForm();
351 if ($form->checkInput()) {
352 $b_ids = $form->getInput("booking_obj_ids");
353 $b_ids = is_array($b_ids)
354 ? array_map(function ($i) {
355 return (int) $i;
356 }, $b_ids)
357 : [];
358
359 if (!$this->checkBookingPoolsForSchedules($b_ids)) {
360 ilUtil::sendFailure($lng->txt("book_all_pools_need_schedules"));
361 $form->setValuesByPost();
362 $main_tpl->setContent($form->getHtml());
363 return;
364 }
365
367 $this->obj_id,
368 $b_ids
369 ));
370
371 $repo = $this->use_book_repo;
372 $handler = new BookingManager\saveObjectSettingsCommandHandler($cmd, $repo);
373 $handler->handle();
374
375 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
376 $ctrl->redirect($this, "");
377 } else {
378 $form->setValuesByPost();
379 $main_tpl->setContent($form->getHtml());
380 }
381 }
382
389 protected function checkBookingPoolsForSchedules($ids)
390 {
391 foreach ($ids as $pool_ref_id) {
393 return false;
394 }
395 }
396 return true;
397 }
398}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class is used for inegration of the booking manager as a service into other repository objects,...
__construct(ilObjectGUI $parent_gui, $main_host_ref_id=0)
Constructor.
saveSettings()
Save settings form.
checkBookingPoolsForSchedules($ids)
Check if all pools have schedules.
initSettingsForm()
Init settings form.
showPoolSelector($return_to)
Pool selector.
setSubTabs($active)
Set sub tabs.
Help adapter for booking manager.
static hasExistingSchedules($a_pool_id)
Check if given pool has any defined schedules.
Class ilObjBookingPool.
Value object for booking service settings of a repository object.
This repo stores infos on repository objects that are using booking managers as a service (resource m...
Class ilObjectGUI Basic methods of all Output classes.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
This class represents a property form user interface.
This class represents a selection list property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$i
Definition: metadata.php:24