ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  {
78  $tpl = $this->tpl;
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  {
100  $tpl = $this->tpl;
101  $lng = $this->lng;
103  $ilAccess = $this->access;
104 
105  include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
106  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
107 
108  if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
109  // if we have schedules but no objects - show info
110  if (sizeof($table->getData())) {
111  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
112  if (!sizeof(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
113  ilUtil::sendInfo($lng->txt("book_type_warning"));
114  }
115  }
116 
117  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
118  $bar = new ilToolbarGUI;
119  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
120  $bar = $bar->getHTML();
121  }
122 
123  $tpl->setContent($bar . $table->getHTML());
124  }
125 
129  public function create()
130  {
131  $tpl = $this->tpl;
133  $ilTabs = $this->tabs;
134  $lng = $this->lng;
135  $ilHelp = $this->help;
136 
137  $ilTabs->clearTargets();
138  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
139  $ilHelp->setScreenIdComponent("book");
140  $ilHelp->setScreenId("schedules");
141  $ilHelp->setSubScreenId("create");
142 
143  $form = $this->initForm();
144  $tpl->setContent($form->getHTML());
145  }
146 
150  public function edit()
151  {
152  $tpl = $this->tpl;
154  $ilTabs = $this->tabs;
155  $lng = $this->lng;
156  $ilHelp = $this->help;
157 
158  $ilTabs->clearTargets();
159  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
160  $ilHelp->setScreenIdComponent("book");
161  $ilHelp->setScreenId("schedules");
162  $ilHelp->setSubScreenId("edit");
163 
164  $form = $this->initForm('edit', $this->schedule_id);
165  $tpl->setContent($form->getHTML());
166  }
167 
174  public function initForm($a_mode = "create", $id = null)
175  {
176  $lng = $this->lng;
178 
179  $lng->loadLanguageModule("dateplaner");
180 
181  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
182 
183  $form_gui = new ilPropertyFormGUI();
184 
185  $title = new ilTextInputGUI($lng->txt("title"), "title");
186  $title->setRequired(true);
187  $title->setSize(40);
188  $title->setMaxLength(120);
189  $form_gui->addItem($title);
190 
191  include_once "Modules/BookingManager/classes/class.ilScheduleInputGUI.php";
192  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
193  $definition->setInfo($lng->txt("book_schedule_days_info"));
194  $definition->setRequired(true);
195  $form_gui->addItem($definition);
196 
197  $deadline_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
198  $deadline_opts->setRequired(true);
199  $form_gui->addItem($deadline_opts);
200 
201  $deadline_time = new ilRadioOption($lng->txt("book_deadline_hours"), "hours");
202  $deadline_opts->addOption($deadline_time);
203 
204  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
205  $deadline->setInfo($lng->txt("book_deadline_info"));
206  $deadline->setSuffix($lng->txt("book_hours"));
207  $deadline->setMinValue(1);
208  $deadline->setSize(3);
209  $deadline->setMaxLength(3);
210  $deadline_time->addSubItem($deadline);
211 
212  $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
213  $deadline_opts->addOption($deadline_start);
214 
215  $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
216  $deadline_opts->addOption($deadline_slot);
217 
218  if ($a_mode == "edit") {
219  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
220  $schedule = new ilBookingSchedule($id);
221  }
222 
223  $av = new ilFormSectionHeaderGUI();
224  $av->setTitle($lng->txt("obj_activation_list_gui"));
225  $form_gui->addItem($av);
226 
227  // #18221
228  $lng->loadLanguageModule('rep');
229 
230  $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
231  $from->setShowTime(true);
232  $form_gui->addItem($from);
233 
234  $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
235  $to->setShowTime(true);
236  $form_gui->addItem($to);
237 
238  if ($a_mode == "edit") {
239  $form_gui->setTitle($lng->txt("book_edit_schedule"));
240 
241  $item = new ilHiddenInputGUI('schedule_id');
242  $item->setValue($id);
243  $form_gui->addItem($item);
244 
245  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
246  $schedule = new ilBookingSchedule($id);
247  $title->setValue($schedule->getTitle());
248  $from->setDate($schedule->getAvailabilityFrom());
249  $to->setDate($schedule->getAvailabilityTo());
250 
251  if ($schedule->getDeadline() == 0) {
252  $deadline_opts->setValue("slot_start");
253  } elseif ($schedule->getDeadline() > 0) {
254  $deadline->setValue($schedule->getDeadline());
255  $deadline_opts->setValue("hours");
256  } else {
257  $deadline->setValue(0);
258  $deadline_opts->setValue("slot_end");
259  }
260 
261  /*
262  if($schedule->getRaster())
263  {
264  $type->setValue("flexible");
265  $raster->setValue($schedule->getRaster());
266  $rent_min->setValue($schedule->getMinRental());
267  $rent_max->setValue($schedule->getMaxRental());
268  $break->setValue($schedule->getAutoBreak());
269  }
270  else
271  {
272  $type->setValue("fix");
273  }
274  */
275 
276  $definition->setValue($schedule->getDefinitionBySlots());
277 
278  $form_gui->addCommandButton("update", $lng->txt("save"));
279  } else {
280  $form_gui->setTitle($lng->txt("book_add_schedule"));
281  $form_gui->addCommandButton("save", $lng->txt("save"));
282  $form_gui->addCommandButton("render", $lng->txt("cancel"));
283  }
284  $form_gui->setFormAction($ilCtrl->getFormAction($this));
285 
286  return $form_gui;
287  }
288 
292  public function save()
293  {
294  $tpl = $this->tpl;
295  $lng = $this->lng;
296 
297  $form = $this->initForm();
298  if ($form->checkInput()) {
299  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
300  $obj = new ilBookingSchedule;
301  $this->formToObject($form, $obj);
302  $obj->save();
303 
304  ilUtil::sendSuccess($lng->txt("book_schedule_added"));
305  $this->render();
306  } else {
307  $form->setValuesByPost();
309  $tpl->setContent($form->getHTML());
310  }
311  }
312 
316  public function update()
317  {
318  $tpl = $this->tpl;
319  $lng = $this->lng;
320 
321  $form = $this->initForm('edit', $this->schedule_id);
322  if ($form->checkInput()) {
323  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
324  $obj = new ilBookingSchedule($this->schedule_id);
325  $this->formToObject($form, $obj);
326  $obj->update();
327 
328  ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
329  $this->render();
330  } else {
331  $form->setValuesByPost();
333  $tpl->setContent($form->getHTML());
334  }
335  }
336 
343  {
344  $days = $form->getInput("days");
345  if ($days) {
346  $days_group = $form->getItemByPostVar("days");
347  foreach ($days_group->getOptions() as $option) {
348  $days_fields[$option->getValue()] = $option;
349  }
350 
351  foreach ($days as $day) {
352  $slot = $form->getInput($day . "_slot");
353  $subs = $days_fields[$day]->getSubItems();
354  if ($slot[0]) {
355  $subs[0]->setValue($slot[0]);
356  }
357  if ($slot[1]) {
358  $subs[1]->setValue($slot[1]);
359  }
360  }
361  }
362  }
363 
369  protected function formToObject($form, $schedule)
370  {
371  $ilObjDataCache = $this->obj_data_cache;
372 
373  $schedule->setTitle($form->getInput("title"));
374  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
375 
376  $from = $form->getItemByPostVar("from");
377  $schedule->setAvailabilityFrom($from->getDate());
378 
379  $to = $form->getItemByPostVar("to");
380  $schedule->setAvailabilityTo($to->getDate());
381 
382  switch ($form->getInput("deadline_opts")) {
383  case "slot_start":
384  $schedule->setDeadline(0);
385  break;
386 
387  case "hours":
388  $schedule->setDeadline($form->getInput("deadline"));
389  break;
390 
391  case "slot_end":
392  $schedule->setDeadline(-1);
393  break;
394  }
395 
396  /*
397  if($form->getInput("type") == "flexible")
398  {
399  $schedule->setRaster($form->getInput("raster"));
400  $schedule->setMinRental($form->getInput("rent_min"));
401  $schedule->setMaxRental($form->getInput("rent_max"));
402  $schedule->setAutoBreak($form->getInput("break"));
403  }
404  else
405  {
406  $schedule->setRaster(NULL);
407  $schedule->setMinRental(NULL);
408  $schedule->setMaxRental(NULL);
409  $schedule->setAutoBreak(NULL);
410  }
411  */
412 
413  $schedule->setDefinitionBySlots(ilScheduleInputGUI::getPostData("days"));
414  }
415 
419  public function confirmDelete()
420  {
422  $lng = $this->lng;
423  $tpl = $this->tpl;
424  $ilTabs = $this->tabs;
425  $ilHelp = $this->help;
426 
427  $ilHelp->setSubScreenId("delete");
428 
429 
430  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
431  $conf = new ilConfirmationGUI();
432  $conf->setFormAction($ilCtrl->getFormAction($this));
433  $conf->setHeaderText($lng->txt('book_confirm_delete'));
434 
435  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
436  $type = new ilBookingSchedule($this->schedule_id);
437  $conf->addItem('schedule_id', $this->schedule_id, $type->getTitle());
438  $conf->setConfirm($lng->txt('delete'), 'delete');
439  $conf->setCancel($lng->txt('cancel'), 'render');
440 
441  $tpl->setContent($conf->getHTML());
442  }
443 
447  public function delete()
448  {
450  $lng = $this->lng;
451 
452  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
453  $obj = new ilBookingSchedule($this->schedule_id);
454  $obj->delete();
455 
456  ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
457  $ilCtrl->redirect($this, 'render');
458  }
459 }
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.
$type
global $DIC
Definition: saml.php:7
__construct($a_parent_obj)
Constructor.
This class represents a section header in a property form.
schedule for booking ressource
if(!array_key_exists('StateId', $_REQUEST)) $id
$from
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 $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.
if(isset($_POST['submit'])) $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.
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)
initForm($a_mode="create", $id=null)
Build property form.
create()
Render creation form.
formToObject($form, $schedule)
Convert incoming form data to schedule object.
Class ilBookingScheduleGUI.
addButton( $a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
render()
Render list of booking schedules.
setDefinitionFromPost(ilPropertyFormGUI $form)
Reload definition values from post data.
if(empty($password)) $table
Definition: pwgen.php:24
setRequired($a_required)
Set Required.
setShowTime($a_showtime)
Set Show Time Information.
Confirmation screen class.