ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCalendarAppointmentPanelGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
32 {
33  protected ?ilDate $seed;
34 
35  protected static int $counter = 0;
36  protected static ?self $instance = null;
37 
39 
40  protected ?ilTemplate $tpl = null;
41  protected ilLanguage $lng;
43  protected ilTree $tree;
44  protected ilObjUser $user;
45 
46  protected function __construct(ilDate $seed = null)
47  {
48  global $DIC;
49 
50  $this->lng = $DIC->language();
51  $this->ctrl = $DIC->ctrl();
52  $this->tree = $DIC->repositoryTree();
53  $this->user = $DIC->user();
55  $this->seed = $seed;
56  }
57 
61  public static function _getInstance(ilDate $seed): self
62  {
63  if (!self::$instance instanceof self) {
64  self::$instance = new self($seed);
65  }
66  return self::$instance;
67  }
68 
69  public function getSeed(): ?ilDate
70  {
71  return $this->seed;
72  }
73 
74  public function getHTML($a_app): string
75  {
76  global $DIC;
77 
78  self::$counter++;
79 
80  $this->tpl = new ilTemplate('tpl.appointment_panel.html', true, true, 'Services/Calendar');
81 
82  // Panel variables
83  $this->tpl->setVariable('PANEL_NUM', self::$counter);
84  $this->tpl->setVariable('PANEL_TITLE', str_replace(' ()', '', $a_app['event']->getPresentationTitle(false)));
85  $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_details'));
86  $this->tpl->setVariable('PANEL_TXT_DATE', $this->lng->txt('date'));
87 
88  if ($a_app['fullday']) {
89  $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
90  new ilDate($a_app['dstart'], IL_CAL_UNIX),
91  new ilDate($a_app['dend'], IL_CAL_UNIX)
92  ));
93  } else {
94  $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
95  new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
96  new ilDateTime($a_app['dend'], IL_CAL_UNIX)
97  ));
98  }
99  if ($a_app['event']->getLocation()) {
100  $this->tpl->setVariable('PANEL_TXT_WHERE', $this->lng->txt('cal_where'));
101  $this->tpl->setVariable('PANEL_WHERE', ilUtil::makeClickable($a_app['event']->getLocation(), true));
102  }
103  if ($a_app['event']->getDescription()) {
104  $this->tpl->setVariable('PANEL_TXT_DESC', $this->lng->txt('description'));
105  $this->tpl->setVariable('PANEL_DESC', ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
106  }
107 
108  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($a_app['event']->getEntryId());
109  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
110  $entry_obj_id = $cat_info['subitem_obj_ids'][$cat_id] ?? $cat_info['obj_id'];
111 
112  $this->tpl->setVariable('PANEL_TXT_CAL_TYPE', $this->lng->txt('cal_cal_type'));
113  switch ($cat_info['type']) {
115  $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_system'));
116  break;
117 
119  $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_personal'));
120  break;
121 
123  $type = ilObject::_lookupType($cat_info['obj_id']);
124  $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_' . $type));
125 
126  // Course group appointment registration
127  if ($this->settings->isCGRegistrationEnabled() and $type == 'crs' or $type == 'grp') {
128  if (!$a_app['event']->isAutoGenerated()) {
129  $reg = new ilCalendarRegistration($a_app['event']->getEntryId());
130 
131  if ($reg->isRegistered(
132  $this->user->getId(),
133  new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
134  new ilDateTime($a_app['dend'], IL_CAL_UNIX)
135  )) {
136  $this->tpl->setCurrentBlock('panel_cancel_book_link');
137  $this->ctrl->setParameterByClass(
138  'ilcalendarappointmentgui',
139  'seed',
140  $this->getSeed()->get(IL_CAL_DATE)
141  );
142  $this->ctrl->setParameterByClass(
143  'ilcalendarappointmentgui',
144  'app_id',
145  $a_app['event']->getEntryId()
146  );
147  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
148  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
149 
150  $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_reg_unregister'));
151  $this->tpl->setVariable(
152  'PANEL_CANCELBOOK_HREF',
153  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmUnregister')
154  );
155  $this->tpl->parseCurrentBlock();
156  } else {
157  $this->tpl->setCurrentBlock('panel_book_link');
158  $this->ctrl->setParameterByClass(
159  'ilcalendarappointmentgui',
160  'seed',
161  $this->getSeed()->get(IL_CAL_DATE)
162  );
163  $this->ctrl->setParameterByClass(
164  'ilcalendarappointmentgui',
165  'app_id',
166  $a_app['event']->getEntryId()
167  );
168  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
169  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
170  $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_reg_register'));
171  $this->tpl->setVariable(
172  'PANEL_BOOK_HREF',
173  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmRegister')
174  );
175  $this->tpl->parseCurrentBlock();
176  }
177 
178  $registrations = array();
179  foreach ($reg->getRegisteredUsers(
180  new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
181  new ilDateTime($a_app['dend'], IL_CAL_UNIX)
182  ) as $usr_data) {
183  $usr_id = $usr_data;
184  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $usr_id);
185  $registrations[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
186  'ilconsultationhoursgui',
187  'showprofile'
188  ) . '">' . ilObjUser::_lookupFullname($usr_id);
189  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
190  }
191  if (count($registrations)) {
192  $this->tpl->setCurrentBlock('panel_current_booking');
193  $this->tpl->setVariable(
194  'PANEL_TXT_CURRENT_BOOKING',
195  $this->lng->txt('cal_reg_registered_users')
196  );
197  $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $registrations));
198  $this->tpl->parseCurrentBlock();
199  }
200  }
201  }
202  break;
203 
205  $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_ch'));
206 
207  $entry = new ilBookingEntry($a_app['event']->getContextId());
208 
209  $is_owner = $entry->isOwner();
210  $user_entry = ($cat_info['obj_id'] == $this->user->getId());
211 
212  if ($user_entry && !$is_owner) {
213  // find source calendar entry in owner calendar
215  $entry->getObjId(),
216  $a_app['event']->getContextId(),
217  $a_app['event']->getStart()
218  );
219  $ref_event = $apps[0];
220  } else {
221  $ref_event = $a_app['event']->getEntryId();
222  }
223 
224  $this->tpl->setCurrentBlock('panel_booking_owner');
225  $this->tpl->setVariable('PANEL_TXT_BOOKING_OWNER', $this->lng->txt('cal_ch_booking_owner'));
226  $this->tpl->setVariable('PANEL_BOOKING_OWNER', ilObjUser::_lookupFullname($entry->getObjId()));
227  $this->tpl->parseCurrentBlock();
228 
229  $this->tpl->setCurrentBlock('panel_max_booking');
230  $this->tpl->setVariable('PANEL_TXT_MAX_BOOKING', $this->lng->txt('cal_ch_num_bookings'));
231  $this->tpl->setVariable('PANEL_MAX_BOOKING', $entry->getNumberOfBookings());
232  $this->tpl->parseCurrentBlock();
233 
234  if (!$is_owner) {
235  if ($entry->hasBooked($ref_event)) {
236  if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
237  $this->tpl->setCurrentBlock('panel_cancel_book_link');
238  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
239  $this->ctrl->setParameterByClass(
240  'ilcalendarappointmentgui',
241  'seed',
242  $this->getSeed()->get(IL_CAL_DATE)
243  );
244  $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
245  $this->tpl->setVariable(
246  'PANEL_CANCELBOOK_HREF',
247  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
248  );
249  $this->tpl->parseCurrentBlock();
250  }
251  } #else if(!$entry->isBookedOut($ref_event))
252  elseif ($entry->isAppointmentBookableForUser($ref_event, $GLOBALS['DIC']['ilUser']->getId())) {
253  $this->tpl->setCurrentBlock('panel_book_link');
254  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
255  $this->ctrl->setParameterByClass(
256  'ilcalendarappointmentgui',
257  'seed',
258  $this->getSeed()->get(IL_CAL_DATE)
259  );
260  $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_ch_book'));
261  $this->tpl->setVariable(
262  'PANEL_BOOK_HREF',
263  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book')
264  );
265  $this->tpl->parseCurrentBlock();
266  }
267 
268  $this->tpl->setCurrentBlock('panel_current_booking');
269  $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
270  $this->tpl->setVariable('PANEL_CURRENT_BOOKING', $entry->getCurrentNumberOfBookings($ref_event));
271  $this->tpl->parseCurrentBlock();
272  } else {
273  $obj_ids = $entry->getTargetObjIds();
274  foreach ($obj_ids as $obj_id) {
275  $title = ilObject::_lookupTitle($obj_id);
276  $refs = ilObject::_getAllReferences($obj_id);
277  $this->tpl->setCurrentBlock('panel_booking_target_row');
278  $this->tpl->setVariable('PANEL_BOOKING_TARGET_TITLE', $title);
279  $this->tpl->setVariable('PANEL_BOOKING_TARGET', ilLink::_getLink(end($refs)));
280  $this->tpl->parseCurrentBlock();
281  }
282  if ($obj_ids) {
283  $this->tpl->setCurrentBlock('panel_booking_target');
284  $this->tpl->setVariable('PANEL_TXT_BOOKING_TARGET', $this->lng->txt('cal_ch_target_object'));
285  $this->tpl->parseCurrentBlock();
286  }
287 
288  $link_users = true;
290  $link_users = false;
291  }
292 
293  $bookings = array();
294  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', 1);
295  foreach ($entry->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) {
296  if ($link_users) {
297  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $user_id);
298  $bookings[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
299  'ilconsultationhoursgui',
300  'showprofile'
301  ) . '">' .
302  ilObjUser::_lookupFullname($user_id) . '</a>';
303  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
304  } else {
305  $bookings[] = ilObjUser::_lookupFullname($user_id);
306  }
307  }
308  $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', '');
309  $this->tpl->setCurrentBlock('panel_current_booking');
310  $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
311  $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $bookings));
312  $this->tpl->parseCurrentBlock();
313  }
314  break;
315 
317  $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_booking'));
318 
319  $this->tpl->setCurrentBlock('panel_cancel_book_link');
320  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
321  $this->ctrl->setParameterByClass(
322  'ilcalendarappointmentgui',
323  'seed',
324  $this->getSeed()->get(IL_CAL_DATE)
325  );
326  $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
327  $this->tpl->setVariable(
328  'PANEL_CANCELBOOK_HREF',
329  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
330  );
331  $this->tpl->parseCurrentBlock();
332  break;
333  }
334 
335  $this->tpl->setVariable('PANEL_TXT_CAL_NAME', $this->lng->txt('cal_calendar_name'));
336  $this->tpl->setVariable('PANEL_CAL_NAME', $cat_info['title']);
337 
338  if ($cat_info['editable'] and !$a_app['event']->isAutoGenerated()) {
339  $this->tpl->setCurrentBlock('panel_edit_link');
340  $this->tpl->setVariable('TXT_PANEL_EDIT', $this->lng->txt('edit'));
341 
342  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
343  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
344  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
345  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
346  $this->tpl->setVariable(
347  'PANEL_EDIT_HREF',
348  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askEdit')
349  );
350 
351  $this->tpl->setCurrentBlock('panel_delete_link');
352  $this->tpl->setVariable('TXT_PANEL_DELETE', $this->lng->txt('delete'));
353 
354  $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
355  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
356  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
357  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
358  $this->tpl->setVariable(
359  'PANEL_DELETE_HREF',
360  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askdelete')
361  );
362  $this->tpl->parseCurrentBlock();
363  }
364  if ($cat_info['type'] == ilCalendarCategory::TYPE_OBJ) {
365  $refs = ilObject::_getAllReferences($entry_obj_id);
366  $type = ilObject::_lookupType($entry_obj_id);
367  $title = ilObject::_lookupTitle($entry_obj_id) ?
368  ilObject::_lookupTitle($entry_obj_id) :
369  $this->lng->txt('obj_' . $type);
370 
371  $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($entry_obj_id));
372  $parent = $this->tree->getParentId(current($refs));
373  $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjId($parent));
374  $this->tpl->setVariable('PANEL_TXT_LINK', $this->lng->txt('ext_link'));
375  $this->tpl->setVariable('PANEL_LINK_HREF', $href);
376  $this->tpl->setVariable('PANEL_LINK_NAME', $title);
377  $this->tpl->setVariable('PANEL_PARENT', $parent_title);
378  }
379 
380  return $this->tpl->get();
381  }
382 }
static _lookupFullname(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
static getAppointmentIds(int $a_user_id, int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)
static _lookupTitle(int $obj_id)
$GLOBALS["DIC"]
Definition: wac.php:31
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
registration for calendar appointments
static _getInstance($a_usr_id=0)
get singleton instance
const IL_CAL_DATE
GUI class for YUI appointment panels.
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
static _getInstance(ilDate $seed)
get singleton instance
static _lookupType(int $id, bool $reference=false)
static makeClickable(string $a_text, bool $detectGotoLinks=false)