ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCalendarExport.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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.ilCalendarUserSettings.php';
25include_once './Services/Calendar/classes/iCal/class.ilICalWriter.php';
26include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
27include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
28include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
29
38{
41
43
44
45 protected $calendars = array();
46 protected $user_settings = NULL;
47 protected $appointments = array();
48 protected $writer = null;
49
50 public function __construct($a_calendar_ids = array())
51 {
52 $this->calendars = $a_calendar_ids;
53 $this->writer = new ilICalWriter();
54
55 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($GLOBALS['ilUser']->getId());
56 }
57
62 public function getUserSettings()
63 {
65 }
66
67
68 public function setExportType($a_type)
69 {
70 $this->export_type = $a_type;
71 }
72
73 public function setAppointments($a_apps)
74 {
75 $this->appointments = $a_apps;
76 }
77
78 public function getAppointments()
79 {
81 }
82
83 public function setCalendarIds($a_cal_ids)
84 {
85 $this->calendars = $a_cal_ids;
86 }
87
88 public function getCalendarIds()
89 {
90 return (array) $this->calendars;
91 }
92
93 public function getExportType()
94 {
95 return $this->export_type;
96 }
97
98 public function export()
99 {
100 $this->writer->addLine('BEGIN:VCALENDAR');
101 $this->writer->addLine('VERSION:2.0');
102 $this->writer->addLine('METHOD:PUBLISH');
103 $this->writer->addLine('PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
104
105 $this->addTimezone();
106
107 switch($this->getExportType())
108 {
110 $this->addCategories();
111 break;
112
114 $this->addAppointments();
115 break;
116 }
117 $this->writer->addLine('END:VCALENDAR');
118 }
119
120 protected function addTimezone()
121 {
122 if($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC)
123 {
124 return;
125 }
126
127 $this->writer->addLine('X-WR-TIMEZONE:'.$GLOBALS['ilUser']->getTimeZone());
128
129 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
130 $tzid_file = ilCalendarUtil::getZoneInfoFile($GLOBALS['ilUser']->getTimeZone());
131 if(!is_file($tzid_file))
132 {
133 $tzid_file = ilCalendarUtil::getZoneInfoFile('Europe/Berlin');
134 }
135 $reader = fopen($tzid_file,'r');
136 while($line = fgets($reader))
137 {
138 $line = str_replace("\n", '', $line);
139 $this->writer->addLine($line);
140 }
141 }
142
143 protected function addCategories()
144 {
145 foreach($this->calendars as $category_id)
146 {
147 foreach(ilCalendarCategoryAssignments::_getAssignedAppointments(array($category_id)) as $app_id)
148 {
149 $this->addAppointment($app_id);
150 }
151 }
152 }
153
154 protected function addAppointments()
155 {
156 foreach($this->getAppointments() as $app)
157 {
158 $this->addAppointment($app);
159 }
160 }
161
162 protected function addAppointment($a_app_id)
163 {
164 $app = new ilCalendarEntry($a_app_id);
165 if($app->isMilestone())
166 {
167 $this->createVTODO($app);
168 }
169 else
170 {
171 $this->createVEVENT($app);
172 }
173 }
174
175 protected function createVTODO($app)
176 {
177 // TODO
178 return true;
179 }
180
181 protected function createVEVENT($app)
182 {
183 global $ilUser;
184
185 $this->writer->addLine('BEGIN:VEVENT');
186 // TODO only domain
187 $this->writer->addLine('UID:'.ilICalWriter::escapeText(
188 $app->getEntryId().'_'.CLIENT_ID.'@'.ILIAS_HTTP_PATH));
189
190 $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
191 #$last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',$ilUser->getTimeZone());
192 $this->writer->addLine('LAST-MODIFIED:'.$last_mod);
193
194 // begin-patch aptar
195 include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
196 if($rec = ilCalendarRecurrences::_getFirstRecurrence($app->getEntryId()))
197 {
198 // Set starting time to first appointment that matches the recurrence rule
199 include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
200 $calc = new ilCalendarRecurrenceCalculator($app,$rec);
201
202 $pStart = $app->getStart();
203 $pEnd = clone $app->getStart();
204 $pEnd->increment(IL_CAL_YEAR,5);
205 $appDiff = $app->getEnd()->get(IL_CAL_UNIX) - $app->getStart()->get(IL_CAL_UNIX);
206 $recs = $calc->calculateDateList($pStart, $pEnd);
207
208 // defaults
209 $startInit = $app->getStart();
210 $endInit = $app->getEnd();
211 foreach($recs as $dt)
212 {
213 $startInit = $dt;
214 $endInit = clone($dt);
215 $endInit->setDate($startInit->get(IL_CAL_UNIX) + $appDiff,IL_CAL_UNIX);
216 break;
217 }
218
219 }
220 else
221 {
222 $startInit = $app->getStart();
223 $endInit = $app->getEnd();
224 }
225
226
227 if($app->isFullday())
228 {
229 // According to RFC 5545 3.6.1 DTEND is not inklusive.
230 // But ILIAS stores inklusive dates in the database.
231 #$app->getEnd()->increment(IL_CAL_DAY,1);
232 $endInit->increment(IL_CAL_DATE,1);
233
234 #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
235 #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
236 $start = $startInit->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
237 #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
238 #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
239 $endInit->increment(IL_CAL_DAY,1);
240 $end = $endInit->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
241
242 $this->writer->addLine('DTSTART;VALUE=DATE:' . $start);
243 $this->writer->addLine('DTEND;VALUE=DATE:'.$end);
244 }
245 else
246 {
247 if($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC)
248 {
249 $start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
250 $end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
251 $this->writer->addLine('DTSTART:'. $start);
252 $this->writer->addLine('DTEND:'.$end);
253
254 }
255 else
256 {
257 $start = $startInit->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
258 $end = $endInit->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
259 $this->writer->addLine('DTSTART;TZID='.$ilUser->getTimezone().':'. $start);
260 $this->writer->addLine('DTEND;TZID='.$ilUser->getTimezone().':'.$end);
261 }
262 }
263 // end-patch aptar
264
265 $this->createRecurrences($app);
266
267 $this->writer->addLine('SUMMARY:'.ilICalWriter::escapeText($app->getPresentationTitle(false)));
268 if(strlen($app->getDescription()))
269 $this->writer->addLine('DESCRIPTION:'.ilICalWriter::escapeText($app->getDescription()));
270 if(strlen($app->getLocation()))
271 $this->writer->addLine('LOCATION:'.ilICalWriter::escapeText($app->getLocation()));
272
273 // TODO: URL
274 $this->buildAppointmentUrl($app);
275
276 $this->writer->addLine('END:VEVENT');
277
278 }
279
280 protected function createRecurrences($app)
281 {
282 global $ilUser;
283
284 include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
285 foreach(ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec)
286 {
287 foreach(ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl)
288 {
289 $this->writer->addLine($excl->toICal());
290 }
291 $this->writer->addLine($rec->toICal($ilUser->getId()));
292 }
293 }
294
295
296 public function getExportString()
297 {
298 return $this->writer->__toString();
299 }
300
306 protected function buildAppointmentUrl(ilCalendarEntry $entry)
307 {
310 );
311
312 if($cat->getType() != ilCalendarCategory::TYPE_OBJ)
313 {
314 $this->writer->addLine('URL;VALUE=URI:'.ILIAS_HTTP_PATH);
315 }
316 else
317 {
318 $refs = ilObject::_getAllReferences($cat->getObjId());
319
320 include_once './Services/Link/classes/class.ilLink.php';
321 $this->writer->addLine(
322 'URL;VALUE=URI:'.ilLink::_getLink(current((array) $refs))
323 );
324 }
325 }
326}
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_YEAR
const IL_CAL_FKT_DATE
const IL_CAL_DAY
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
static _lookupCategories($a_cal_id)
lookup categories
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
Model for a calendar entry.
getEntryId()
get entry id
@classDescription Export calendar(s) to ical format
__construct($a_calendar_ids=array())
buildAppointmentUrl(ilCalendarEntry $entry)
Build url from calendar entry.
getUserSettings()
Get user settings.
Calculates an ilDateList for a given calendar entry and recurrence rule.
static getExclusionDates($a_cal_id)
Read exclusion dates.
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
static _getFirstRecurrence($a_cal_id)
get first recurrence
static _getInstanceByUserId($a_user_id)
get singleton instance
static getZoneInfoFile($a_tz)
static escapeText($a_text)
static _getAllReferences($a_id)
get all reference ids of object
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilUser
Definition: imgupload.php:15