ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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;
81 
82  $ilTabs->clearTargets();
83  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
84 
85  $form = $this->initForm();
86  $tpl->setContent($form->getHTML());
87  }
88 
92  function edit()
93  {
94  global $tpl, $ilCtrl, $ilTabs, $lng;
95 
96  $ilTabs->clearTargets();
97  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
98 
99  $form = $this->initForm('edit', (int)$_GET['schedule_id']);
100  $tpl->setContent($form->getHTML());
101  }
102 
109  function initForm($a_mode = "create", $id = NULL)
110  {
111  global $lng, $ilCtrl;
112 
113  $lng->loadLanguageModule("dateplaner");
114 
115  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
116 
117  $form_gui = new ilPropertyFormGUI();
118 
119  $title = new ilTextInputGUI($lng->txt("title"), "title");
120  $title->setRequired(true);
121  $title->setSize(40);
122  $title->setMaxLength(120);
123  $form_gui->addItem($title);
124 
125  /*
126  $type = new ilRadioGroupInputGUI($lng->txt("book_schedule_type"), "type");
127  $type->setRequired(true);
128  $form_gui->addItem($type);
129  $fix = new ilRadioOption($lng->txt("book_schedule_type_fix"), "fix");
130  $fix->setInfo($lng->txt("book_schedule_type_fix_info"));
131  $type->addOption($fix);
132  $flex = new ilRadioOption($lng->txt("book_schedule_type_flexible"), "flexible");
133  $flex->setInfo($lng->txt("book_schedule_type_flexible_info"));
134  $type->addOption($flex);
135 
136  $raster = new ilNumberInputGUI($lng->txt("book_schedule_raster"), "raster");
137  $raster->setRequired(true);
138  $raster->setInfo($lng->txt("book_schedule_raster_info"));
139  $raster->setMinValue(1);
140  $raster->setSize(3);
141  $raster->setMaxLength(3);
142  $raster->setSuffix($lng->txt("book_minutes"));
143  $flex->addSubItem($raster);
144 
145  $rent_min = new ilNumberInputGUI($lng->txt("book_schedule_rent_min"), "rent_min");
146  $rent_min->setInfo($lng->txt("book_schedule_rent_info"));
147  $rent_min->setMinValue(1);
148  $rent_min->setSize(3);
149  $rent_min->setMaxLength(3);
150  $flex->addSubItem($rent_min);
151 
152  $rent_max = new ilNumberInputGUI($lng->txt("book_schedule_rent_max"), "rent_max");
153  $rent_max->setInfo($lng->txt("book_schedule_rent_info"));
154  $rent_max->setMinValue(1);
155  $rent_max->setSize(3);
156  $rent_max->setMaxLength(3);
157  $flex->addSubItem($rent_max);
158 
159  $break = new ilNumberInputGUI($lng->txt("book_schedule_break"), "break");
160  $break->setInfo($lng->txt("book_schedule_break_info"));
161  $break->setMinValue(1);
162  $break->setSize(3);
163  $break->setMaxLength(3);
164  $flex->addSubItem($break);
165  */
166 
167  include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
168  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
169  $definition->setInfo($lng->txt("book_schedule_days_info"));
170  $definition->setRequired(true);
171  $form_gui->addItem($definition);
172 
173  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
174  $deadline->setInfo($lng->txt("book_deadline_info"));
175  $deadline->setSuffix($lng->txt("book_hours"));
176  $deadline->setMinValue(0);
177  $deadline->setSize(3);
178  $deadline->setMaxLength(3);
179  $form_gui->addItem($deadline);
180 
181  if ($a_mode == "edit")
182  {
183  $form_gui->setTitle($lng->txt("book_edit_schedule"));
184 
185  $item = new ilHiddenInputGUI('schedule_id');
186  $item->setValue($id);
187  $form_gui->addItem($item);
188 
189  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
190  $schedule = new ilBookingSchedule($id);
191  $title->setValue($schedule->getTitle());
192  $deadline->setValue($schedule->getDeadline());
193 
194  /*
195  if($schedule->getRaster())
196  {
197  $type->setValue("flexible");
198  $raster->setValue($schedule->getRaster());
199  $rent_min->setValue($schedule->getMinRental());
200  $rent_max->setValue($schedule->getMaxRental());
201  $break->setValue($schedule->getAutoBreak());
202  }
203  else
204  {
205  $type->setValue("fix");
206  }
207  */
208 
209  $definition->setValue($schedule->getDefinitionBySlots());
210 
211  $form_gui->addCommandButton("update", $lng->txt("save"));
212  }
213  else
214  {
215  $form_gui->setTitle($lng->txt("book_add_schedule"));
216  $form_gui->addCommandButton("save", $lng->txt("save"));
217  $form_gui->addCommandButton("render", $lng->txt("cancel"));
218  }
219  $form_gui->setFormAction($ilCtrl->getFormAction($this));
220 
221  return $form_gui;
222  }
223 
227  function save()
228  {
229  global $tpl, $lng;
230 
231  $form = $this->initForm();
232  if($form->checkInput())
233  {
234  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
235  $obj = new ilBookingSchedule;
236  $this->formToObject($form, $obj);
237  $obj->save();
238 
239  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
240  $this->render();
241  }
242  else
243  {
244  $form->setValuesByPost();
245  $this->setDefinitionFromPost($form);
246  $tpl->setContent($form->getHTML());
247  }
248  }
249 
253  function update()
254  {
255  global $tpl, $lng;
256 
257  $form = $this->initForm('edit', (int)$_POST['schedule_id']);
258  if($form->checkInput())
259  {
260  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
261  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
262  $this->formToObject($form, $obj);
263  $obj->update();
264 
265  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
266  $this->render();
267  }
268  else
269  {
270  $form->setValuesByPost();
271  $this->setDefinitionFromPost($form);
272  $tpl->setContent($form->getHTML());
273  }
274  }
275 
281  protected function setDefinitionFromPost(ilPropertyFormGUI $form)
282  {
283  $days = $form->getInput("days");
284  if($days)
285  {
286  $days_group = $form->getItemByPostVar("days");
287  foreach($days_group->getOptions() as $option)
288  {
289  $days_fields[$option->getValue()] = $option;
290  }
291 
292  foreach($days as $day)
293  {
294  $slot = $form->getInput($day."_slot");
295  $subs = $days_fields[$day]->getSubItems();
296  if($slot[0])
297  {
298  $subs[0]->setValue($slot[0]);
299  }
300  if($slot[1])
301  {
302  $subs[1]->setValue($slot[1]);
303  }
304  }
305  }
306  }
307 
313  protected function formToObject($form, $schedule)
314  {
315  global $ilObjDataCache;
316 
317  $schedule->setTitle($form->getInput("title"));
318  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
319  $schedule->setDeadline($form->getInput("deadline"));
320 
321  /*
322  if($form->getInput("type") == "flexible")
323  {
324  $schedule->setRaster($form->getInput("raster"));
325  $schedule->setMinRental($form->getInput("rent_min"));
326  $schedule->setMaxRental($form->getInput("rent_max"));
327  $schedule->setAutoBreak($form->getInput("break"));
328  }
329  else
330  {
331  $schedule->setRaster(NULL);
332  $schedule->setMinRental(NULL);
333  $schedule->setMaxRental(NULL);
334  $schedule->setAutoBreak(NULL);
335  }
336  */
337 
338  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
339  }
340 
344  function confirmDelete()
345  {
346  global $ilCtrl, $lng, $tpl, $ilTabs;
347 
348  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
349  $conf = new ilConfirmationGUI();
350  $conf->setFormAction($ilCtrl->getFormAction($this));
351  $conf->setHeaderText($lng->txt('book_confirm_delete'));
352 
353  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
354  $type = new ilBookingSchedule((int)$_GET['schedule_id']);
355  $conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
356  $conf->setConfirm($lng->txt('delete'), 'delete');
357  $conf->setCancel($lng->txt('cancel'), 'render');
358 
359  $tpl->setContent($conf->getHTML());
360  }
361 
365  function delete()
366  {
367  global $ilCtrl, $lng;
368 
369  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
370  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
371  $obj->delete();
372 
373  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
374  $ilCtrl->redirect($this, 'render');
375  }
376 }
377 
378 ?>