ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
52 protected $schedule_id;
53
58 public function __construct($a_parent_obj)
59 {
60 global $DIC;
61
62 $this->tpl = $DIC["tpl"];
63 $this->tabs = $DIC->tabs();
64 $this->ctrl = $DIC->ctrl();
65 $this->lng = $DIC->language();
66 $this->access = $DIC->access();
67 $this->help = $DIC["ilHelp"];
68 $this->obj_data_cache = $DIC["ilObjDataCache"];
69 $this->ref_id = $a_parent_obj->ref_id;
70 $this->schedule_id = (int) $_REQUEST['schedule_id'];
71 }
72
76 public function executeCommand()
77 {
79 $ilTabs = $this->tabs;
81
82 $next_class = $ilCtrl->getNextClass($this);
83
84 switch ($next_class) {
85 default:
86 $cmd = $ilCtrl->getCmd("render");
87 $this->$cmd();
88 break;
89 }
90 return true;
91 }
92
98 public function render()
99 {
103 $ilAccess = $this->access;
104
105 $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
106
107 if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
108 // if we have schedules but no objects - show info
109 if (sizeof($table->getData())) {
110 if (!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
111 ilUtil::sendInfo($lng->txt("book_type_warning"));
112 }
113 }
114
115 $bar = new ilToolbarGUI;
116 $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
117 $bar = $bar->getHTML();
118 }
119
120 $tpl->setContent($bar . $table->getHTML());
121 }
122
126 public function create()
127 {
130 $ilTabs = $this->tabs;
132 $ilHelp = $this->help;
133
134 $ilTabs->clearTargets();
135 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
136 $ilHelp->setScreenIdComponent("book");
137 $ilHelp->setScreenId("schedules");
138 $ilHelp->setSubScreenId("create");
139
140 $form = $this->initForm();
141 $tpl->setContent($form->getHTML());
142 }
143
147 public function edit()
148 {
151 $ilTabs = $this->tabs;
153 $ilHelp = $this->help;
154
155 $ilTabs->clearTargets();
156 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
157 $ilHelp->setScreenIdComponent("book");
158 $ilHelp->setScreenId("schedules");
159 $ilHelp->setSubScreenId("edit");
160
161 $form = $this->initForm('edit', $this->schedule_id);
162 $tpl->setContent($form->getHTML());
163 }
164
171 public function initForm($a_mode = "create", $id = null)
172 {
175
176 $lng->loadLanguageModule("dateplaner");
177
178 $form_gui = new ilPropertyFormGUI();
179
180 $title = new ilTextInputGUI($lng->txt("title"), "title");
181 $title->setRequired(true);
182 $title->setSize(40);
183 $title->setMaxLength(120);
184 $form_gui->addItem($title);
185
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 $schedule = new ilBookingSchedule($id);
214 }
215
216 $av = new ilFormSectionHeaderGUI();
217 $av->setTitle($lng->txt("obj_activation_list_gui"));
218 $form_gui->addItem($av);
219
220 // #18221
221 $lng->loadLanguageModule('rep');
222
223 $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
224 $from->setShowTime(true);
225 $form_gui->addItem($from);
226
227 $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
228 $to->setShowTime(true);
229 $form_gui->addItem($to);
230
231 if ($a_mode == "edit") {
232 $form_gui->setTitle($lng->txt("book_edit_schedule"));
233
234 $item = new ilHiddenInputGUI('schedule_id');
235 $item->setValue($id);
236 $form_gui->addItem($item);
237
238 $schedule = new ilBookingSchedule($id);
239 $title->setValue($schedule->getTitle());
240 $from->setDate($schedule->getAvailabilityFrom());
241 $to->setDate($schedule->getAvailabilityTo());
242
243 if ($schedule->getDeadline() == 0) {
244 $deadline_opts->setValue("slot_start");
245 } elseif ($schedule->getDeadline() > 0) {
246 $deadline->setValue($schedule->getDeadline());
247 $deadline_opts->setValue("hours");
248 } else {
249 $deadline->setValue(0);
250 $deadline_opts->setValue("slot_end");
251 }
252
253 /*
254 if($schedule->getRaster())
255 {
256 $type->setValue("flexible");
257 $raster->setValue($schedule->getRaster());
258 $rent_min->setValue($schedule->getMinRental());
259 $rent_max->setValue($schedule->getMaxRental());
260 $break->setValue($schedule->getAutoBreak());
261 }
262 else
263 {
264 $type->setValue("fix");
265 }
266 */
267
268 $definition->setValue($schedule->getDefinitionBySlots());
269
270 $form_gui->addCommandButton("update", $lng->txt("save"));
271 } else {
272 $form_gui->setTitle($lng->txt("book_add_schedule"));
273 $form_gui->addCommandButton("save", $lng->txt("save"));
274 $form_gui->addCommandButton("render", $lng->txt("cancel"));
275 }
276 $form_gui->setFormAction($ilCtrl->getFormAction($this));
277
278 return $form_gui;
279 }
280
284 public function save()
285 {
288
289 $form = $this->initForm();
290 if ($form->checkInput()) {
291 $obj = new ilBookingSchedule;
292 $this->formToObject($form, $obj);
293 $obj->save();
294
295 ilUtil::sendSuccess($lng->txt("book_schedule_added"));
296 $this->render();
297 } else {
298 $form->setValuesByPost();
299 $this->setDefinitionFromPost($form);
300 $tpl->setContent($form->getHTML());
301 }
302 }
303
307 public function update()
308 {
311
312 $form = $this->initForm('edit', $this->schedule_id);
313 if ($form->checkInput()) {
314 $obj = new ilBookingSchedule($this->schedule_id);
315 $this->formToObject($form, $obj);
316 $obj->update();
317
318 ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
319 $this->render();
320 } else {
321 $form->setValuesByPost();
322 $this->setDefinitionFromPost($form);
323 $tpl->setContent($form->getHTML());
324 }
325 }
326
332 protected function setDefinitionFromPost(ilPropertyFormGUI $form)
333 {
334 $days = $form->getInput("days");
335 if ($days) {
336 $days_group = $form->getItemByPostVar("days");
337 foreach ($days_group->getOptions() as $option) {
338 $days_fields[$option->getValue()] = $option;
339 }
340
341 foreach ($days as $day) {
342 $slot = $form->getInput($day . "_slot");
343 $subs = $days_fields[$day]->getSubItems();
344 if ($slot[0]) {
345 $subs[0]->setValue($slot[0]);
346 }
347 if ($slot[1]) {
348 $subs[1]->setValue($slot[1]);
349 }
350 }
351 }
352 }
353
359 protected function formToObject($form, $schedule)
360 {
361 $ilObjDataCache = $this->obj_data_cache;
362
363 $schedule->setTitle($form->getInput("title"));
364 $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
365
366 $from = $form->getItemByPostVar("from");
367 $schedule->setAvailabilityFrom($from->getDate());
368
369 $to = $form->getItemByPostVar("to");
370 $schedule->setAvailabilityTo($to->getDate());
371
372 switch ($form->getInput("deadline_opts")) {
373 case "slot_start":
374 $schedule->setDeadline(0);
375 break;
376
377 case "hours":
378 $schedule->setDeadline($form->getInput("deadline"));
379 break;
380
381 case "slot_end":
382 $schedule->setDeadline(-1);
383 break;
384 }
385
386 /*
387 if($form->getInput("type") == "flexible")
388 {
389 $schedule->setRaster($form->getInput("raster"));
390 $schedule->setMinRental($form->getInput("rent_min"));
391 $schedule->setMaxRental($form->getInput("rent_max"));
392 $schedule->setAutoBreak($form->getInput("break"));
393 }
394 else
395 {
396 $schedule->setRaster(NULL);
397 $schedule->setMinRental(NULL);
398 $schedule->setMaxRental(NULL);
399 $schedule->setAutoBreak(NULL);
400 }
401 */
402
403 $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
404 }
405
409 public function confirmDelete()
410 {
414 $ilTabs = $this->tabs;
415 $ilHelp = $this->help;
416
417 $ilHelp->setSubScreenId("delete");
418
419
420 $conf = new ilConfirmationGUI();
421 $conf->setFormAction($ilCtrl->getFormAction($this));
422 $conf->setHeaderText($lng->txt('book_confirm_delete'));
423
424 $type = new ilBookingSchedule($this->schedule_id);
425 $conf->addItem('schedule_id', $this->schedule_id, $type->getTitle());
426 $conf->setConfirm($lng->txt('delete'), 'delete');
427 $conf->setCancel($lng->txt('cancel'), 'render');
428
429 $tpl->setContent($conf->getHTML());
430 }
431
435 public function delete()
436 {
439
440 $obj = new ilBookingSchedule($this->schedule_id);
441 $obj->delete();
442
443 ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
444 $ilCtrl->redirect($this, 'render');
445 }
446}
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.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
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.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
help()
Definition: help.php:2
global $ilCtrl
Definition: ilias.php:18
$type
$DIC
Definition: xapitoken.php:46