ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 
58  public function executeCommand(): void
59  {
60  $ilCtrl = $this->ctrl;
61 
62  $next_class = $ilCtrl->getNextClass($this);
63 
64  switch ($next_class) {
65  default:
66  $cmd = $ilCtrl->getCmd("render");
67  $this->$cmd();
68  break;
69  }
70  }
71 
76  public function render(): void
77  {
78  $tpl = $this->tpl;
79  $lng = $this->lng;
80  $ilCtrl = $this->ctrl;
81  $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
82 
83  $bar = "";
84  if ($this->access->canManageSettings($this->ref_id)) {
85  // if we have schedules but no objects - show info
86  if (count($table->getData())) {
87  if (!count(ilBookingObject::getList(ilObject::_lookupObjId($this->ref_id)))) {
88  $this->tpl->setOnScreenMessage('info', $lng->txt("book_type_warning"));
89  }
90  }
91 
92  $bar = new ilToolbarGUI();
93  $bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
94  $bar = $bar->getHTML();
95  }
96 
97  $tpl->setContent($bar . $table->getHTML());
98  }
99 
103  public function create(): void
104  {
105  $tpl = $this->tpl;
106  $ilCtrl = $this->ctrl;
107  $ilTabs = $this->tabs;
108  $lng = $this->lng;
109  $ilHelp = $this->help;
110 
111  $ilTabs->clearTargets();
112  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
113  $ilHelp->setScreenIdComponent("book");
114  $ilHelp->setScreenId("schedules");
115  $ilHelp->setSubScreenId("create");
116 
117  $form = $this->initForm();
118  $tpl->setContent($form->getHTML());
119  }
120 
124  public function edit(): void
125  {
126  $tpl = $this->tpl;
127  $ilCtrl = $this->ctrl;
128  $ilTabs = $this->tabs;
129  $lng = $this->lng;
130  $ilHelp = $this->help;
131 
132  $ilTabs->clearTargets();
133  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
134  $ilHelp->setScreenIdComponent("book");
135  $ilHelp->setScreenId("schedules");
136  $ilHelp->setSubScreenId("edit");
137 
138  $form = $this->initForm('edit', $this->schedule_id);
139  $tpl->setContent($form->getHTML());
140  }
141 
145  public function initForm(
146  string $a_mode = "create",
147  ?int $id = null
148  ): ilPropertyFormGUI {
149  $lng = $this->lng;
150  $ilCtrl = $this->ctrl;
151 
152  $lng->loadLanguageModule("dateplaner");
153 
154  $form_gui = new ilPropertyFormGUI();
155 
156  $title = new ilTextInputGUI($lng->txt("title"), "title");
157  $title->setRequired(true);
158  $title->setSize(40);
159  $title->setMaxLength(120);
160  $form_gui->addItem($title);
161 
162  $definition = new ilScheduleInputGUI($lng->txt("book_schedule_days"), "days");
163  $definition->setInfo($lng->txt("book_schedule_days_info"));
164  $definition->setRequired(true);
165  $form_gui->addItem($definition);
166 
167  $deadline_opts = new ilRadioGroupInputGUI($lng->txt("book_deadline_options"), "deadline_opts");
168  $deadline_opts->setRequired(true);
169  $form_gui->addItem($deadline_opts);
170 
171  $deadline_time = new ilRadioOption($lng->txt("book_deadline_hours"), "hours");
172  $deadline_opts->addOption($deadline_time);
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(1);
178  $deadline->setSize(3);
179  $deadline->setMaxLength(3);
180  $deadline_time->addSubItem($deadline);
181 
182  $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
183  $deadline_opts->addOption($deadline_start);
184 
185  $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
186  $deadline_opts->addOption($deadline_slot);
187 
188  if ($a_mode === "edit") {
189  $schedule = new ilBookingSchedule($id);
190  }
191 
192  $av = new ilFormSectionHeaderGUI();
193  $av->setTitle($lng->txt("obj_activation_list_gui"));
194  $form_gui->addItem($av);
195 
196  // #18221
197  $lng->loadLanguageModule('rep');
198 
199  $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
200  $from->setShowTime(true);
201  $form_gui->addItem($from);
202 
203  $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
204  $to->setShowTime(true);
205  $form_gui->addItem($to);
206 
207  if ($a_mode === "edit") {
208  $form_gui->setTitle($lng->txt("book_edit_schedule"));
209 
210  $item = new ilHiddenInputGUI('schedule_id');
211  $item->setValue($id);
212  $form_gui->addItem($item);
213 
214  $schedule = new ilBookingSchedule($id);
215  $title->setValue($schedule->getTitle());
216  $from->setDate($schedule->getAvailabilityFrom());
217  $to->setDate($schedule->getAvailabilityTo());
218 
219  if ($schedule->getDeadline() === 0) {
220  $deadline_opts->setValue("slot_start");
221  } elseif ($schedule->getDeadline() > 0) {
222  $deadline->setValue($schedule->getDeadline());
223  $deadline_opts->setValue("hours");
224  } else {
225  $deadline->setValue(0);
226  $deadline_opts->setValue("slot_end");
227  }
228 
229  $definition->setValue($schedule->getDefinitionBySlots());
230 
231  $form_gui->addCommandButton("update", $lng->txt("save"));
232  } else {
233  $form_gui->setTitle($lng->txt("book_add_schedule"));
234  $form_gui->addCommandButton("save", $lng->txt("save"));
235  $form_gui->addCommandButton("render", $lng->txt("cancel"));
236  }
237  $form_gui->setFormAction($ilCtrl->getFormAction($this));
238 
239  return $form_gui;
240  }
241 
242  public function save(): void
243  {
244  $tpl = $this->tpl;
245  $lng = $this->lng;
246 
247  $form = $this->initForm();
248  if ($form->checkInput()) {
249  $obj = new ilBookingSchedule();
250  $this->formToObject($form, $obj);
251  $obj->save();
252 
253  $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_added"));
254  $this->render();
255  } else {
256  $form->setValuesByPost();
257  $tpl->setContent($form->getHTML());
258  }
259  }
260 
261  public function update(): void
262  {
263  $tpl = $this->tpl;
264  $lng = $this->lng;
265 
266  $form = $this->initForm('edit', $this->schedule_id);
267  if ($form->checkInput()) {
268  $obj = new ilBookingSchedule($this->schedule_id);
269  $this->formToObject($form, $obj);
270  $obj->update();
271 
272  $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_updated"));
273  $this->render();
274  } else {
275  $form->setValuesByPost();
276  $tpl->setContent($form->getHTML());
277  }
278  }
279 
283  protected function formToObject(
284  ilPropertyFormGUI $form,
285  ilBookingSchedule $schedule
286  ): void {
287  $ilObjDataCache = $this->obj_data_cache;
288 
289  $schedule->setTitle($form->getInput("title"));
290  $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
291 
292  $from = $form->getItemByPostVar("from");
293  if ($from !== null) {
294  $schedule->setAvailabilityFrom($from->getDate());
295  }
296 
297  $to = $form->getItemByPostVar("to");
298  if ($to !== null) {
299  $schedule->setAvailabilityTo($to->getDate());
300  }
301 
302  switch ($form->getInput("deadline_opts")) {
303  case "slot_start":
304  $schedule->setDeadline(0);
305  break;
306 
307  case "hours":
308  $schedule->setDeadline($form->getInput("deadline"));
309  break;
310 
311  case "slot_end":
312  $schedule->setDeadline(-1);
313  break;
314  }
315 
316  /*
317  if($form->getInput("type") == "flexible")
318  {
319  $schedule->setRaster($form->getInput("raster"));
320  $schedule->setMinRental($form->getInput("rent_min"));
321  $schedule->setMaxRental($form->getInput("rent_max"));
322  $schedule->setAutoBreak($form->getInput("break"));
323  }
324  else
325  {
326  $schedule->setRaster(NULL);
327  $schedule->setMinRental(NULL);
328  $schedule->setMaxRental(NULL);
329  $schedule->setAutoBreak(NULL);
330  }
331  */
332 
333  $days = $form->getInput("days");
334  $schedule->setDefinitionBySlots($days);
335  }
336 
340  public function confirmDelete(): void
341  {
342  $ilCtrl = $this->ctrl;
343  $lng = $this->lng;
344  $tpl = $this->tpl;
345  $ilHelp = $this->help;
346 
347  $ilHelp->setSubScreenId("delete");
348 
349 
350  $conf = new ilConfirmationGUI();
351  $conf->setFormAction($ilCtrl->getFormAction($this));
352  $conf->setHeaderText($lng->txt('book_confirm_delete'));
353 
354  $type = new ilBookingSchedule($this->schedule_id);
355  $conf->addItem('schedule_id', $this->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  public function delete(): void
366  {
367  $ilCtrl = $this->ctrl;
368  $lng = $this->lng;
369 
370  $obj = new ilBookingSchedule($this->schedule_id);
371  $obj->delete();
372 
373  $this->tpl->setOnScreenMessage('success', $lng->txt('book_schedule_deleted'), true);
374  $ilCtrl->redirect($this, 'render');
375  }
376 }
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:22
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.