ILIAS  release_8 Revision v8.24
class.ilBookingScheduleGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected \ILIAS\BookingManager\StandardGUIRequest $book_request;
29 protected ilTabsGUI $tabs;
30 protected ilCtrl $ctrl;
31 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->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 && ilBookingSchedule::lookupPoolId($this->schedule_id) !== ilObject::_lookupObjId($this->ref_id)) {
58 throw new ilPermissionException("Schedule pool id does not match pool id.");
59 }
60
61 }
62
63 public function executeCommand(): void
64 {
65 $ilCtrl = $this->ctrl;
66
67 $next_class = $ilCtrl->getNextClass($this);
68
69 switch ($next_class) {
70 default:
71 $cmd = $ilCtrl->getCmd("render");
72 $this->$cmd();
73 break;
74 }
75 }
76
81 public function render(): void
82 {
85 $ilCtrl = $this->ctrl;
86 $ilAccess = $this->access;
87
88 $table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
89
90 $bar = "";
91 if ($ilAccess->checkAccess('write', '', $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 {
113 $ilCtrl = $this->ctrl;
114 $ilTabs = $this->tabs;
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 {
134 $ilCtrl = $this->ctrl;
135 $ilTabs = $this->tabs;
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
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_time->addSubItem($deadline);
188
189 $deadline_start = new ilRadioOption($lng->txt("book_deadline_slot_start"), "slot_start");
190 $deadline_opts->addOption($deadline_start);
191
192 $deadline_slot = new ilRadioOption($lng->txt("book_deadline_slot_end"), "slot_end");
193 $deadline_opts->addOption($deadline_slot);
194
195 if ($a_mode === "edit") {
196 $schedule = new ilBookingSchedule($id);
197 }
198
199 $av = new ilFormSectionHeaderGUI();
200 $av->setTitle($lng->txt("obj_activation_list_gui"));
201 $form_gui->addItem($av);
202
203 // #18221
204 $lng->loadLanguageModule('rep');
205
206 $from = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_start"), "from");
207 $from->setShowTime(true);
208 $form_gui->addItem($from);
209
210 $to = new ilDateTimeInputGUI($lng->txt("rep_activation_limited_end"), "to");
211 $to->setShowTime(true);
212 $form_gui->addItem($to);
213
214 if ($a_mode === "edit") {
215 $form_gui->setTitle($lng->txt("book_edit_schedule"));
216
217 $item = new ilHiddenInputGUI('schedule_id');
218 $item->setValue($id);
219 $form_gui->addItem($item);
220
221 $schedule = new ilBookingSchedule($id);
222 $title->setValue($schedule->getTitle());
223 $from->setDate($schedule->getAvailabilityFrom());
224 $to->setDate($schedule->getAvailabilityTo());
225
226 if ($schedule->getDeadline() === 0) {
227 $deadline_opts->setValue("slot_start");
228 } elseif ($schedule->getDeadline() > 0) {
229 $deadline->setValue($schedule->getDeadline());
230 $deadline_opts->setValue("hours");
231 } else {
232 $deadline->setValue(0);
233 $deadline_opts->setValue("slot_end");
234 }
235
236 $definition->setValue($schedule->getDefinitionBySlots());
237
238 $form_gui->addCommandButton("update", $lng->txt("save"));
239 } else {
240 $form_gui->setTitle($lng->txt("book_add_schedule"));
241 $form_gui->addCommandButton("save", $lng->txt("save"));
242 $form_gui->addCommandButton("render", $lng->txt("cancel"));
243 }
244 $form_gui->setFormAction($ilCtrl->getFormAction($this));
245
246 return $form_gui;
247 }
248
249 public function save(): void
250 {
253
254 $form = $this->initForm();
255 if ($form->checkInput()) {
256 $obj = new ilBookingSchedule();
257 $this->formToObject($form, $obj);
258 $obj->save();
259
260 $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_added"));
261 $this->render();
262 } else {
263 $form->setValuesByPost();
264 $tpl->setContent($form->getHTML());
265 }
266 }
267
268 public function update(): void
269 {
272
273 $form = $this->initForm('edit', $this->schedule_id);
274 if ($form->checkInput()) {
275 $obj = new ilBookingSchedule($this->schedule_id);
276 $this->formToObject($form, $obj);
277 $obj->update();
278
279 $this->tpl->setOnScreenMessage('success', $lng->txt("book_schedule_updated"));
280 $this->render();
281 } else {
282 $form->setValuesByPost();
283 $tpl->setContent($form->getHTML());
284 }
285 }
286
290 protected function formToObject(
291 ilPropertyFormGUI $form,
292 ilBookingSchedule $schedule
293 ): void {
294 $ilObjDataCache = $this->obj_data_cache;
295
296 $schedule->setTitle($form->getInput("title"));
297 $schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
298
299 $from = $form->getItemByPostVar("from");
300 if ($from !== null) {
301 $schedule->setAvailabilityFrom($from->getDate());
302 }
303
304 $to = $form->getItemByPostVar("to");
305 if ($to !== null) {
306 $schedule->setAvailabilityTo($to->getDate());
307 }
308
309 switch ($form->getInput("deadline_opts")) {
310 case "slot_start":
311 $schedule->setDeadline(0);
312 break;
313
314 case "hours":
315 $schedule->setDeadline($form->getInput("deadline"));
316 break;
317
318 case "slot_end":
319 $schedule->setDeadline(-1);
320 break;
321 }
322
323 /*
324 if($form->getInput("type") == "flexible")
325 {
326 $schedule->setRaster($form->getInput("raster"));
327 $schedule->setMinRental($form->getInput("rent_min"));
328 $schedule->setMaxRental($form->getInput("rent_max"));
329 $schedule->setAutoBreak($form->getInput("break"));
330 }
331 else
332 {
333 $schedule->setRaster(NULL);
334 $schedule->setMinRental(NULL);
335 $schedule->setMaxRental(NULL);
336 $schedule->setAutoBreak(NULL);
337 }
338 */
339
340 $days = $form->getInput("days");
341 $schedule->setDefinitionBySlots($days);
342 }
343
347 public function confirmDelete(): void
348 {
349 $ilCtrl = $this->ctrl;
352 $ilHelp = $this->help;
353
354 $ilHelp->setSubScreenId("delete");
355
356
357 $conf = new ilConfirmationGUI();
358 $conf->setFormAction($ilCtrl->getFormAction($this));
359 $conf->setHeaderText($lng->txt('book_confirm_delete'));
360
361 $type = new ilBookingSchedule($this->schedule_id);
362 $conf->addItem('schedule_id', $this->schedule_id, $type->getTitle());
363 $conf->setConfirm($lng->txt('delete'), 'delete');
364 $conf->setCancel($lng->txt('cancel'), 'render');
365
366 $tpl->setContent($conf->getHTML());
367 }
368
372 public function delete(): void
373 {
374 $ilCtrl = $this->ctrl;
376
377 $obj = new ilBookingSchedule($this->schedule_id);
378 $obj->delete();
379
380 $this->tpl->setOnScreenMessage('success', $lng->txt('book_schedule_deleted'), true);
381 $ilCtrl->redirect($this, 'render');
382 }
383}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
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.
create()
Render creation form.
initForm(string $a_mode="create", ?int $id=null)
Build property form.
ILIAS BookingManager StandardGUIRequest $book_request
__construct(ilObjBookingPoolGUI $a_parent_obj)
ilGlobalTemplateInterface $tpl
formToObject(ilPropertyFormGUI $form, ilBookingSchedule $schedule)
Set form data into schedule object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAvailabilityFrom(?ilDateTime $a_date=null)
setDefinitionBySlots(array $a_def)
setDeadline(int $a_deadline)
Set deadline.
static lookupPoolId(int $schedule_id)
setAvailabilityTo(?ilDateTime $a_date=null)
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...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
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...
Help GUI class.
setScreenIdComponent(string $a_comp)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
loadLanguageModule(string $a_module)
Load language module.
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...
This class represents a number property in a property form.
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...
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
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-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
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...
setContent(string $a_html)
Sets content for standard template.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$type
$lng