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