ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once "./Services/Object/classes/class.ilObjectGUI.php";
5 
14 {
18  protected $ctrl;
19 
23  protected $tpl;
24 
28  protected $lng;
29 
33  protected $access;
34 
38  protected $tabs;
39 
43  protected $help;
44 
48  protected $obj_data_cache;
49 
53  protected $user;
54 
55  protected $ref_id; // [int]
56  protected $pool_id; // [int]
57  protected $pool_has_schedule; // [bool]
58  protected $pool_overall_limit; // [int]
59  protected $user_to_deasign;
63  protected $object_id;
64 
69  public function __construct($a_parent_obj)
70  {
71  global $DIC;
72 
73  $this->ctrl = $DIC->ctrl();
74  $this->tpl = $DIC["tpl"];
75  $this->lng = $DIC->language();
76  $this->access = $DIC->access();
77  $this->tabs = $DIC->tabs();
78  $this->help = $DIC["ilHelp"];
79  $this->obj_data_cache = $DIC["ilObjDataCache"];
80  $this->user = $DIC->user();
81  $this->ref_id = $a_parent_obj->ref_id;
82  $this->pool_id = $a_parent_obj->object->getId();
83  $this->pool_gui = $a_parent_obj;
84  $this->pool_has_schedule =
85  ($a_parent_obj->object->getScheduleType() != ilObjBookingPool::TYPE_NO_SCHEDULE);
86  $this->pool_overall_limit = $this->pool_has_schedule
87  ? null
88  : $a_parent_obj->object->getOverallLimit();
89 
90  $this->object_id = (int) $_REQUEST['object_id'];
91  $this->user_to_deasign = (int) $_REQUEST['bkusr'];
92  $this->rsv_ids = array_map('intval', explode(";", $_GET["rsv_ids"]));
93  }
94 
98  public function executeCommand()
99  {
101 
102  $next_class = $ilCtrl->getNextClass($this);
103 
104  switch ($next_class) {
105 
106  case "ilpropertyformgui":
107  // only case is currently adv metadata internal link in info settings, see #24497
108  $form = $this->initForm();
109  $this->ctrl->forwardCommand($form);
110  break;
111 
112  default:
113  $cmd = $ilCtrl->getCmd("render");
114  $this->$cmd();
115  break;
116  }
117  return true;
118  }
119 
125  public function render()
126  {
127  $this->pool_gui->showNoScheduleMessage();
128 
129  $tpl = $this->tpl;
131  $lng = $this->lng;
132  $ilAccess = $this->access;
133 
134  if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
135  include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
136  $bar = new ilToolbarGUI;
137  $bar->addButton($lng->txt('book_add_object'), $ilCtrl->getLinkTarget($this, 'create'));
138  $bar = $bar->getHTML();
139  }
140 
141  $tpl->setPermanentLink('book', $this->ref_id);
142 
143  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
144  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit);
145  $tpl->setContent($bar . $table->getHTML());
146  }
147 
148  public function applyFilter()
149  {
150  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
151  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit, $this->repo_parent, $this->repo_parent_call);
152  $table->resetOffset();
153  $table->writeFilterToSession();
154  $this->render();
155  }
156 
157  public function resetFilter()
158  {
159  include_once 'Modules/BookingManager/classes/class.ilBookingObjectsTableGUI.php';
160  $table = new ilBookingObjectsTableGUI($this, 'render', $this->ref_id, $this->pool_id, $this->pool_has_schedule, $this->pool_overall_limit, $this->repo_parent, $this->repo_parent_call);
161  $table->resetOffset();
162  $table->resetFilter();
163  $this->render();
164  }
165 
169  public function create(ilPropertyFormGUI $a_form = null)
170  {
171  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
172  return;
173  }
174 
176  $tpl = $this->tpl;
177  $lng = $this->lng;
178  $ilTabs = $this->tabs;
179 
180  $ilTabs->clearTargets();
181  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
182 
183  $this->setHelpId('create');
184 
185  if (!$a_form) {
186  $a_form = $this->initForm();
187  }
188  $tpl->setContent($a_form->getHTML());
189  }
190 
194  public function edit(ilPropertyFormGUI $a_form = null)
195  {
196  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
197  return;
198  }
199 
200  $tpl = $this->tpl;
202  $ilTabs = $this->tabs;
203  $lng = $this->lng;
204 
205  $ilTabs->clearTargets();
206  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
207 
208  $this->setHelpId('edit');
209 
210  if (!$a_form) {
211  $a_form = $this->initForm('edit', $this->object_id);
212  }
213  $tpl->setContent($a_form->getHTML());
214  }
215 
216  protected function setHelpId($a_id)
217  {
218  $ilHelp = $this->help;
219 
220  $object_subtype = $this->pool_has_schedule
221  ? '-schedule'
222  : '-nonschedule';
223 
224  $ilHelp->setScreenIdComponent('book');
225  $ilHelp->setScreenId('object' . $object_subtype);
226  $ilHelp->setSubScreenId($a_id);
227  }
228 
235  public function initForm($a_mode = "create", $id = null)
236  {
237  $lng = $this->lng;
239  $ilObjDataCache = $this->obj_data_cache;
240 
241  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
242 
243  $form_gui = new ilPropertyFormGUI();
244 
245  $title = new ilTextInputGUI($lng->txt("title"), "title");
246  $title->setRequired(true);
247  $title->setSize(40);
248  $title->setMaxLength(120);
249  $form_gui->addItem($title);
250 
251  $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
252  $desc->setCols(70);
253  $desc->setRows(15);
254  $form_gui->addItem($desc);
255 
256  $file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
257  $file->setALlowDeletion(true);
258  $form_gui->addItem($file);
259 
260  $nr = new ilNumberInputGUI($lng->txt("booking_nr_of_items"), "items");
261  $nr->setRequired(true);
262  $nr->setSize(3);
263  $nr->setMaxLength(3);
264  $form_gui->addItem($nr);
265 
266  if ($this->pool_has_schedule) {
267  $options = array();
268  include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
269  foreach (ilBookingSchedule::getList($ilObjDataCache->lookupObjId($this->ref_id)) as $schedule) {
270  $options[$schedule["booking_schedule_id"]] = $schedule["title"];
271  }
272  $schedule = new ilSelectInputGUI($lng->txt("book_schedule"), "schedule");
273  $schedule->setRequired(true);
274  $schedule->setOptions($options);
275  $form_gui->addItem($schedule);
276  }
277 
279  $post->setTitle($lng->txt("book_post_booking_information"));
280  $form_gui->addItem($post);
281 
282  $pdesc = new ilTextAreaInputGUI($lng->txt("book_post_booking_text"), "post_text");
283  $pdesc->setCols(70);
284  $pdesc->setRows(15);
285  $pdesc->setInfo($lng->txt("book_post_booking_text_info"));
286  $form_gui->addItem($pdesc);
287 
288  $pfile = new ilFileInputGUI($lng->txt("book_post_booking_file"), "post_file");
289  $pfile->setALlowDeletion(true);
290  $form_gui->addItem($pfile);
291 
292  // #18214 - should also work for new objects
293  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
294  $this->record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_EDITOR, "book", $this->pool_id, "bobj", $id);
295  $this->record_gui->setPropertyForm($form_gui);
296  $this->record_gui->parse();
297 
298  if ($a_mode == "edit") {
299  $form_gui->setTitle($lng->txt("book_edit_object"));
300 
301  $item = new ilHiddenInputGUI('object_id');
302  $item->setValue($id);
303  $form_gui->addItem($item);
304 
305  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
306  $obj = new ilBookingObject($id);
307  $title->setValue($obj->getTitle());
308  $desc->setValue($obj->getDescription());
309  $nr->setValue($obj->getNrOfItems());
310  $pdesc->setValue($obj->getPostText());
311  $file->setValue($obj->getFile());
312  $pfile->setValue($obj->getPostFile());
313 
314  if (isset($schedule)) {
315  $schedule->setValue($obj->getScheduleId());
316  }
317 
318  $form_gui->addCommandButton("update", $lng->txt("save"));
319  } else {
320  $form_gui->setTitle($lng->txt("book_add_object"));
321  $form_gui->addCommandButton("save", $lng->txt("save"));
322  $form_gui->addCommandButton("render", $lng->txt("cancel"));
323  }
324  $form_gui->setFormAction($ilCtrl->getFormAction($this));
325 
326  return $form_gui;
327  }
328 
332  public function save()
333  {
334  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
335  return;
336  }
337 
339  $lng = $this->lng;
340 
341  $form = $this->initForm();
342  if ($form->checkInput()) {
343  $valid = true;
344  if ($this->record_gui &&
345  !$this->record_gui->importEditFormPostValues()) {
346  $valid = false;
347  }
348 
349  if ($valid) {
350  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
351  $obj = new ilBookingObject;
352  $obj->setPoolId($this->pool_id);
353  $obj->setTitle($form->getInput("title"));
354  $obj->setDescription($form->getInput("desc"));
355  $obj->setNrOfItems($form->getInput("items"));
356  $obj->setPostText($form->getInput("post_text"));
357 
358  if ($this->pool_has_schedule) {
359  $obj->setScheduleId($form->getInput("schedule"));
360  }
361 
362  $obj->save();
363 
364  $file = $form->getItemByPostVar("file");
365  if ($_FILES["file"]["tmp_name"]) {
366  $obj->uploadFile($_FILES["file"]);
367  } elseif ($file->getDeletionFlag()) {
368  $obj->deleteFile();
369  }
370 
371  $pfile = $form->getItemByPostVar("post_file");
372  if ($_FILES["post_file"]["tmp_name"]) {
373  $obj->uploadPostFile($_FILES["post_file"]);
374  } elseif ($pfile->getDeletionFlag()) {
375  $obj->deletePostFile();
376  }
377 
378  $obj->update();
379 
380  if ($this->record_gui) {
381  $this->record_gui->writeEditForm(null, $obj->getId());
382  }
383 
384  ilUtil::sendSuccess($lng->txt("book_object_added"), true);
385  $ilCtrl->redirect($this, "render");
386  }
387  }
388 
389  $form->setValuesByPost();
390  $this->create($form);
391  }
392 
396  public function update()
397  {
398  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
399  return;
400  }
401 
402  $lng = $this->lng;
404 
405  $form = $this->initForm('edit', $this->object_id);
406  if ($form->checkInput()) {
407  $valid = true;
408  if ($this->record_gui &&
409  !$this->record_gui->importEditFormPostValues()) {
410  $valid = false;
411  }
412 
413  if ($valid) {
414  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
415  $obj = new ilBookingObject($this->object_id);
416  $obj->setTitle($form->getInput("title"));
417  $obj->setDescription($form->getInput("desc"));
418  $obj->setNrOfItems($form->getInput("items"));
419  $obj->setPostText($form->getInput("post_text"));
420 
421  $file = $form->getItemByPostVar("file");
422  if ($_FILES["file"]["tmp_name"]) {
423  $obj->uploadFile($_FILES["file"]);
424  } elseif ($file->getDeletionFlag()) {
425  $obj->deleteFile();
426  }
427 
428  $pfile = $form->getItemByPostVar("post_file");
429  if ($_FILES["post_file"]["tmp_name"]) {
430  $obj->uploadPostFile($_FILES["post_file"]);
431  } elseif ($pfile->getDeletionFlag()) {
432  $obj->deletePostFile();
433  }
434 
435  if ($this->pool_has_schedule) {
436  $obj->setScheduleId($form->getInput("schedule"));
437  }
438 
439  $obj->update();
440 
441  if ($this->record_gui) {
442  $this->record_gui->writeEditForm();
443  }
444 
445  ilUtil::sendSuccess($lng->txt("book_object_updated"), true);
446  $ilCtrl->redirect($this, "render");
447  }
448  }
449 
450  $form->setValuesByPost();
451  $this->edit($form);
452  }
453 
457  public function confirmDelete()
458  {
459  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
460  return;
461  }
462 
464  $lng = $this->lng;
465  $tpl = $this->tpl;
466  $ilTabs = $this->tabs;
467 
468  $ilTabs->clearTargets();
469  $ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
470 
471  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
472  $conf = new ilConfirmationGUI();
473  $conf->setFormAction($ilCtrl->getFormAction($this));
474  $conf->setHeaderText($lng->txt('book_confirm_delete'));
475 
476  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
477  $type = new ilBookingObject($this->object_id);
478  $conf->addItem('object_id', $this->object_id, $type->getTitle());
479  $conf->setConfirm($lng->txt('delete'), 'delete');
480  $conf->setCancel($lng->txt('cancel'), 'render');
481 
482  $tpl->setContent($conf->getHTML());
483  }
484 
488  public function delete()
489  {
490  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
491  return;
492  }
493 
495  $lng = $this->lng;
496 
497  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
498  $obj = new ilBookingObject($this->object_id);
499  $obj->delete();
500 
501  ilUtil::sendSuccess($lng->txt('book_object_deleted'), true);
502  $ilCtrl->redirect($this, 'render');
503  }
504 
505  public function rsvConfirmCancelUser()
506  {
508  $lng = $this->lng;
509  $tpl = $this->tpl;
510 
512  if (!$id) {
513  return;
514  }
515 
516  $this->setHelpId("cancel_booking");
517 
518  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
519  $conf = new ilConfirmationGUI();
520  $conf->setFormAction($ilCtrl->getFormAction($this));
521  $conf->setHeaderText($lng->txt('book_confirm_cancel'));
522 
523  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
524  $type = new ilBookingObject($id);
525  $conf->addItem('object_id', $id, $type->getTitle());
526  if ($this->user_to_deasign) {
527  $conf->addHiddenItem('bkusr', $this->user_to_deasign);
528  }
529  if ($_GET['part_view'] == ilBookingParticipantGUI::PARTICIPANT_VIEW) {
530  $conf->addHiddenItem('part_view', ilBookingParticipantGUI::PARTICIPANT_VIEW);
531  }
532  $conf->setConfirm($lng->txt('book_set_cancel'), 'rsvCancelUser');
533  $conf->setCancel($lng->txt('cancel'), 'render');
534 
535  $tpl->setContent($conf->getHTML());
536  }
537 
538  public function rsvCancelUser()
539  {
541  $lng = $this->lng;
542 
543  if ($this->user_to_deasign) {
544  $user_id = $this->user_to_deasign;
545  } else {
546  $user_id = $this->user->getId();
547  }
548 
550  if (!$id || !$user_id) {
551  return;
552  }
553 
554  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
556  $obj = new ilBookingReservation($id);
557  if ($obj->getUserId() != $user_id) {
558  ilUtil::sendFailure($lng->txt('permission_denied'), true);
559  $ilCtrl->redirect($this, 'render');
560  }
561 
563  $obj->update();
564 
565  ilUtil::sendSuccess($lng->txt('settings_saved'));
567  $this->ctrl->redirectByClass('ilbookingparticipantgui', 'render');
568  } else {
569  $ilCtrl->redirect($this, 'render');
570  }
571  }
572 
573  public function deliverInfo()
574  {
576  if (!$id) {
577  return;
578  }
579 
580  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
581  $obj = new ilBookingObject($id);
582  $file = $obj->getFileFullPath();
583  if ($file) {
584  ilUtil::deliverFile($file, $obj->getFile());
585  }
586  }
587 
588  public function displayPostInfo()
589  {
590  $tpl = $this->tpl;
592  $lng = $this->lng;
594 
596  if (!$id) {
597  return;
598  }
599 
600 
601  // placeholder
602 
603  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
605  $tmp = array();
606  foreach ($book_ids as $book_id) {
607  if (in_array($book_id, $this->rsv_ids)) {
608  $obj = new ilBookingReservation($book_id);
609  $from = $obj->getFrom();
610  $to = $obj->getTo();
611  if ($from > time()) {
612  $tmp[$from . "-" . $to]++;
613  }
614  }
615  }
616 
619 
620  $period = array();
621  ksort($tmp);
622  foreach ($tmp as $time => $counter) {
623  $time = explode("-", $time);
625  new ilDateTime($time[0], IL_CAL_UNIX),
626  new ilDateTime($time[1], IL_CAL_UNIX)
627  );
628  if ($counter > 1) {
629  $time .= " (" . $counter . ")";
630  }
631  $period[] = $time;
632  }
633  $book_id = array_shift($book_ids);
634 
636 
637 
638  /*
639  #23578 since Booking pool participants.
640  $obj = new ilBookingReservation($book_id);
641  if ($obj->getUserId() != $ilUser->getId())
642  {
643  return;
644  }
645  */
646 
647  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
648  $obj = new ilBookingObject($id);
649  $pfile = $obj->getPostFile();
650  $ptext = $obj->getPostText();
651 
652  $mytpl = new ilTemplate('tpl.booking_reservation_post.html', true, true, 'Modules/BookingManager');
653  $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
654 
655  if ($ptext) {
656  // placeholder
657  $ptext = str_replace("[OBJECT]", $obj->getTitle(), $ptext);
658  $ptext = str_replace("[PERIOD]", implode("<br />", $period), $ptext);
659 
660  $mytpl->setVariable("POST_TEXT", nl2br($ptext));
661  }
662 
663  if ($pfile) {
664  $ilCtrl->setParameter($this, "object_id", $obj->getId());
665  $url = $ilCtrl->getLinkTarget($this, 'deliverPostFile');
666  $ilCtrl->setParameter($this, "object_id", "");
667 
668  $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
669  $mytpl->setVariable("URL_FILE", $url);
670  $mytpl->setVariable("TXT_FILE", $pfile);
671  }
672 
673  $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
674  $mytpl->setVariable("URL_SUBMIT", $ilCtrl->getLinkTargetByClass('ilobjbookingpoolgui', 'render'));
675 
676  $tpl->setContent($mytpl->get());
677  }
678 
679  public function deliverPostFile()
680  {
682 
684  if (!$id) {
685  return;
686  }
687 
688  include_once 'Modules/BookingManager/classes/class.ilBookingReservation.php';
690  $obj = new ilBookingReservation($book_id);
691  if ($obj->getUserId() != $ilUser->getId()) {
692  return;
693  }
694 
695  include_once 'Modules/BookingManager/classes/class.ilBookingObject.php';
696  $obj = new ilBookingObject($id);
697  $file = $obj->getPostFileFullPath();
698  if ($file) {
699  ilUtil::deliverFile($file, $obj->getPostFile());
700  }
701  }
702 
703  //Table to assing participants to an object.
704  //Todo move to a complete GUI class
705  public function assignParticipants()
706  {
707  $this->tabs->clearTargets();
708  $this->tabs->setBackTarget($this->lng->txt('book_back_to_list'), $this->ctrl->getLinkTarget($this, 'render'));
709 
710  include_once("./Modules/BookingManager/classes/class.ilBookingAssignParticipantsTableGUI.php");
711  $table = new ilBookingAssignParticipantsTableGUI($this, 'assignParticipants', $this->ref_id, $this->pool_id, $this->object_id);
712 
713  $this->tpl->setContent($table->getHTML());
714  }
715 }
a bookable ressource
update()
Update object dataset.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
setALlowDeletion($a_val)
Set allow deletion.
This class represents a section header in a property form.
This class represents a file property in a property form.
edit(ilPropertyFormGUI $a_form=null)
Render edit form.
$valid
if(!array_key_exists('StateId', $_REQUEST)) $id
static setUseRelativeDates($a_status)
set use relative dates
$from
const IL_CAL_UNIX
confirmDelete()
Confirm delete.
user()
Definition: user.php:4
static useRelativeDates()
check if relative dates are used
global $ilCtrl
Definition: ilias.php:18
create(ilPropertyFormGUI $a_form=null)
Render creation form.
$time
Definition: cron.php:21
This class represents a hidden form property in a property form.
initForm($a_mode="create", $id=null)
Build property form.
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
Class ilBookingObjectGUI.
List participant / booking pool assignment.
if(isset($_POST['submit'])) $form
This class represents a number property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
$post
Definition: post.php:34
Date and time handling
$ilUser
Definition: imgupload.php:18
List booking objects (for booking type)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
render()
Render list of booking objects.
save()
Create new object dataset.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
addButton( $a_txt, $a_cmd, $a_target="", $a_acc_key="", $a_additional_attrs='', $a_id="", $a_class='submit')
Add button to toolbar.
This class represents a text area property in a property form.
setPoolId($a_pool_id)
Set booking pool id.
$url
if(empty($password)) $table
Definition: pwgen.php:24
static getList($a_pool_id)
Get list of booking objects for given pool.
$_POST["username"]
setRequired($a_required)
Set Required.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Confirmation screen class.
__construct($a_parent_obj)
Constructor.