ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarAppointmentPanelGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 protected ?ilDate $seed;
28
29 protected static int $counter = 0;
30 protected static ?self $instance = null;
31
33
34 protected ?ilTemplate $tpl = null;
35 protected ilLanguage $lng;
37 protected ilTree $tree;
38 protected ilObjUser $user;
39
40 protected function __construct(?ilDate $seed = null)
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->ctrl = $DIC->ctrl();
46 $this->tree = $DIC->repositoryTree();
47 $this->user = $DIC->user();
49 $this->seed = $seed;
50 }
51
55 public static function _getInstance(ilDate $seed): self
56 {
57 if (!self::$instance instanceof self) {
58 self::$instance = new self($seed);
59 }
60 return self::$instance;
61 }
62
63 public function getSeed(): ?ilDate
64 {
65 return $this->seed;
66 }
67
68 public function getHTML($a_app): string
69 {
70 global $DIC;
71
73
74 $this->tpl = new ilTemplate('tpl.appointment_panel.html', true, true, 'components/ILIAS/Calendar');
75
76 // Panel variables
77 $this->tpl->setVariable('PANEL_NUM', self::$counter);
78 $this->tpl->setVariable('PANEL_TITLE', str_replace(' ()', '', $a_app['event']->getPresentationTitle(false)));
79 $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_details'));
80 $this->tpl->setVariable('PANEL_TXT_DATE', $this->lng->txt('date'));
81
82 if ($a_app['fullday']) {
83 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
84 new ilDate($a_app['dstart'], IL_CAL_UNIX),
85 new ilDate($a_app['dend'], IL_CAL_UNIX)
86 ));
87 } else {
88 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
89 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
90 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
91 ));
92 }
93 if ($a_app['event']->getLocation()) {
94 $this->tpl->setVariable('PANEL_TXT_WHERE', $this->lng->txt('cal_where'));
95 $this->tpl->setVariable('PANEL_WHERE', ilUtil::makeClickable($a_app['event']->getLocation(), true));
96 }
97 if ($a_app['event']->getDescription()) {
98 $this->tpl->setVariable('PANEL_TXT_DESC', $this->lng->txt('description'));
99 $this->tpl->setVariable('PANEL_DESC', ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
100 }
101
102 $cat_id = ilCalendarCategoryAssignments::_lookupCategory($a_app['event']->getEntryId());
103 $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
104 $entry_obj_id = $cat_info['subitem_obj_ids'][$cat_id] ?? $cat_info['obj_id'];
105
106 $this->tpl->setVariable('PANEL_TXT_CAL_TYPE', $this->lng->txt('cal_cal_type'));
107 switch ($cat_info['type']) {
109 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_system'));
110 break;
111
113 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_personal'));
114 break;
115
117 $type = ilObject::_lookupType($cat_info['obj_id']);
118 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_' . $type));
119
120 // Course group appointment registration
121 if ($this->settings->isCGRegistrationEnabled() and $type == 'crs' or $type == 'grp') {
122 if (!$a_app['event']->isAutoGenerated()) {
123 $reg = new ilCalendarRegistration($a_app['event']->getEntryId());
124
125 if ($reg->isRegistered(
126 $this->user->getId(),
127 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
128 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
129 )) {
130 $this->tpl->setCurrentBlock('panel_cancel_book_link');
131 $this->ctrl->setParameterByClass(
132 'ilcalendarappointmentgui',
133 'seed',
134 $this->getSeed()->get(IL_CAL_DATE)
135 );
136 $this->ctrl->setParameterByClass(
137 'ilcalendarappointmentgui',
138 'app_id',
139 $a_app['event']->getEntryId()
140 );
141 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
142 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
143
144 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_reg_unregister'));
145 $this->tpl->setVariable(
146 'PANEL_CANCELBOOK_HREF',
147 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmUnregister')
148 );
149 $this->tpl->parseCurrentBlock();
150 } else {
151 $this->tpl->setCurrentBlock('panel_book_link');
152 $this->ctrl->setParameterByClass(
153 'ilcalendarappointmentgui',
154 'seed',
155 $this->getSeed()->get(IL_CAL_DATE)
156 );
157 $this->ctrl->setParameterByClass(
158 'ilcalendarappointmentgui',
159 'app_id',
160 $a_app['event']->getEntryId()
161 );
162 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
163 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
164 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_reg_register'));
165 $this->tpl->setVariable(
166 'PANEL_BOOK_HREF',
167 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmRegister')
168 );
169 $this->tpl->parseCurrentBlock();
170 }
171
172 $registrations = array();
173 foreach ($reg->getRegisteredUsers(
174 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
175 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
176 ) as $usr_data) {
177 $usr_id = $usr_data;
178 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $usr_id);
179 $registrations[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
180 'ilconsultationhoursgui',
181 'showprofile'
182 ) . '">' . ilObjUser::_lookupFullname($usr_id);
183 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
184 }
185 if (count($registrations)) {
186 $this->tpl->setCurrentBlock('panel_current_booking');
187 $this->tpl->setVariable(
188 'PANEL_TXT_CURRENT_BOOKING',
189 $this->lng->txt('cal_reg_registered_users')
190 );
191 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $registrations));
192 $this->tpl->parseCurrentBlock();
193 }
194 }
195 }
196 break;
197
199 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_ch'));
200
201 $entry = new ilBookingEntry($a_app['event']->getContextId());
202
203 $is_owner = $entry->isOwner();
204 $user_entry = ($cat_info['obj_id'] == $this->user->getId());
205
206 if ($user_entry && !$is_owner) {
207 // find source calendar entry in owner calendar
209 $entry->getObjId(),
210 $a_app['event']->getContextId(),
211 $a_app['event']->getStart()
212 );
213 $ref_event = $apps[0];
214 } else {
215 $ref_event = $a_app['event']->getEntryId();
216 }
217
218 $this->tpl->setCurrentBlock('panel_booking_owner');
219 $this->tpl->setVariable('PANEL_TXT_BOOKING_OWNER', $this->lng->txt('cal_ch_booking_owner'));
220 $this->tpl->setVariable('PANEL_BOOKING_OWNER', ilObjUser::_lookupFullname($entry->getObjId()));
221 $this->tpl->parseCurrentBlock();
222
223 $this->tpl->setCurrentBlock('panel_max_booking');
224 $this->tpl->setVariable('PANEL_TXT_MAX_BOOKING', $this->lng->txt('cal_ch_num_bookings'));
225 $this->tpl->setVariable('PANEL_MAX_BOOKING', $entry->getNumberOfBookings());
226 $this->tpl->parseCurrentBlock();
227
228 if (!$is_owner) {
229 if ($entry->hasBooked($ref_event)) {
230 if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
231 $this->tpl->setCurrentBlock('panel_cancel_book_link');
232 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
233 $this->ctrl->setParameterByClass(
234 'ilcalendarappointmentgui',
235 'seed',
236 $this->getSeed()->get(IL_CAL_DATE)
237 );
238 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
239 $this->tpl->setVariable(
240 'PANEL_CANCELBOOK_HREF',
241 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
242 );
243 $this->tpl->parseCurrentBlock();
244 }
245 } #else if(!$entry->isBookedOut($ref_event))
246 elseif ($entry->isAppointmentBookableForUser($ref_event, $GLOBALS['DIC']['ilUser']->getId())) {
247 $this->tpl->setCurrentBlock('panel_book_link');
248 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
249 $this->ctrl->setParameterByClass(
250 'ilcalendarappointmentgui',
251 'seed',
252 $this->getSeed()->get(IL_CAL_DATE)
253 );
254 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_ch_book'));
255 $this->tpl->setVariable(
256 'PANEL_BOOK_HREF',
257 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book')
258 );
259 $this->tpl->parseCurrentBlock();
260 }
261
262 $this->tpl->setCurrentBlock('panel_current_booking');
263 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
264 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', $entry->getCurrentNumberOfBookings($ref_event));
265 $this->tpl->parseCurrentBlock();
266 } else {
267 $obj_ids = $entry->getTargetObjIds();
268 foreach ($obj_ids as $obj_id) {
269 $title = ilObject::_lookupTitle($obj_id);
270 $refs = ilObject::_getAllReferences($obj_id);
271 $this->tpl->setCurrentBlock('panel_booking_target_row');
272 $this->tpl->setVariable('PANEL_BOOKING_TARGET_TITLE', $title);
273 $this->tpl->setVariable('PANEL_BOOKING_TARGET', ilLink::_getLink(end($refs)));
274 $this->tpl->parseCurrentBlock();
275 }
276 if ($obj_ids) {
277 $this->tpl->setCurrentBlock('panel_booking_target');
278 $this->tpl->setVariable('PANEL_TXT_BOOKING_TARGET', $this->lng->txt('cal_ch_target_object'));
279 $this->tpl->parseCurrentBlock();
280 }
281
282 $link_users = true;
284 $link_users = false;
285 }
286
287 $bookings = array();
288 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', 1);
289 foreach ($entry->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) {
290 if ($link_users) {
291 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $user_id);
292 $bookings[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
293 'ilconsultationhoursgui',
294 'showprofile'
295 ) . '">' .
296 ilObjUser::_lookupFullname($user_id) . '</a>';
297 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
298 } else {
300 }
301 }
302 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', '');
303 $this->tpl->setCurrentBlock('panel_current_booking');
304 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
305 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $bookings));
306 $this->tpl->parseCurrentBlock();
307 }
308 break;
309
311 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_booking'));
312
313 $this->tpl->setCurrentBlock('panel_cancel_book_link');
314 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
315 $this->ctrl->setParameterByClass(
316 'ilcalendarappointmentgui',
317 'seed',
318 $this->getSeed()->get(IL_CAL_DATE)
319 );
320 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
321 $this->tpl->setVariable(
322 'PANEL_CANCELBOOK_HREF',
323 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
324 );
325 $this->tpl->parseCurrentBlock();
326 break;
327 }
328
329 $this->tpl->setVariable('PANEL_TXT_CAL_NAME', $this->lng->txt('cal_calendar_name'));
330 $this->tpl->setVariable('PANEL_CAL_NAME', $cat_info['title']);
331
332 if ($cat_info['editable'] and !$a_app['event']->isAutoGenerated()) {
333 $this->tpl->setCurrentBlock('panel_edit_link');
334 $this->tpl->setVariable('TXT_PANEL_EDIT', $this->lng->txt('edit'));
335
336 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
337 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
338 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
339 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
340 $this->tpl->setVariable(
341 'PANEL_EDIT_HREF',
342 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askEdit')
343 );
344
345 $this->tpl->setCurrentBlock('panel_delete_link');
346 $this->tpl->setVariable('TXT_PANEL_DELETE', $this->lng->txt('delete'));
347
348 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
349 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
350 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
351 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
352 $this->tpl->setVariable(
353 'PANEL_DELETE_HREF',
354 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askdelete')
355 );
356 $this->tpl->parseCurrentBlock();
357 }
358 if ($cat_info['type'] == ilCalendarCategory::TYPE_OBJ) {
359 $refs = ilObject::_getAllReferences($entry_obj_id);
360 $type = ilObject::_lookupType($entry_obj_id);
361 $title = ilObject::_lookupTitle($entry_obj_id) ?
362 ilObject::_lookupTitle($entry_obj_id) :
363 $this->lng->txt('obj_' . $type);
364
365 $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($entry_obj_id));
366 $parent = $this->tree->getParentId(current($refs));
367 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjId($parent));
368 $this->tpl->setVariable('PANEL_TXT_LINK', $this->lng->txt('ext_link'));
369 $this->tpl->setVariable('PANEL_LINK_HREF', $href);
370 $this->tpl->setVariable('PANEL_LINK_NAME', $title);
371 $this->tpl->setVariable('PANEL_PARENT', $parent_title);
372 }
373
374 return $this->tpl->get();
375 }
376}
const IL_CAL_DATE
const IL_CAL_UNIX
Booking definition.
GUI class for YUI appointment panels.
static _getInstance(ilDate $seed)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
registration for calendar appointments
Stores all calendar relevant settings.
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 formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
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.
Class for single dates.
language handling
User class.
static _lookupFullname(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static makeClickable(string $a_text, bool $detectGotoLinks=false, ?string $ilias_http_path=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
$counter
$GLOBALS["DIC"]
Definition: wac.php:54