ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
18  function __construct($a_parent_obj)
19  {
20  $this->ref_id = $a_parent_obj->ref_id;
21  }
22 
26  function executeCommand()
27  {
28  global $tpl, $ilTabs, $ilCtrl;
29 
30  $next_class = $ilCtrl->getNextClass($this);
31 
32  switch($next_class)
33  {
34  default:
35  $cmd = $ilCtrl->getCmd("render");
36  $this->$cmd();
37  break;
38  }
39  return true;
40  }
41 
47  function render()
48  {
49  global $tpl, $lng, $ilCtrl, $ilAccess;
50 
51  include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
52  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
53 
54  if ($ilAccess->checkAccess('write', '', $this->ref_id))
55  {
56  // if we have schedules but no objects - show info
57  if(sizeof($table->getData()))
58  {
59  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
60  if(!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id))))
61  {
62  ilUtil::sendInfo($lng->txt("book_type_warning"));
63  }
64  }
65 
66  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
67  $bar = new ilToolbarGUI;
68  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
69  $bar = $bar->getHTML();
70  }
71 
72  $tpl->setContent($bar.$table->getHTML());
73  }
74 
78  function create()
79  {
80  global $tpl, $ilCtrl, $ilTabs, $lng, $ilHelp;
81 
82  $ilTabs->clearTargets();
83  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
84  $ilHelp->setScreenIdComponent("book");
85  $ilHelp->setScreenId("schedules");
86  $ilHelp->setSubScreenId("create");
87 
88  $form = $this->initForm();
89  $tpl->setContent($form->getHTML());
90  }
91 
95  function edit()
96  {
97  global $tpl, $ilCtrl, $ilTabs, $lng, $ilHelp;
98 
99  $ilTabs->clearTargets();
100  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
101  $ilHelp->setScreenIdComponent("book");
102  $ilHelp->setScreenId("schedules");
103  $ilHelp->setSubScreenId("edit");
104 
105  $form = $this->initForm('edit', (int)$_GET['schedule_id']);
106  $tpl->setContent($form->getHTML());
107  }
108 
115  function initForm($a_mode = "create", $id = NULL)
116  {
117  global $lng, $ilCtrl;
118 
119  $lng->loadLanguageModule("dateplaner");
120 
121  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
122 
123  $form_gui = new ilPropertyFormGUI();
124 
125  $title = new ilTextInputGUI($lng->txt("title"), "title");
126  $title->setRequired(true);
127  $title->setSize(40);
128  $title->setMaxLength(120);
129  $form_gui->addItem($title);
130 
131  include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
132  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
133  $definition->setInfo($lng->txt("book_schedule_days_info"));
134  $definition->setRequired(true);
135  $form_gui->addItem($definition);
136 
137  $deadline_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
138  $deadline_opts->setRequired(true);
139  $form_gui->addItem($deadline_opts);
140 
141  $deadline_time = new ilRadioOption($lng->txt("book_deadline_hours"), "hours");
142  $deadline_opts->addOption($deadline_time);
143 
144  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
145  $deadline->setInfo($lng->txt("book_deadline_info"));
146  $deadline->setSuffix($lng->txt("book_hours"));
147  $deadline->setMinValue(1);
148  $deadline->setSize(3);
149  $deadline->setMaxLength(3);
150  $deadline_time->addSubItem($deadline);
151 
152  $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
153  $deadline_opts->addOption($deadline_start);
154 
155  $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
156  $deadline_opts->addOption($deadline_slot);
157 
158  if ($a_mode == "edit")
159  {
160  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
161  $schedule = new ilBookingSchedule($id);
162  }
163 
164  $av = new ilFormSectionHeaderGUI();
165  $av->setTitle($lng->txt("obj_activation_list_gui"));
166  $form_gui->addItem($av);
167 
168  // #18221
169  $lng->loadLanguageModule('rep');
170 
171  $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
172  $from->setShowTime(true);
173  $form_gui->addItem($from);
174 
175  $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
176  $to->setShowTime(true);
177  $form_gui->addItem($to);
178 
179  if ($a_mode == "edit")
180  {
181  $form_gui->setTitle($lng->txt("book_edit_schedule"));
182 
183  $item = new ilHiddenInputGUI('schedule_id');
184  $item->setValue($id);
185  $form_gui->addItem($item);
186 
187  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
188  $schedule = new ilBookingSchedule($id);
189  $title->setValue($schedule->getTitle());
190  $from->setDate($schedule->getAvailabilityFrom());
191  $to->setDate($schedule->getAvailabilityTo());
192 
193  if($schedule->getDeadline() == 0)
194  {
195  $deadline_opts->setValue("slot_start");
196  }
197  else if($schedule->getDeadline() > 0)
198  {
199  $deadline->setValue($schedule->getDeadline());
200  $deadline_opts->setValue("hours");
201  }
202  else
203  {
204  $deadline->setValue(0);
205  $deadline_opts->setValue("slot_end");
206  }
207 
208  /*
209  if($schedule->getRaster())
210  {
211  $type->setValue("flexible");
212  $raster->setValue($schedule->getRaster());
213  $rent_min->setValue($schedule->getMinRental());
214  $rent_max->setValue($schedule->getMaxRental());
215  $break->setValue($schedule->getAutoBreak());
216  }
217  else
218  {
219  $type->setValue("fix");
220  }
221  */
222 
223  $definition->setValue($schedule->getDefinitionBySlots());
224 
225  $form_gui->addCommandButton("update", $lng->txt("save"));
226  }
227  else
228  {
229  $form_gui->setTitle($lng->txt("book_add_schedule"));
230  $form_gui->addCommandButton("save", $lng->txt("save"));
231  $form_gui->addCommandButton("render", $lng->txt("cancel"));
232  }
233  $form_gui->setFormAction($ilCtrl->getFormAction($this));
234 
235  return $form_gui;
236  }
237 
241  function save()
242  {
243  global $tpl, $lng;
244 
245  $form = $this->initForm();
246  if($form->checkInput())
247  {
248  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
249  $obj = new ilBookingSchedule;
250  $this->formToObject($form, $obj);
251  $obj->save();
252 
253  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
254  $this->render();
255  }
256  else
257  {
258  $form->setValuesByPost();
259  $this->setDefinitionFromPost($form);
260  $tpl->setContent($form->getHTML());
261  }
262  }
263 
267  function update()
268  {
269  global $tpl, $lng;
270 
271  $form = $this->initForm('edit', (int)$_POST['schedule_id']);
272  if($form->checkInput())
273  {
274  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
275  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
276  $this->formToObject($form, $obj);
277  $obj->update();
278 
279  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
280  $this->render();
281  }
282  else
283  {
284  $form->setValuesByPost();
285  $this->setDefinitionFromPost($form);
286  $tpl->setContent($form->getHTML());
287  }
288  }
289 
295  protected function setDefinitionFromPost(ilPropertyFormGUI $form)
296  {
297  $days = $form->getInput("days");
298  if($days)
299  {
300  $days_group = $form->getItemByPostVar("days");
301  foreach($days_group->getOptions() as $option)
302  {
303  $days_fields[$option->getValue()] = $option;
304  }
305 
306  foreach($days as $day)
307  {
308  $slot = $form->getInput($day."_slot");
309  $subs = $days_fields[$day]->getSubItems();
310  if($slot[0])
311  {
312  $subs[0]->setValue($slot[0]);
313  }
314  if($slot[1])
315  {
316  $subs[1]->setValue($slot[1]);
317  }
318  }
319  }
320  }
321 
327  protected function formToObject($form, $schedule)
328  {
329  global $ilObjDataCache;
330 
331  $schedule->setTitle($form->getInput("title"));
332  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
333 
334  $from = $form->getItemByPostVar("from");
335  $schedule->setAvailabilityFrom($from->getDate());
336 
337  $to = $form->getItemByPostVar("to");
338  $schedule->setAvailabilityTo($to->getDate());
339 
340  switch($form->getInput("deadline_opts"))
341  {
342  case "slot_start":
343  $schedule->setDeadline(0);
344  break;
345 
346  case "hours":
347  $schedule->setDeadline($form->getInput("deadline"));
348  break;
349 
350  case "slot_end":
351  $schedule->setDeadline(-1);
352  break;
353  }
354 
355  /*
356  if($form->getInput("type") == "flexible")
357  {
358  $schedule->setRaster($form->getInput("raster"));
359  $schedule->setMinRental($form->getInput("rent_min"));
360  $schedule->setMaxRental($form->getInput("rent_max"));
361  $schedule->setAutoBreak($form->getInput("break"));
362  }
363  else
364  {
365  $schedule->setRaster(NULL);
366  $schedule->setMinRental(NULL);
367  $schedule->setMaxRental(NULL);
368  $schedule->setAutoBreak(NULL);
369  }
370  */
371 
372  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
373  }
374 
378  function confirmDelete()
379  {
380  global $ilCtrl, $lng, $tpl, $ilTabs, $ilHelp;
381 
382  $ilHelp->setSubScreenId("delete");
383 
384 
385  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
386  $conf = new ilConfirmationGUI();
387  $conf->setFormAction($ilCtrl->getFormAction($this));
388  $conf->setHeaderText($lng->txt('book_confirm_delete'));
389 
390  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
391  $type = new ilBookingSchedule((int)$_GET['schedule_id']);
392  $conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
393  $conf->setConfirm($lng->txt('delete'), 'delete');
394  $conf->setCancel($lng->txt('cancel'), 'render');
395 
396  $tpl->setContent($conf->getHTML());
397  }
398 
402  function delete()
403  {
404  global $ilCtrl, $lng;
405 
406  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
407  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
408  $obj->delete();
409 
410  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
411  $ilCtrl->redirect($this, 'render');
412  }
413 }
414 
415 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
getItemByPostVar($a_post_var)
Get Item by POST variable.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
This class represents a property form user interface.
__construct($a_parent_obj)
Constructor.
$_GET["client_id"]
This class represents a section header 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.
schedule for booking ressource
$cmd
Definition: sahs_server.php:35
This class represents a text property in a property form.
List booking schedules (for booking pool)
This class represents a date/time property in a property form.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
This class represents a property in a property form.
This class represents a number property in a property form.
static _lookupObjId($a_id)
This class represents a text property in a property form.
initForm($a_mode="create", $id=NULL)
Build property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static getPostData($a_post_var, $a_remove_invalid=true)
create()
Render creation form.
formToObject($form, $schedule)
Convert incoming form data to schedule object.
Class ilBookingScheduleGUI.
global $lng
Definition: privfeed.php:17
render()
Render list of booking schedules.
setDefinitionFromPost(ilPropertyFormGUI $form)
Reload definition values from post data.
$_POST["username"]
setRequired($a_required)
Set Required.
setShowTime($a_showtime)
Set Show Time Information.
Confirmation screen class.