ILIAS  Release_4_2_x_branch Revision 61807
 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  $this->slots_no = $a_parent_obj->object->getNumberOfSlots();
22  }
23 
27  function executeCommand()
28  {
29  global $tpl, $ilTabs, $ilCtrl;
30 
31  $next_class = $ilCtrl->getNextClass($this);
32 
33  switch($next_class)
34  {
35  default:
36  $cmd = $ilCtrl->getCmd("render");
37  $this->$cmd();
38  break;
39  }
40  return true;
41  }
42 
48  function render()
49  {
50  global $tpl, $lng, $ilCtrl, $ilAccess;
51 
52  include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
53  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
54 
55  if ($ilAccess->checkAccess('write', '', $this->ref_id))
56  {
57  // if we have schedules but no types - show info
58  if(sizeof($table->getData()))
59  {
60  include_once "Modules/BookingManager/classes/class.ilBookingType.php";
61  if(!sizeof(ilBookingType::getList(ilObject::_lookupObjId($this->ref_id))))
62  {
63  ilUtil::sendInfo($lng->txt("book_type_warning"));
64  }
65  }
66 
67  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
68  $bar = new ilToolbarGUI;
69  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
70  $bar = $bar->getHTML();
71  }
72 
73  $tpl->setContent($bar.$table->getHTML());
74  }
75 
79  function create()
80  {
81  global $tpl, $ilCtrl, $ilTabs, $lng;
82 
83  $ilTabs->clearTargets();
84  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
85 
86  $form = $this->initForm();
87  $tpl->setContent($form->getHTML());
88  }
89 
93  function edit()
94  {
95  global $tpl, $ilCtrl, $ilTabs, $lng;
96 
97  $ilTabs->clearTargets();
98  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
99 
100  $form = $this->initForm('edit', (int)$_GET['schedule_id']);
101  $tpl->setContent($form->getHTML());
102  }
103 
110  function initForm($a_mode = "create", $id = NULL)
111  {
112  global $lng, $ilCtrl;
113 
114  $lng->loadLanguageModule("dateplaner");
115 
116  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
117 
118  $form_gui = new ilPropertyFormGUI();
119 
120  $title = new ilTextInputGUI($lng->txt("title"), "title");
121  $title->setRequired(true);
122  $title->setSize(40);
123  $title->setMaxLength(120);
124  $form_gui->addItem($title);
125 
126  /*
127  $type = new ilRadioGroupInputGUI($lng->txt("book_schedule_type"), "type");
128  $type->setRequired(true);
129  $form_gui->addItem($type);
130  $fix = new ilRadioOption($lng->txt("book_schedule_type_fix"), "fix");
131  $fix->setInfo($lng->txt("book_schedule_type_fix_info"));
132  $type->addOption($fix);
133  $flex = new ilRadioOption($lng->txt("book_schedule_type_flexible"), "flexible");
134  $flex->setInfo($lng->txt("book_schedule_type_flexible_info"));
135  $type->addOption($flex);
136 
137  $raster = new ilNumberInputGUI($lng->txt("book_schedule_raster"), "raster");
138  $raster->setRequired(true);
139  $raster->setInfo($lng->txt("book_schedule_raster_info"));
140  $raster->setMinValue(1);
141  $raster->setSize(3);
142  $raster->setMaxLength(3);
143  $raster->setSuffix($lng->txt("book_minutes"));
144  $flex->addSubItem($raster);
145 
146  $rent_min = new ilNumberInputGUI($lng->txt("book_schedule_rent_min"), "rent_min");
147  $rent_min->setInfo($lng->txt("book_schedule_rent_info"));
148  $rent_min->setMinValue(1);
149  $rent_min->setSize(3);
150  $rent_min->setMaxLength(3);
151  $flex->addSubItem($rent_min);
152 
153  $rent_max = new ilNumberInputGUI($lng->txt("book_schedule_rent_max"), "rent_max");
154  $rent_max->setInfo($lng->txt("book_schedule_rent_info"));
155  $rent_max->setMinValue(1);
156  $rent_max->setSize(3);
157  $rent_max->setMaxLength(3);
158  $flex->addSubItem($rent_max);
159 
160  $break = new ilNumberInputGUI($lng->txt("book_schedule_break"), "break");
161  $break->setInfo($lng->txt("book_schedule_break_info"));
162  $break->setMinValue(1);
163  $break->setSize(3);
164  $break->setMaxLength(3);
165  $flex->addSubItem($break);
166  */
167 
168  include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
169  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
170  $definition->setInfo($lng->txt("book_schedule_days_info"));
171  $definition->setRequired(true);
172  $form_gui->addItem($definition);
173 
174  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
175  $deadline->setInfo($lng->txt("book_deadline_info"));
176  $deadline->setSuffix($lng->txt("book_hours"));
177  $deadline->setMinValue(0);
178  $deadline->setSize(3);
179  $deadline->setMaxLength(3);
180  $form_gui->addItem($deadline);
181 
182  if ($a_mode == "edit")
183  {
184  $form_gui->setTitle($lng->txt("book_edit_schedule"));
185 
186  $item = new ilHiddenInputGUI('schedule_id');
187  $item->setValue($id);
188  $form_gui->addItem($item);
189 
190  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
191  $schedule = new ilBookingSchedule($id);
192  $title->setValue($schedule->getTitle());
193  $deadline->setValue($schedule->getDeadline());
194 
195  /*
196  if($schedule->getRaster())
197  {
198  $type->setValue("flexible");
199  $raster->setValue($schedule->getRaster());
200  $rent_min->setValue($schedule->getMinRental());
201  $rent_max->setValue($schedule->getMaxRental());
202  $break->setValue($schedule->getAutoBreak());
203  }
204  else
205  {
206  $type->setValue("fix");
207  }
208  */
209 
210  $definition->setValue($schedule->getDefinitionBySlots());
211 
212  $form_gui->addCommandButton("update", $lng->txt("save"));
213  }
214  else
215  {
216  $form_gui->setTitle($lng->txt("book_add_schedule"));
217  $form_gui->addCommandButton("save", $lng->txt("save"));
218  $form_gui->addCommandButton("render", $lng->txt("cancel"));
219  }
220  $form_gui->setFormAction($ilCtrl->getFormAction($this));
221 
222  return $form_gui;
223  }
224 
228  function save()
229  {
230  global $tpl, $lng;
231 
232  $form = $this->initForm();
233  if($form->checkInput())
234  {
235  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
236  $obj = new ilBookingSchedule;
237  $this->formToObject($form, $obj);
238  $obj->save();
239 
240  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
241  $this->render();
242  }
243  else
244  {
245  $form->setValuesByPost();
246  $this->setDefinitionFromPost($form);
247  $tpl->setContent($form->getHTML());
248  }
249  }
250 
254  function update()
255  {
256  global $tpl, $lng;
257 
258  $form = $this->initForm('edit', (int)$_POST['schedule_id']);
259  if($form->checkInput())
260  {
261  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
262  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
263  $this->formToObject($form, $obj);
264  $obj->update();
265 
266  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
267  $this->render();
268  }
269  else
270  {
271  $form->setValuesByPost();
272  $this->setDefinitionFromPost($form);
273  $tpl->setContent($form->getHTML());
274  }
275  }
276 
282  protected function setDefinitionFromPost(ilPropertyFormGUI $form)
283  {
284  $days = $form->getInput("days");
285  if($days)
286  {
287  $days_group = $form->getItemByPostVar("days");
288  foreach($days_group->getOptions() as $option)
289  {
290  $days_fields[$option->getValue()] = $option;
291  }
292 
293  foreach($days as $day)
294  {
295  $slot = $form->getInput($day."_slot");
296  $subs = $days_fields[$day]->getSubItems();
297  if($slot[0])
298  {
299  $subs[0]->setValue($slot[0]);
300  }
301  if($slot[1])
302  {
303  $subs[1]->setValue($slot[1]);
304  }
305  }
306  }
307  }
308 
314  protected function formToObject($form, $schedule)
315  {
316  global $ilObjDataCache;
317 
318  $schedule->setTitle($form->getInput("title"));
319  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
320  $schedule->setDeadline($form->getInput("deadline"));
321 
322  /*
323  if($form->getInput("type") == "flexible")
324  {
325  $schedule->setRaster($form->getInput("raster"));
326  $schedule->setMinRental($form->getInput("rent_min"));
327  $schedule->setMaxRental($form->getInput("rent_max"));
328  $schedule->setAutoBreak($form->getInput("break"));
329  }
330  else
331  {
332  $schedule->setRaster(NULL);
333  $schedule->setMinRental(NULL);
334  $schedule->setMaxRental(NULL);
335  $schedule->setAutoBreak(NULL);
336  }
337  */
338 
339  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
340  }
341 
345  function confirmDelete()
346  {
347  global $ilCtrl, $lng, $tpl, $ilTabs;
348 
349  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
350  $conf = new ilConfirmationGUI();
351  $conf->setFormAction($ilCtrl->getFormAction($this));
352  $conf->setHeaderText($lng->txt('book_confirm_delete'));
353 
354  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
355  $type = new ilBookingSchedule((int)$_GET['schedule_id']);
356  $conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
357  $conf->setConfirm($lng->txt('delete'), 'delete');
358  $conf->setCancel($lng->txt('cancel'), 'render');
359 
360  $tpl->setContent($conf->getHTML());
361  }
362 
366  function delete()
367  {
368  global $ilCtrl, $lng;
369 
370  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
371  $obj = new ilBookingSchedule((int)$_POST['schedule_id']);
372  $obj->delete();
373 
374  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
375  $ilCtrl->redirect($this, 'render');
376  }
377 }
378 
379 ?>