ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilBookingScheduleGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected \ILIAS\BookingManager\Access\AccessManager $access;
28  protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
30  protected ilTabsGUI $tabs;
31  protected ilCtrl $ctrl;
32  protected ilLanguage $lng;
33  protected ilHelpGUI $help;
35  protected int $schedule_id;
36  protected int $ref_id;
37 
38  public function __construct(
39  ilObjBookingPoolGUI $a_parent_obj
40  ) {
41  global $DIC;
42 
43  $this->tpl = $DIC->ui()->mainTemplate();
44  $this->tabs = $DIC->tabs();
45  $this->ctrl = $DIC->ctrl();
46  $this->lng = $DIC->language();
47  $this->access = $DIC->bookingManager()->internal()->domain()->access();
48  $this->help = $DIC["ilHelp"];
49  $this->obj_data_cache = $DIC["ilObjDataCache"];
50  $this->ref_id = $a_parent_obj->getRefId();
51  $this->book_request = $DIC->bookingManager()
52  ->internal()
53  ->gui()
54  ->standardRequest();
55  $this->schedule_id = $this->book_request->getScheduleId();
56 
57  if ($this->schedule_id > 0) {
58  $this->access->validateScheduleId(
59  $this->schedule_id,
60  ilObject::_lookupObjId($this->ref_id)
61  );
62  }
63  }
64 
65  public function executeCommand(): void
66  {
67  $ilCtrl = $this->ctrl;
68 
69  $next_class = $ilCtrl->getNextClass($this);
70 
71  switch ($next_class) {
72  default:
73  $cmd = $ilCtrl->getCmd("render");
74  $this->$cmd();
75  break;
76  }
77  }
78 
83  public function render(): void
84  {
85  $tpl = $this->tpl;
86  $lng = $this->lng;
87  $ilCtrl = $this->ctrl;
88  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
89 
90  $bar = "";
91  if ($this->access->canManageSettings($this->ref_id)) {
92  // if we have schedules but no objects - show info
93  if (count($table->getData())) {
94  if (!count(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
95  $this->tpl->setOnScreenMessage('info', $lng->txt("book_type_warning"));
96  }
97  }
98 
99  $bar = new ilToolbarGUI();
100  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
101  $bar = $bar->getHTML();
102  }
103 
104  $tpl->setContent($bar . $table->getHTML());
105  }
106 
110  public function create(): void
111  {
112  $tpl = $this->tpl;
113  $ilCtrl = $this->ctrl;
114  $ilTabs = $this->tabs;
115  $lng = $this->lng;
116  $ilHelp = $this->help;
117 
118  $ilTabs->clearTargets();
119  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
120  $ilHelp->setScreenIdComponent("book");
121  $ilHelp->setScreenId("schedules");
122  $ilHelp->setSubScreenId("create");
123 
124  $form = $this->initForm();
125  $tpl->setContent($form->getHTML());
126  }
127 
131  public function edit(): void
132  {
133  $tpl = $this->tpl;
134  $ilCtrl = $this->ctrl;
135  $ilTabs = $this->tabs;
136  $lng = $this->lng;
137  $ilHelp = $this->help;
138 
139  $ilTabs->clearTargets();
140  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
141  $ilHelp->setScreenIdComponent("book");
142  $ilHelp->setScreenId("schedules");
143  $ilHelp->setSubScreenId("edit");
144 
145  $form = $this->initForm('edit', $this->schedule_id);
146  $tpl->setContent($form->getHTML());
147  }
148 
152  public function initForm(
153  string $a_mode = "create",
154  ?int $id = null
155  ): ilPropertyFormGUI {
156  $lng = $this->lng;
157  $ilCtrl = $this->ctrl;
158 
159  $lng->loadLanguageModule("dateplaner");
160 
161  $form_gui = new ilPropertyFormGUI();
162 
163  $title = new ilTextInputGUI($lng->txt("title"), "title");
164  $title->setRequired(true);
165  $title->setSize(40);
166  $title->setMaxLength(120);
167  $form_gui->addItem($title);
168 
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_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
175  $deadline_opts->setRequired(true);
176  $form_gui->addItem($deadline_opts);
177 
178  $deadline_time = new ilRadioOption($lng->txt("book_deadline_hours"), "hours");
179  $deadline_opts->addOption($deadline_time);
180 
181  $deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
182  $deadline->setInfo($lng->txt("book_deadline_info"));
183  $deadline->setSuffix($lng->txt("book_hours"));
184  $deadline->setMinValue(1);
185  $deadline->setSize(3);
186  $deadline->setMaxLength(3);
187  $deadline->setRequired(true);
188  $deadline_time->addSubItem($deadline);
189 
190  $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
191  $deadline_opts->addOption($deadline_start);
192 
193  $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
194  $deadline_opts->addOption($deadline_slot);
195 
196  if ($a_mode === "edit") {
197  $schedule = new ilBookingSchedule($id);
198  }
199 
200  $av = new ilFormSectionHeaderGUI();
201  $av->setTitle($lng->txt("obj_activation_list_gui"));
202  $form_gui->addItem($av);
203 
204  // #18221
205  $lng->loadLanguageModule('rep');
206 
207  $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
208  $from->setShowTime(true);
209  $form_gui->addItem($from);
210 
211  $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
212  $to->setShowTime(true);
213  $form_gui->addItem($to);
214 
215  if ($a_mode === "edit") {
216  $form_gui->setTitle($lng->txt("book_edit_schedule"));
217 
218  $item = new ilHiddenInputGUI('schedule_id');
219  $item->setValue($id);
220  $form_gui->addItem($item);
221 
222  $schedule = new ilBookingSchedule($id);
223  $title->setValue($schedule->getTitle());
224  $from->setDate($schedule->getAvailabilityFrom());
225  $to->setDate($schedule->getAvailabilityTo());
226 
227  if ($schedule->getDeadline() === 0) {
228  $deadline_opts->setValue("slot_start");
229  } elseif ($schedule->getDeadline() > 0) {
230  $deadline->setValue($schedule->getDeadline());
231  $deadline_opts->setValue("hours");
232  } else {
233  $deadline->setValue(0);
234  $deadline_opts->setValue("slot_end");
235  }
236 
237  $definition->setValue($schedule->getDefinitionBySlots());
238 
239  $form_gui->addCommandButton("update", $lng->txt("save"));
240  } else {
241  $form_gui->setTitle($lng->txt("book_add_schedule"));
242  $form_gui->addCommandButton("save", $lng->txt("save"));
243  $form_gui->addCommandButton("render", $lng->txt("cancel"));
244  }
245  $form_gui->setFormAction($ilCtrl->getFormAction($this));
246 
247  return $form_gui;
248  }
249 
250  public function save(): void
251  {
252  $tpl = $this->tpl;
253  $lng = $this->lng;
254 
255  $form = $this->initForm();
256  if ($form->checkInput()) {
257  $obj = new ilBookingSchedule();
258  $this->formToObject($form, $obj);
259  $obj->save();
260 
261  $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_added"));
262  $this->render();
263  } else {
264  $form->setValuesByPost();
265  $tpl->setContent($form->getHTML());
266  }
267  }
268 
269  public function update(): void
270  {
271  $tpl = $this->tpl;
272  $lng = $this->lng;
273 
274  $form = $this->initForm('edit', $this->schedule_id);
275  if ($form->checkInput()) {
276  $obj = new ilBookingSchedule($this->schedule_id);
277  $this->formToObject($form, $obj);
278  $obj->update();
279 
280  $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_updated"));
281  $this->render();
282  } else {
283  $form->setValuesByPost();
284  $tpl->setContent($form->getHTML());
285  }
286  }
287 
291  protected function formToObject(
292  ilPropertyFormGUI $form,
293  ilBookingSchedule $schedule
294  ): void {
295  $ilObjDataCache = $this->obj_data_cache;
296 
297  $schedule->setTitle($form->getInput("title"));
298  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
299 
300  $from = $form->getItemByPostVar("from");
301  if ($from !== null) {
302  $schedule->setAvailabilityFrom($from->getDate());
303  }
304 
305  $to = $form->getItemByPostVar("to");
306  if ($to !== null) {
307  $schedule->setAvailabilityTo($to->getDate());
308  }
309 
310  switch ($form->getInput("deadline_opts")) {
311  case "slot_start":
312  $schedule->setDeadline(0);
313  break;
314 
315  case "hours":
316  $schedule->setDeadline($form->getInput("deadline"));
317  break;
318 
319  case "slot_end":
320  $schedule->setDeadline(-1);
321  break;
322  }
323 
324  /*
325  if($form->getInput("type") == "flexible")
326  {
327  $schedule->setRaster($form->getInput("raster"));
328  $schedule->setMinRental($form->getInput("rent_min"));
329  $schedule->setMaxRental($form->getInput("rent_max"));
330  $schedule->setAutoBreak($form->getInput("break"));
331  }
332  else
333  {
334  $schedule->setRaster(NULL);
335  $schedule->setMinRental(NULL);
336  $schedule->setMaxRental(NULL);
337  $schedule->setAutoBreak(NULL);
338  }
339  */
340 
341  $days = $form->getInput("days");
342  $schedule->setDefinitionBySlots($days);
343  }
344 
348  public function confirmDelete(): void
349  {
350  $ilCtrl = $this->ctrl;
351  $lng = $this->lng;
352  $tpl = $this->tpl;
353  $ilHelp = $this->help;
354 
355  $ilHelp->setSubScreenId("delete");
356 
357 
358  $conf = new ilConfirmationGUI();
359  $conf->setFormAction($ilCtrl->getFormAction($this));
360  $conf->setHeaderText($lng->txt('book_confirm_delete'));
361 
362  $type = new ilBookingSchedule($this->schedule_id);
363  $conf->addItem('schedule_id', $this->schedule_id, $type->getTitle());
364  $conf->setConfirm($lng->txt('delete'), 'delete');
365  $conf->setCancel($lng->txt('cancel'), 'render');
366 
367  $tpl->setContent($conf->getHTML());
368  }
369 
373  public function delete(): void
374  {
375  $ilCtrl = $this->ctrl;
376  $lng = $this->lng;
377 
378  $obj = new ilBookingSchedule($this->schedule_id);
379  $obj->delete();
380 
381  $this->tpl->setOnScreenMessage('success', $lng->txt('book_schedule_deleted'), true);
382  $ilCtrl->redirect($this, 'render');
383  }
384 }
setDeadline(int $a_deadline)
Set deadline.
ilObjBookingPoolGUI: ilPermissionGUI, ilBookingObjectGUI ilObjBookingPoolGUI: ilBookingScheduleGUI, ilInfoScreenGUI, ilPublicUserProfileGUI ilObjBookingPoolGUI: ilCommonActionDispatcherGUI, ilObjectCopyGUI, ilObjectMetaDataGUI ilObjBookingPoolGUI: ilBookingParticipantGUI, ilBookingReservationsGUI, ilBookingPreferencesGUI ilObjBookingPoolGUI: ILIAS ilObjBookingPoolGUI: ilRepositoryGUI, ilAdministrationGUI
This class represents an option in a radio group.
initForm(string $a_mode="create", ?int $id=null)
Build property form.
ILIAS BookingManager Access AccessManager $access
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getItemByPostVar(string $a_post_var)
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
setShowTime(bool $a_showtime)
loadLanguageModule(string $a_module)
Load language module.
ILIAS BookingManager StandardGUIRequest $book_request
__construct(ilObjBookingPoolGUI $a_parent_obj)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a date/time property in a property form.
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a hidden form property in a property form.
ilGlobalTemplateInterface $tpl
getNextClass($a_gui_class=null)
This class represents a property in a property form.
This class represents a number property in a property form.
setSubScreenId(string $a_id)
setScreenIdComponent(string $a_comp)
global $DIC
Definition: shib_login.php:26
setDefinitionBySlots(array $a_def)
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
create()
Render creation form.
setRequired(bool $a_required)
formToObject(ilPropertyFormGUI $form, ilBookingSchedule $schedule)
Set form data into schedule object.
setAvailabilityTo(?ilDateTime $a_date=null)
setAvailabilityFrom(?ilDateTime $a_date=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
render()
Render list of booking schedules uses ilBookingSchedulesTableGUI.