ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBookingObjectGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $ctrl;
17
21 protected $tpl;
22
26 protected $lng;
27
31 protected $access;
32
36 protected $tabs;
37
41 protected $help;
42
46 protected $obj_data_cache;
47
51 protected $user;
52
53 protected $pool_has_schedule; // [bool]
54 protected $pool_overall_limit; // [int]
55
59 protected $pool_uses_preferences = false;
60
65 protected $management = true;
66
71 protected $context_obj_id;
72
76 protected $object_id;
77
82 public function __construct($a_parent_obj, $seed, $sseed, ilBookingHelpAdapter $help, int $context_obj_id = 0)
83 {
84 global $DIC;
85
86 $this->ctrl = $DIC->ctrl();
87 $this->tpl = $DIC["tpl"];
88 $this->lng = $DIC->language();
89 $this->access = $DIC->access();
90 $this->tabs = $DIC->tabs();
91 $this->help = $help;
92 $this->obj_data_cache = $DIC["ilObjDataCache"];
93 $this->user = $DIC->user();
94
95 $this->seed = $seed;
96 $this->sseed = $sseed;
97
98 $this->context_obj_id = $context_obj_id;
99
101 $this->pool_gui = $a_parent_obj;
102 $this->pool_has_schedule =
103 ($a_parent_obj->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE);
104 $this->pool_uses_preferences =
105 ($a_parent_obj->object->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES);
106 $this->pool_overall_limit = $this->pool_has_schedule
107 ? null
108 : $a_parent_obj->object->getOverallLimit();
109
110 $this->object_id = (int) $_REQUEST['object_id'];
111 $this->ref_id = (int) $_REQUEST['ref_id'];
112 $this->ctrl->saveParameter($this, "object_id");
113
114 $this->rsv_ids = array_map('intval', explode(";", $_GET["rsv_ids"]));
115 }
116
122 public function activateManagement($a_val)
123 {
124 $this->management = $a_val;
125 }
126
132 public function isManagementActivated()
133 {
134 return $this->management;
135 }
136
137
143 protected function getPoolRefId() : int
144 {
145 return $this->pool_gui->ref_id;
146 }
147
153 protected function getPoolObjId() : int
154 {
155 return $this->pool_gui->object->getId();
156 }
157
163 protected function hasPoolSchedule() : bool
164 {
165 return ($this->pool_gui->object->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE);
166 }
167
173 protected function getPoolOverallLimit()
174 {
175 return $this->hasPoolSchedule()
176 ? null
177 : $this->pool_gui->object->getOverallLimit();
178 }
179
184 public function executeCommand()
185 {
186 $ilCtrl = $this->ctrl;
187
188 $next_class = $ilCtrl->getNextClass($this);
189
190 switch ($next_class) {
191
192 case "ilpropertyformgui":
193 // only case is currently adv metadata internal link in info settings, see #24497
194 $form = $this->initForm();
195 $this->ctrl->forwardCommand($form);
196 break;
197
198 case "ilbookingprocessgui":
199 if (!$this->pool_uses_preferences) {
200 $ilCtrl->setReturn($this, "render");
201 } else {
202 $ilCtrl->setReturn($this, "returnToPreferences");
203 }
204 $process_gui = new ilBookingProcessGUI(
205 $this->pool_gui->object,
206 $this->object_id,
207 $this->help,
208 $this->seed,
209 $this->sseed,
210 $this->context_obj_id
211 );
212 $this->ctrl->forwardCommand($process_gui);
213 break;
214
215 default:
216 $cmd = $ilCtrl->getCmd("render");
217 $this->$cmd();
218 break;
219 }
220 return true;
221 }
222
226 protected function showNoScheduleMessage()
227 {
228 $this->pool_gui->showNoScheduleMessage();
229 }
230
234 protected function returnToPreferences()
235 {
236 $this->ctrl->redirectByClass("ilBookingPreferencesGUI");
237 }
238
244 public function render()
245 {
246 $this->showNoScheduleMessage();
247
249 $ilCtrl = $this->ctrl;
251 $ilAccess = $this->access;
252
253 if ($this->isManagementActivated() && $ilAccess->checkAccess('write', '', $this->getPoolRefId())) {
254 $bar = new ilToolbarGUI;
255 $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
256 $bar = $bar->getHTML();
257 }
258
259 $tpl->setPermanentLink('book', $this->getPoolRefId());
260
261 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
262 $tpl->setContent($bar . $table->getHTML());
263 }
264
265 public function applyFilter()
266 {
267 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
268 $table->resetOffset();
269 $table->writeFilterToSession();
270 $this->render();
271 }
272
273 public function resetFilter()
274 {
275 $table = new ilBookingObjectsTableGUI($this, 'render', $this->getPoolRefId(), $this->getPoolObjId(), $this->hasPoolSchedule(), $this->getPoolOverallLimit(), $this->isManagementActivated());
276 $table->resetOffset();
277 $table->resetFilter();
278 $this->render();
279 }
280
284 public function create(ilPropertyFormGUI $a_form = null)
285 {
286 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
287 return;
288 }
289
290 $ilCtrl = $this->ctrl;
293 $ilTabs = $this->tabs;
294
295 $ilTabs->clearTargets();
296 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
297
298 $this->setHelpId('create');
299
300 if (!$a_form) {
301 $a_form = $this->initForm();
302 }
303 $tpl->setContent($a_form->getHTML());
304 }
305
309 public function edit(ilPropertyFormGUI $a_form = null)
310 {
311 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
312 return;
313 }
314
316 $ilCtrl = $this->ctrl;
317 $ilTabs = $this->tabs;
319
320 $ilTabs->clearTargets();
321 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
322
323 $this->setHelpId('edit');
324
325 if (!$a_form) {
326 $a_form = $this->initForm('edit', $this->object_id);
327 }
328 $tpl->setContent($a_form->getHTML());
329 }
330
331 protected function setHelpId($a_id)
332 {
333 $this->help->setHelpId($a_id);
334 }
335
342 public function initForm($a_mode = "create", $id = null)
343 {
345 $ilCtrl = $this->ctrl;
346 $ilObjDataCache = $this->obj_data_cache;
347
348 $form_gui = new ilPropertyFormGUI();
349
350 $title = new ilTextInputGUI($lng->txt("title"), "title");
351 $title->setRequired(true);
352 $title->setSize(40);
353 $title->setMaxLength(120);
354 $form_gui->addItem($title);
355
356 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
357 $desc->setCols(70);
358 $desc->setRows(15);
359 $form_gui->addItem($desc);
360
361 $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
362 $file->setALlowDeletion(true);
363 $form_gui->addItem($file);
364
365 $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
366 $nr->setRequired(true);
367 $nr->setSize(3);
368 $nr->setMaxLength(3);
369 $form_gui->addItem($nr);
370
371 if ($this->hasPoolSchedule()) {
372 $options = array();
373 foreach (ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->getPoolRefId())) as $schedule) {
374 $options[$schedule["booking_schedule_id"]] = $schedule["title"];
375 }
376 $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
377 $schedule->setRequired(true);
378 $schedule->setOptions($options);
379 $form_gui->addItem($schedule);
380 }
381
382 $post = new ilFormSectionHeaderGUI();
383 $post->setTitle($lng->txt("book_post_booking_information"));
384 $form_gui->addItem($post);
385
386 $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
387 $pdesc->setCols(70);
388 $pdesc->setRows(15);
389 $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
390 $form_gui->addItem($pdesc);
391
392 $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
393 $pfile->setALlowDeletion(true);
394 $form_gui->addItem($pfile);
395
396 // #18214 - should also work for new objects
397 $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, "book", $this->getPoolObjId(), "bobj", $id);
398 $this->record_gui->setPropertyForm($form_gui);
399 $this->record_gui->parse();
400
401 if ($a_mode == "edit") {
402 $form_gui->setTitle($lng->txt("book_edit_object"));
403
404 $item = new ilHiddenInputGUI('object_id');
405 $item->setValue($id);
406 $form_gui->addItem($item);
407
408 $obj = new ilBookingObject($id);
409 $title->setValue($obj->getTitle());
410 $desc->setValue($obj->getDescription());
411 $nr->setValue($obj->getNrOfItems());
412 $pdesc->setValue($obj->getPostText());
413 $file->setValue($obj->getFile());
414 $pfile->setValue($obj->getPostFile());
415
416 if (isset($schedule)) {
417 $schedule->setValue($obj->getScheduleId());
418 }
419
420 $form_gui->addCommandButton("update", $lng->txt("save"));
421 } else {
422 $form_gui->setTitle($lng->txt("book_add_object"));
423 $form_gui->addCommandButton("save", $lng->txt("save"));
424 $form_gui->addCommandButton("render", $lng->txt("cancel"));
425 }
426 $form_gui->setFormAction($ilCtrl->getFormAction($this));
427
428 return $form_gui;
429 }
430
434 public function save()
435 {
436 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
437 return;
438 }
439
440 $ilCtrl = $this->ctrl;
442
443 $form = $this->initForm();
444 if ($form->checkInput()) {
445 $valid = true;
446 if ($this->record_gui &&
447 !$this->record_gui->importEditFormPostValues()) {
448 $valid = false;
449 }
450 if ($valid) {
451 $obj = new ilBookingObject;
452 $obj->setPoolId($this->getPoolObjId());
453 $obj->setTitle($form->getInput("title"));
454 $obj->setDescription($form->getInput("desc"));
455 $obj->setNrOfItems($form->getInput("items"));
456 $obj->setPostText($form->getInput("post_text"));
457
458 if ($this->hasPoolSchedule()) {
459 $obj->setScheduleId($form->getInput("schedule"));
460 }
461
462 $obj->save();
463
464 $file = $form->getItemByPostVar("file");
465 if ($_FILES["file"]["tmp_name"]) {
466 $obj->uploadFile($_FILES["file"]);
467 } elseif ($file->getDeletionFlag()) {
468 $obj->deleteFile();
469 }
470
471 $pfile = $form->getItemByPostVar("post_file");
472 if ($_FILES["post_file"]["tmp_name"]) {
473 $obj->uploadPostFile($_FILES["post_file"]);
474 } elseif ($pfile->getDeletionFlag()) {
475 $obj->deletePostFile();
476 }
477
478 $obj->update();
479
480 if ($this->record_gui) {
481 $this->record_gui->writeEditForm(null, $obj->getId());
482 }
483
484 ilUtil::sendSuccess($lng->txt("book_object_added"), true);
485 $ilCtrl->redirect($this, "render");
486 }
487 }
488
489 $form->setValuesByPost();
490 $this->create($form);
491 }
492
496 public function update()
497 {
498 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
499 return;
500 }
501
503 $ilCtrl = $this->ctrl;
504
505 $form = $this->initForm('edit', $this->object_id);
506 if ($form->checkInput()) {
507 $valid = true;
508 if ($this->record_gui &&
509 !$this->record_gui->importEditFormPostValues()) {
510 $valid = false;
511 }
512
513 if ($valid) {
514 $obj = new ilBookingObject($this->object_id);
515 $obj->setTitle($form->getInput("title"));
516 $obj->setDescription($form->getInput("desc"));
517 $obj->setNrOfItems($form->getInput("items"));
518 $obj->setPostText($form->getInput("post_text"));
519
520 $file = $form->getItemByPostVar("file");
521 if ($_FILES["file"]["tmp_name"]) {
522 $obj->uploadFile($_FILES["file"]);
523 } elseif ($file->getDeletionFlag()) {
524 $obj->deleteFile();
525 }
526
527 $pfile = $form->getItemByPostVar("post_file");
528 if ($_FILES["post_file"]["tmp_name"]) {
529 $obj->uploadPostFile($_FILES["post_file"]);
530 } elseif ($pfile->getDeletionFlag()) {
531 $obj->deletePostFile();
532 }
533
534 if ($this->hasPoolSchedule()) {
535 $obj->setScheduleId($form->getInput("schedule"));
536 }
537
538 $obj->update();
539
540 if ($this->record_gui) {
541 $this->record_gui->writeEditForm();
542 }
543
544 ilUtil::sendSuccess($lng->txt("book_object_updated"), true);
545 $ilCtrl->redirect($this, "render");
546 }
547 }
548
549 $form->setValuesByPost();
550 $this->edit($form);
551 }
552
556 public function confirmDelete()
557 {
558 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
559 return;
560 }
561
562 $ilCtrl = $this->ctrl;
565 $ilTabs = $this->tabs;
566
567 $ilTabs->clearTargets();
568 $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
569
570 $conf = new ilConfirmationGUI();
571 $conf->setFormAction($ilCtrl->getFormAction($this));
572 $conf->setHeaderText($lng->txt('book_confirm_delete'));
573
574 $type = new ilBookingObject($this->object_id);
575 $conf->addItem('object_id', $this->object_id, $type->getTitle());
576 $conf->setConfirm($lng->txt('delete'), 'delete');
577 $conf->setCancel($lng->txt('cancel'), 'render');
578
579 $tpl->setContent($conf->getHTML());
580 }
581
585 public function delete()
586 {
587 if (!$this->access->checkAccess('write', '', $this->ref_id)) {
588 return;
589 }
590
591 $ilCtrl = $this->ctrl;
593
594 $obj = new ilBookingObject($this->object_id);
595 $obj->delete();
596
597 ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
598 $ilCtrl->setParameter($this, 'object_id', "");
599 $ilCtrl->redirect($this, 'render');
600 }
601
602
603 public function deliverInfo()
604 {
605 $id = $this->object_id;
606 if (!$id) {
607 return;
608 }
609
610 $obj = new ilBookingObject($id);
611 $file = $obj->getFileFullPath();
612 if ($file) {
613 ilUtil::deliverFile($file, $obj->getFile());
614 }
615 }
616}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Help adapter for booking manager.
Class ilBookingObjectGUI.
returnToPreferences()
Return to preferences.
edit(ilPropertyFormGUI $a_form=null)
Render edit form.
update()
Update object dataset.
isManagementActivated()
Is management activated?
hasPoolSchedule()
Has booking pool a schedule?
getPoolOverallLimit()
Get booking pool overall limit.
showNoScheduleMessage()
Show no schedule message.
render()
Render list of booking objects.
initForm($a_mode="create", $id=null)
Build property form.
save()
Create new object dataset.
getPoolObjId()
Get obj id of booking pool.
create(ilPropertyFormGUI $a_form=null)
Render creation form.
getPoolRefId()
Get ref id of booking pool.
activateManagement($a_val)
Activate management.
a bookable ressource
setPoolId($a_pool_id)
Set booking pool id.
List booking objects (for booking type)
Booking process ui class.
static getList($a_pool_id)
Get list of booking objects for given pool.
Confirmation screen class.
This class represents a file property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$valid
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type