ILIAS  release_8 Revision v8.24
class.ilCalendarAppointmentPanelGUI.php
Go to the documentation of this file.
1<?php
2
3declare(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 if ($a_app["event"]->isMilestone()) {
86 $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_ms_details'));
87 } else {
88 $this->tpl->setVariable('PANEL_DETAILS', $this->lng->txt('cal_details'));
89 }
90 $this->tpl->setVariable('PANEL_TXT_DATE', $this->lng->txt('date'));
91
92 if ($a_app['fullday']) {
93 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
94 new ilDate($a_app['dstart'], IL_CAL_UNIX),
95 new ilDate($a_app['dend'], IL_CAL_UNIX)
96 ));
97 } else {
98 $this->tpl->setVariable('PANEL_DATE', ilDatePresentation::formatPeriod(
99 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
100 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
101 ));
102 }
103 if ($a_app['event']->getLocation()) {
104 $this->tpl->setVariable('PANEL_TXT_WHERE', $this->lng->txt('cal_where'));
105 $this->tpl->setVariable('PANEL_WHERE', ilUtil::makeClickable($a_app['event']->getLocation(), true));
106 }
107 if ($a_app['event']->getDescription()) {
108 $this->tpl->setVariable('PANEL_TXT_DESC', $this->lng->txt('description'));
109 $this->tpl->setVariable('PANEL_DESC', ilUtil::makeClickable(nl2br($a_app['event']->getDescription())));
110 }
111
112 if ($a_app['event']->isMilestone() && $a_app['event']->getCompletion() > 0) {
113 $this->tpl->setVariable('PANEL_TXT_COMPL', $this->lng->txt('cal_task_completion'));
114 $this->tpl->setVariable('PANEL_COMPL', $a_app['event']->getCompletion() . " %");
115 }
116
117 if ($a_app['event']->isMilestone()) {
118 // users responsible
119 $users = $a_app['event']->readResponsibleUsers();
120 $delim = "";
121 $value = '';
122 foreach ($users as $r) {
123 $value .= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]";
124 $delim = "<br />";
125 }
126 if (count($users) > 0) {
127 $this->tpl->setVariable('PANEL_TXT_RESP', $this->lng->txt('cal_responsible'));
128 $this->tpl->setVariable('PANEL_RESP', $value);
129 }
130 }
131
132 $cat_id = ilCalendarCategoryAssignments::_lookupCategory($a_app['event']->getEntryId());
133 $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
134 $entry_obj_id = $cat_info['subitem_obj_ids'][$cat_id] ?? $cat_info['obj_id'];
135
136 $this->tpl->setVariable('PANEL_TXT_CAL_TYPE', $this->lng->txt('cal_cal_type'));
137 switch ($cat_info['type']) {
139 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_system'));
140 break;
141
143 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_personal'));
144 break;
145
147 $type = ilObject::_lookupType($cat_info['obj_id']);
148 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_type_' . $type));
149
150 // Course group appointment registration
151 if ($this->settings->isCGRegistrationEnabled() and $type == 'crs' or $type == 'grp') {
152 if (!$a_app['event']->isAutoGenerated()) {
153 $reg = new ilCalendarRegistration($a_app['event']->getEntryId());
154
155 if ($reg->isRegistered(
156 $this->user->getId(),
157 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
158 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
159 )) {
160 $this->tpl->setCurrentBlock('panel_cancel_book_link');
161 $this->ctrl->setParameterByClass(
162 'ilcalendarappointmentgui',
163 'seed',
164 $this->getSeed()->get(IL_CAL_DATE)
165 );
166 $this->ctrl->setParameterByClass(
167 'ilcalendarappointmentgui',
168 'app_id',
169 $a_app['event']->getEntryId()
170 );
171 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
172 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
173
174 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_reg_unregister'));
175 $this->tpl->setVariable(
176 'PANEL_CANCELBOOK_HREF',
177 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmUnregister')
178 );
179 $this->tpl->parseCurrentBlock();
180 } else {
181 $this->tpl->setCurrentBlock('panel_book_link');
182 $this->ctrl->setParameterByClass(
183 'ilcalendarappointmentgui',
184 'seed',
185 $this->getSeed()->get(IL_CAL_DATE)
186 );
187 $this->ctrl->setParameterByClass(
188 'ilcalendarappointmentgui',
189 'app_id',
190 $a_app['event']->getEntryId()
191 );
192 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dstart', $a_app['dstart']);
193 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dend', $a_app['dend']);
194 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_reg_register'));
195 $this->tpl->setVariable(
196 'PANEL_BOOK_HREF',
197 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'confirmRegister')
198 );
199 $this->tpl->parseCurrentBlock();
200 }
201
202 $registrations = array();
203 foreach ($reg->getRegisteredUsers(
204 new ilDateTime($a_app['dstart'], IL_CAL_UNIX),
205 new ilDateTime($a_app['dend'], IL_CAL_UNIX)
206 ) as $usr_data) {
207 $usr_id = $usr_data;
208 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $usr_id);
209 $registrations[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
210 'ilconsultationhoursgui',
211 'showprofile'
212 ) . '">' . ilObjUser::_lookupFullname($usr_id);
213 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
214 }
215 if (count($registrations)) {
216 $this->tpl->setCurrentBlock('panel_current_booking');
217 $this->tpl->setVariable(
218 'PANEL_TXT_CURRENT_BOOKING',
219 $this->lng->txt('cal_reg_registered_users')
220 );
221 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $registrations));
222 $this->tpl->parseCurrentBlock();
223 }
224 }
225 }
226 break;
227
229 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_ch'));
230
231 $entry = new ilBookingEntry($a_app['event']->getContextId());
232
233 $is_owner = $entry->isOwner();
234 $user_entry = ($cat_info['obj_id'] == $this->user->getId());
235
236 if ($user_entry && !$is_owner) {
237 // find source calendar entry in owner calendar
239 $entry->getObjId(),
240 $a_app['event']->getContextId(),
241 $a_app['event']->getStart()
242 );
243 $ref_event = $apps[0];
244 } else {
245 $ref_event = $a_app['event']->getEntryId();
246 }
247
248 $this->tpl->setCurrentBlock('panel_booking_owner');
249 $this->tpl->setVariable('PANEL_TXT_BOOKING_OWNER', $this->lng->txt('cal_ch_booking_owner'));
250 $this->tpl->setVariable('PANEL_BOOKING_OWNER', ilObjUser::_lookupFullname($entry->getObjId()));
251 $this->tpl->parseCurrentBlock();
252
253 $this->tpl->setCurrentBlock('panel_max_booking');
254 $this->tpl->setVariable('PANEL_TXT_MAX_BOOKING', $this->lng->txt('cal_ch_num_bookings'));
255 $this->tpl->setVariable('PANEL_MAX_BOOKING', $entry->getNumberOfBookings());
256 $this->tpl->parseCurrentBlock();
257
258 if (!$is_owner) {
259 if ($entry->hasBooked($ref_event)) {
260 if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
261 $this->tpl->setCurrentBlock('panel_cancel_book_link');
262 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
263 $this->ctrl->setParameterByClass(
264 'ilcalendarappointmentgui',
265 'seed',
266 $this->getSeed()->get(IL_CAL_DATE)
267 );
268 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
269 $this->tpl->setVariable(
270 'PANEL_CANCELBOOK_HREF',
271 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
272 );
273 $this->tpl->parseCurrentBlock();
274 }
275 } #else if(!$entry->isBookedOut($ref_event))
276 elseif ($entry->isAppointmentBookableForUser($ref_event, $GLOBALS['DIC']['ilUser']->getId())) {
277 $this->tpl->setCurrentBlock('panel_book_link');
278 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
279 $this->ctrl->setParameterByClass(
280 'ilcalendarappointmentgui',
281 'seed',
282 $this->getSeed()->get(IL_CAL_DATE)
283 );
284 $this->tpl->setVariable('TXT_PANEL_BOOK', $this->lng->txt('cal_ch_book'));
285 $this->tpl->setVariable(
286 'PANEL_BOOK_HREF',
287 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book')
288 );
289 $this->tpl->parseCurrentBlock();
290 }
291
292 $this->tpl->setCurrentBlock('panel_current_booking');
293 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
294 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', $entry->getCurrentNumberOfBookings($ref_event));
295 $this->tpl->parseCurrentBlock();
296 } else {
297 $obj_ids = $entry->getTargetObjIds();
298 foreach ($obj_ids as $obj_id) {
299 $title = ilObject::_lookupTitle($obj_id);
300 $refs = ilObject::_getAllReferences($obj_id);
301 $this->tpl->setCurrentBlock('panel_booking_target_row');
302 $this->tpl->setVariable('PANEL_BOOKING_TARGET_TITLE', $title);
303 $this->tpl->setVariable('PANEL_BOOKING_TARGET', ilLink::_getLink(end($refs)));
304 $this->tpl->parseCurrentBlock();
305 }
306 if ($obj_ids) {
307 $this->tpl->setCurrentBlock('panel_booking_target');
308 $this->tpl->setVariable('PANEL_TXT_BOOKING_TARGET', $this->lng->txt('cal_ch_target_object'));
309 $this->tpl->parseCurrentBlock();
310 }
311
312 $link_users = true;
314 $link_users = false;
315 }
316
317 $bookings = array();
318 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', 1);
319 foreach ($entry->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) {
320 if ($link_users) {
321 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', $user_id);
322 $bookings[] = '<a href="' . $this->ctrl->getLinkTargetByClass(
323 'ilconsultationhoursgui',
324 'showprofile'
325 ) . '">' .
326 ilObjUser::_lookupFullname($user_id) . '</a>';
327 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'user', '');
328 } else {
329 $bookings[] = ilObjUser::_lookupFullname($user_id);
330 }
331 }
332 $this->ctrl->setParameterByClass('ilconsultationhoursgui', 'panel', '');
333 $this->tpl->setCurrentBlock('panel_current_booking');
334 $this->tpl->setVariable('PANEL_TXT_CURRENT_BOOKING', $this->lng->txt('cal_ch_current_bookings'));
335 $this->tpl->setVariable('PANEL_CURRENT_BOOKING', implode('<br />', $bookings));
336 $this->tpl->parseCurrentBlock();
337 }
338 break;
339
341 $this->tpl->setVariable('PANEL_CAL_TYPE', $this->lng->txt('cal_ch_booking'));
342
343 $this->tpl->setCurrentBlock('panel_cancel_book_link');
344 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
345 $this->ctrl->setParameterByClass(
346 'ilcalendarappointmentgui',
347 'seed',
348 $this->getSeed()->get(IL_CAL_DATE)
349 );
350 $this->tpl->setVariable('TXT_PANEL_CANCELBOOK', $this->lng->txt('cal_ch_cancel_booking'));
351 $this->tpl->setVariable(
352 'PANEL_CANCELBOOK_HREF',
353 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
354 );
355 $this->tpl->parseCurrentBlock();
356 break;
357 }
358
359 $this->tpl->setVariable('PANEL_TXT_CAL_NAME', $this->lng->txt('cal_calendar_name'));
360 $this->tpl->setVariable('PANEL_CAL_NAME', $cat_info['title']);
361
362 if ($cat_info['editable'] and !$a_app['event']->isAutoGenerated()) {
363 $this->tpl->setCurrentBlock('panel_edit_link');
364 $this->tpl->setVariable('TXT_PANEL_EDIT', $this->lng->txt('edit'));
365
366 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
367 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
368 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
369 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
370 $this->tpl->setVariable(
371 'PANEL_EDIT_HREF',
372 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askEdit')
373 );
374
375 $this->tpl->setCurrentBlock('panel_delete_link');
376 $this->tpl->setVariable('TXT_PANEL_DELETE', $this->lng->txt('delete'));
377
378 $this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
379 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'seed', $this->getSeed()->get(IL_CAL_DATE));
380 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
381 $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'dt', $a_app['dstart']);
382 $this->tpl->setVariable(
383 'PANEL_DELETE_HREF',
384 $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'askdelete')
385 );
386 $this->tpl->parseCurrentBlock();
387 }
388 if ($cat_info['type'] == ilCalendarCategory::TYPE_OBJ) {
389 $refs = ilObject::_getAllReferences($entry_obj_id);
390 $type = ilObject::_lookupType($entry_obj_id);
391 $title = ilObject::_lookupTitle($entry_obj_id) ?
392 ilObject::_lookupTitle($entry_obj_id) :
393 $this->lng->txt('obj_' . $type);
394
395 $href = ilLink::_getStaticLink(current($refs), ilObject::_lookupType($entry_obj_id));
396 $parent = $this->tree->getParentId(current($refs));
397 $parent_title = ilObject::_lookupTitle(ilObject::_lookupObjId($parent));
398 $this->tpl->setVariable('PANEL_TXT_LINK', $this->lng->txt('ext_link'));
399 $this->tpl->setVariable('PANEL_LINK_HREF', $href);
400 $this->tpl->setVariable('PANEL_LINK_NAME', $title);
401 $this->tpl->setVariable('PANEL_PARENT', $parent_title);
402 }
403
404 return $this->tpl->get();
405 }
406}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
const IL_CAL_DATE
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeClickable(string $a_text, bool $detectGotoLinks=false)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type