ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBookingScheduleGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $tpl;
18
22 protected $tabs;
23
27 protected $ctrl;
28
32 protected $lng;
33
37 protected $access;
38
42 protected $help;
43
47 protected $obj_data_cache;
48
53 public function __construct($a_parent_obj)
54 {
55 global $DIC;
56
57 $this->tpl = $DIC["tpl"];
58 $this->tabs = $DIC->tabs();
59 $this->ctrl = $DIC->ctrl();
60 $this->lng = $DIC->language();
61 $this->access = $DIC->access();
62 $this->help = $DIC["ilHelp"];
63 $this->obj_data_cache = $DIC["ilObjDataCache"];
64 $this->ref_id = $a_parent_obj->ref_id;
65 }
66
70 public function executeCommand()
71 {
73 $ilTabs = $this->tabs;
75
76 $next_class = $ilCtrl->getNextClass($this);
77
78 switch ($next_class) {
79 default:
80 $cmd = $ilCtrl->getCmd("render");
81 $this->$cmd();
82 break;
83 }
84 return true;
85 }
86
92 public function render()
93 {
97 $ilAccess = $this->access;
98
99 include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
100 $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
101
102 if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
103 // if we have schedules but no objects - show info
104 if (sizeof($table->getData())) {
105 include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
106 if (!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
107 ilUtil::sendInfo($lng->txt("book_type_warning"));
108 }
109 }
110
111 include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
112 $bar = new ilToolbarGUI;
113 $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
114 $bar = $bar->getHTML();
115 }
116
117 $tpl->setContent($bar . $table->getHTML());
118 }
119
123 public function create()
124 {
127 $ilTabs = $this->tabs;
129 $ilHelp = $this->help;
130
131 $ilTabs->clearTargets();
132 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
133 $ilHelp->setScreenIdComponent("book");
134 $ilHelp->setScreenId("schedules");
135 $ilHelp->setSubScreenId("create");
136
137 $form = $this->initForm();
138 $tpl->setContent($form->getHTML());
139 }
140
144 public function edit()
145 {
148 $ilTabs = $this->tabs;
150 $ilHelp = $this->help;
151
152 $ilTabs->clearTargets();
153 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
154 $ilHelp->setScreenIdComponent("book");
155 $ilHelp->setScreenId("schedules");
156 $ilHelp->setSubScreenId("edit");
157
158 $form = $this->initForm('edit', (int) $_GET['schedule_id']);
159 $tpl->setContent($form->getHTML());
160 }
161
168 public function initForm($a_mode = "create", $id = null)
169 {
172
173 $lng->loadLanguageModule("dateplaner");
174
175 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
176
177 $form_gui = new ilPropertyFormGUI();
178
179 $title = new ilTextInputGUI($lng->txt("title"), "title");
180 $title->setRequired(true);
181 $title->setSize(40);
182 $title->setMaxLength(120);
183 $form_gui->addItem($title);
184
185 include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
186 $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
187 $definition->setInfo($lng->txt("book_schedule_days_info"));
188 $definition->setRequired(true);
189 $form_gui->addItem($definition);
190
191 $deadline_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
192 $deadline_opts->setRequired(true);
193 $form_gui->addItem($deadline_opts);
194
195 $deadline_time = new ilRadioOption($lng->txt("book_deadline_hours"), "hours");
196 $deadline_opts->addOption($deadline_time);
197
198 $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
199 $deadline->setInfo($lng->txt("book_deadline_info"));
200 $deadline->setSuffix($lng->txt("book_hours"));
201 $deadline->setMinValue(1);
202 $deadline->setSize(3);
203 $deadline->setMaxLength(3);
204 $deadline_time->addSubItem($deadline);
205
206 $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
207 $deadline_opts->addOption($deadline_start);
208
209 $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
210 $deadline_opts->addOption($deadline_slot);
211
212 if ($a_mode == "edit") {
213 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
214 $schedule = new ilBookingSchedule($id);
215 }
216
217 $av = new ilFormSectionHeaderGUI();
218 $av->setTitle($lng->txt("obj_activation_list_gui"));
219 $form_gui->addItem($av);
220
221 // #18221
222 $lng->loadLanguageModule('rep');
223
224 $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
225 $from->setShowTime(true);
226 $form_gui->addItem($from);
227
228 $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
229 $to->setShowTime(true);
230 $form_gui->addItem($to);
231
232 if ($a_mode == "edit") {
233 $form_gui->setTitle($lng->txt("book_edit_schedule"));
234
235 $item = new ilHiddenInputGUI('schedule_id');
236 $item->setValue($id);
237 $form_gui->addItem($item);
238
239 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
240 $schedule = new ilBookingSchedule($id);
241 $title->setValue($schedule->getTitle());
242 $from->setDate($schedule->getAvailabilityFrom());
243 $to->setDate($schedule->getAvailabilityTo());
244
245 if ($schedule->getDeadline() == 0) {
246 $deadline_opts->setValue("slot_start");
247 } elseif ($schedule->getDeadline() > 0) {
248 $deadline->setValue($schedule->getDeadline());
249 $deadline_opts->setValue("hours");
250 } else {
251 $deadline->setValue(0);
252 $deadline_opts->setValue("slot_end");
253 }
254
255 /*
256 if($schedule->getRaster())
257 {
258 $type->setValue("flexible");
259 $raster->setValue($schedule->getRaster());
260 $rent_min->setValue($schedule->getMinRental());
261 $rent_max->setValue($schedule->getMaxRental());
262 $break->setValue($schedule->getAutoBreak());
263 }
264 else
265 {
266 $type->setValue("fix");
267 }
268 */
269
270 $definition->setValue($schedule->getDefinitionBySlots());
271
272 $form_gui->addCommandButton("update", $lng->txt("save"));
273 } else {
274 $form_gui->setTitle($lng->txt("book_add_schedule"));
275 $form_gui->addCommandButton("save", $lng->txt("save"));
276 $form_gui->addCommandButton("render", $lng->txt("cancel"));
277 }
278 $form_gui->setFormAction($ilCtrl->getFormAction($this));
279
280 return $form_gui;
281 }
282
286 public function save()
287 {
290
291 $form = $this->initForm();
292 if ($form->checkInput()) {
293 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
294 $obj = new ilBookingSchedule;
295 $this->formToObject($form, $obj);
296 $obj->save();
297
298 ilUtil::sendSuccess($lng->txt("book_schedule_added"));
299 $this->render();
300 } else {
301 $form->setValuesByPost();
303 $tpl->setContent($form->getHTML());
304 }
305 }
306
310 public function update()
311 {
314
315 $form = $this->initForm('edit', (int) $_POST['schedule_id']);
316 if ($form->checkInput()) {
317 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
318 $obj = new ilBookingSchedule((int) $_POST['schedule_id']);
319 $this->formToObject($form, $obj);
320 $obj->update();
321
322 ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
323 $this->render();
324 } else {
325 $form->setValuesByPost();
327 $tpl->setContent($form->getHTML());
328 }
329 }
330
337 {
338 $days = $form->getInput("days");
339 if ($days) {
340 $days_group = $form->getItemByPostVar("days");
341 foreach ($days_group->getOptions() as $option) {
342 $days_fields[$option->getValue()] = $option;
343 }
344
345 foreach ($days as $day) {
346 $slot = $form->getInput($day . "_slot");
347 $subs = $days_fields[$day]->getSubItems();
348 if ($slot[0]) {
349 $subs[0]->setValue($slot[0]);
350 }
351 if ($slot[1]) {
352 $subs[1]->setValue($slot[1]);
353 }
354 }
355 }
356 }
357
363 protected function formToObject($form, $schedule)
364 {
365 $ilObjDataCache = $this->obj_data_cache;
366
367 $schedule->setTitle($form->getInput("title"));
368 $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
369
370 $from = $form->getItemByPostVar("from");
371 $schedule->setAvailabilityFrom($from->getDate());
372
373 $to = $form->getItemByPostVar("to");
374 $schedule->setAvailabilityTo($to->getDate());
375
376 switch ($form->getInput("deadline_opts")) {
377 case "slot_start":
378 $schedule->setDeadline(0);
379 break;
380
381 case "hours":
382 $schedule->setDeadline($form->getInput("deadline"));
383 break;
384
385 case "slot_end":
386 $schedule->setDeadline(-1);
387 break;
388 }
389
390 /*
391 if($form->getInput("type") == "flexible")
392 {
393 $schedule->setRaster($form->getInput("raster"));
394 $schedule->setMinRental($form->getInput("rent_min"));
395 $schedule->setMaxRental($form->getInput("rent_max"));
396 $schedule->setAutoBreak($form->getInput("break"));
397 }
398 else
399 {
400 $schedule->setRaster(NULL);
401 $schedule->setMinRental(NULL);
402 $schedule->setMaxRental(NULL);
403 $schedule->setAutoBreak(NULL);
404 }
405 */
406
407 $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
408 }
409
413 public function confirmDelete()
414 {
418 $ilTabs = $this->tabs;
419 $ilHelp = $this->help;
420
421 $ilHelp->setSubScreenId("delete");
422
423
424 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
425 $conf = new ilConfirmationGUI();
426 $conf->setFormAction($ilCtrl->getFormAction($this));
427 $conf->setHeaderText($lng->txt('book_confirm_delete'));
428
429 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
430 $type = new ilBookingSchedule((int) $_GET['schedule_id']);
431 $conf->addItem('schedule_id', (int) $_GET['schedule_id'], $type->getTitle());
432 $conf->setConfirm($lng->txt('delete'), 'delete');
433 $conf->setCancel($lng->txt('cancel'), 'render');
434
435 $tpl->setContent($conf->getHTML());
436 }
437
441 public function delete()
442 {
445
446 include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
447 $obj = new ilBookingSchedule((int) $_POST['schedule_id']);
448 $obj->delete();
449
450 ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
451 $ilCtrl->redirect($this, 'render');
452 }
453}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
Class ilBookingScheduleGUI.
initForm($a_mode="create", $id=null)
Build property form.
formToObject($form, $schedule)
Convert incoming form data to schedule object.
render()
Render list of booking schedules.
create()
Render creation form.
__construct($a_parent_obj)
Constructor.
setDefinitionFromPost(ilPropertyFormGUI $form)
Reload definition values from post data.
schedule for booking ressource
List booking schedules (for booking pool)
Confirmation screen class.
This class represents a date/time property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
static _lookupObjId($a_id)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text property in a property form.
static getPostData($a_post_var, $a_remove_invalid=true)
This class represents a text property in a property form.
addButton( $a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
$type
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$from