ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilCalendarExport Class Reference

@classDescription Export calendar(s) to ical format More...

+ Collaboration diagram for ilCalendarExport:

Public Member Functions

 __construct ($a_calendar_ids=array())
 
 getUserSettings ()
 Get user settings. More...
 
 setExportType ($a_type)
 
 setAppointments ($a_apps)
 
 getAppointments ()
 
 setCalendarIds ($a_cal_ids)
 
 getCalendarIds ()
 
 getExportType ()
 
 export ()
 
 getExportString ()
 

Data Fields

const EXPORT_CALENDARS = 1
 
const EXPORT_APPOINTMENTS = 2
 

Protected Member Functions

 addTimezone ()
 
 addCategories ()
 
 addAppointments ()
 
 addAppointment ($a_app_id)
 
 createVTODO ($app)
 
 createVEVENT ($app)
 Create VEVENT entry @global ilObjUser $ilUser. More...
 
 createRecurrences ($app)
 
 buildAppointmentUrl (ilCalendarEntry $entry)
 Build url from calendar entry. More...
 

Protected Attributes

 $export_type = self::EXPORT_CALENDARS
 
 $calendars = array()
 
 $user_settings = NULL
 
 $appointments = array()
 
 $writer = null
 

Private Attributes

 $logger = null
 

Detailed Description

@classDescription Export calendar(s) to ical format

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 37 of file class.ilCalendarExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilCalendarExport::__construct (   $a_calendar_ids = array())

Definition at line 55 of file class.ilCalendarExport.php.

56 {
57 $this->logger = $GLOBALS['DIC']->logger()->cal();
58
59
60 $this->calendars = $a_calendar_ids;
61 $this->writer = new ilICalWriter();
62
63 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($GLOBALS['ilUser']->getId());
64 }
static _getInstanceByUserId($a_user_id)
get singleton instance
$GLOBALS['loaded']
Global hash that tracks already loaded includes.

References $GLOBALS, and ilCalendarUserSettings\_getInstanceByUserId().

+ Here is the call graph for this function:

Member Function Documentation

◆ addAppointment()

ilCalendarExport::addAppointment (   $a_app_id)
protected

Definition at line 170 of file class.ilCalendarExport.php.

171 {
172 $app = new ilCalendarEntry($a_app_id);
173 if($app->isMilestone())
174 {
175 $this->createVTODO($app);
176 }
177 else
178 {
179 $this->createVEVENT($app);
180 }
181 }
Model for a calendar entry.
createVEVENT($app)
Create VEVENT entry @global ilObjUser $ilUser.

References createVEVENT(), and createVTODO().

Referenced by addAppointments(), and addCategories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAppointments()

ilCalendarExport::addAppointments ( )
protected

Definition at line 162 of file class.ilCalendarExport.php.

163 {
164 foreach($this->getAppointments() as $app)
165 {
166 $this->addAppointment($app);
167 }
168 }

References addAppointment(), and getAppointments().

Referenced by export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCategories()

ilCalendarExport::addCategories ( )
protected

Definition at line 151 of file class.ilCalendarExport.php.

152 {
153 foreach($this->calendars as $category_id)
154 {
155 foreach(ilCalendarCategoryAssignments::_getAssignedAppointments(array($category_id)) as $app_id)
156 {
157 $this->addAppointment($app_id);
158 }
159 }
160 }
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.

References ilCalendarCategoryAssignments\_getAssignedAppointments(), and addAppointment().

Referenced by export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTimezone()

ilCalendarExport::addTimezone ( )
protected

Definition at line 128 of file class.ilCalendarExport.php.

129 {
130 if($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC)
131 {
132 return;
133 }
134
135 $this->writer->addLine('X-WR-TIMEZONE:'.$GLOBALS['ilUser']->getTimeZone());
136
137 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
138 $tzid_file = ilCalendarUtil::getZoneInfoFile($GLOBALS['ilUser']->getTimeZone());
139 if(!is_file($tzid_file))
140 {
141 $tzid_file = ilCalendarUtil::getZoneInfoFile('Europe/Berlin');
142 }
143 $reader = fopen($tzid_file,'r');
144 while($line = fgets($reader))
145 {
146 $line = str_replace("\n", '', $line);
147 $this->writer->addLine($line);
148 }
149 }
getUserSettings()
Get user settings.
static getZoneInfoFile($a_tz)

References $GLOBALS, $reader, ilCalendarUserSettings\CAL_EXPORT_TZ_UTC, getUserSettings(), and ilCalendarUtil\getZoneInfoFile().

Referenced by export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildAppointmentUrl()

ilCalendarExport::buildAppointmentUrl ( ilCalendarEntry  $entry)
protected

Build url from calendar entry.

Parameters
ilCalendarEntry$entry
Returns
string

Definition at line 328 of file class.ilCalendarExport.php.

329 {
332 );
333
334 if($cat->getType() != ilCalendarCategory::TYPE_OBJ)
335 {
336 $this->writer->addLine('URL;VALUE=URI:'.ILIAS_HTTP_PATH);
337 }
338 else
339 {
340 $refs = ilObject::_getAllReferences($cat->getObjId());
341
342 include_once './Services/Link/classes/class.ilLink.php';
343 $this->writer->addLine(
344 'URL;VALUE=URI:'.ilLink::_getLink(current((array) $refs))
345 );
346 }
347 }
static _lookupCategories($a_cal_id)
lookup categories
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
getEntryId()
get entry id
static _getAllReferences($a_id)
get all reference ids of object

References ilObject\_getAllReferences(), ilLink\_getLink(), ilCalendarCategoryAssignments\_lookupCategories(), ilCalendarEntry\getEntryId(), ilCalendarCategory\getInstanceByCategoryId(), and ilCalendarCategory\TYPE_OBJ.

Referenced by createVEVENT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createRecurrences()

ilCalendarExport::createRecurrences (   $app)
protected

Definition at line 302 of file class.ilCalendarExport.php.

303 {
304 global $ilUser;
305
306 include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
307 foreach(ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec)
308 {
309 foreach(ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl)
310 {
311 $this->writer->addLine($excl->toICal());
312 }
313 $this->writer->addLine($rec->toICal($ilUser->getId()));
314 }
315 }
static getExclusionDates($a_cal_id)
Read exclusion dates.
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
$ilUser
Definition: imgupload.php:18

References $ilUser, ilCalendarRecurrences\_getRecurrences(), and ilCalendarRecurrenceExclusions\getExclusionDates().

Referenced by createVEVENT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVEVENT()

ilCalendarExport::createVEVENT (   $app)
protected

Create VEVENT entry @global ilObjUser $ilUser.

Parameters
ilCalendarEntry$app

Definition at line 194 of file class.ilCalendarExport.php.

195 {
196 global $ilUser;
197
198 if(!$app->getStart() instanceof ilDateTime)
199 {
200 $this->logger->notice('Cannot create appointment for app_id: ' . $app->getEntryId());
201 }
202
203 $this->writer->addLine('BEGIN:VEVENT');
204
205 $now = new ilDateTime(time(), IL_CAL_UNIX);
206 $this->writer->addLine('DTSTAMP:'.$now->get(IL_CAL_FKT_DATE,'Ymd\THis\Z', ilTimeZone::UTC));
207
208 $this->writer->addLine('UID:'.ilICalWriter::escapeText(
209 $app->getEntryId().'_'.CLIENT_ID.'@'.ILIAS_HTTP_PATH));
210
211
212 $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
213 #$last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',$ilUser->getTimeZone());
214 $this->writer->addLine('LAST-MODIFIED:'.$last_mod);
215
216 // begin-patch aptar
217 include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
218 if($rec = ilCalendarRecurrences::_getFirstRecurrence($app->getEntryId()))
219 {
220 // Set starting time to first appointment that matches the recurrence rule
221 include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
222 $calc = new ilCalendarRecurrenceCalculator($app,$rec);
223
224 $pStart = $app->getStart();
225 $pEnd = clone $app->getStart();
226 $pEnd->increment(IL_CAL_YEAR,5);
227 $appDiff = $app->getEnd()->get(IL_CAL_UNIX) - $app->getStart()->get(IL_CAL_UNIX);
228 $recs = $calc->calculateDateList($pStart, $pEnd);
229
230 // defaults
231 $startInit = $app->getStart();
232 $endInit = $app->getEnd();
233 foreach($recs as $dt)
234 {
235 $startInit = $dt;
236 $endInit = clone($dt);
237 $endInit->setDate($startInit->get(IL_CAL_UNIX) + $appDiff,IL_CAL_UNIX);
238 break;
239 }
240
241 }
242 else
243 {
244 $startInit = $app->getStart();
245 $endInit = $app->getEnd();
246 }
247
248
249 if($app->isFullday())
250 {
251 // According to RFC 5545 3.6.1 DTEND is not inklusive.
252 // But ILIAS stores inklusive dates in the database.
253 #$app->getEnd()->increment(IL_CAL_DAY,1);
254 $endInit->increment(IL_CAL_DATE,1);
255
256 #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
257 #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
258 $start = $startInit->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
259 #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
260 #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
261 $endInit->increment(IL_CAL_DAY,1);
262 $end = $endInit->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
263
264 $this->writer->addLine('DTSTART;VALUE=DATE:' . $start);
265 $this->writer->addLine('DTEND;VALUE=DATE:'.$end);
266 }
267 else
268 {
269 if($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC)
270 {
271 $start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
272 $end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
273 $this->writer->addLine('DTSTART:'. $start);
274 $this->writer->addLine('DTEND:'.$end);
275
276 }
277 else
278 {
279 $start = $startInit->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
280 $end = $endInit->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
281 $this->writer->addLine('DTSTART;TZID='.$ilUser->getTimezone().':'. $start);
282 $this->writer->addLine('DTEND;TZID='.$ilUser->getTimezone().':'.$end);
283 }
284 }
285 // end-patch aptar
286
287 $this->createRecurrences($app);
288
289 $this->writer->addLine('SUMMARY:'.ilICalWriter::escapeText($app->getPresentationTitle(false)));
290 if(strlen($app->getDescription()))
291 $this->writer->addLine('DESCRIPTION:'.ilICalWriter::escapeText($app->getDescription()));
292 if(strlen($app->getLocation()))
293 $this->writer->addLine('LOCATION:'.ilICalWriter::escapeText($app->getLocation()));
294
295 // TODO: URL
296 $this->buildAppointmentUrl($app);
297
298 $this->writer->addLine('END:VEVENT');
299
300 }
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_YEAR
const IL_CAL_FKT_DATE
const IL_CAL_DAY
buildAppointmentUrl(ilCalendarEntry $entry)
Build url from calendar entry.
Calculates an ilDateList for a given calendar entry and recurrence rule.
static _getFirstRecurrence($a_cal_id)
get first recurrence
@classDescription Date and time handling
static escapeText($a_text)

References $ilUser, $start, ilCalendarRecurrences\_getFirstRecurrence(), buildAppointmentUrl(), ilCalendarUserSettings\CAL_EXPORT_TZ_UTC, createRecurrences(), ilICalWriter\escapeText(), getUserSettings(), IL_CAL_DATE, IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_UNIX, IL_CAL_YEAR, and ilTimeZone\UTC.

Referenced by addAppointment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVTODO()

ilCalendarExport::createVTODO (   $app)
protected

Definition at line 183 of file class.ilCalendarExport.php.

184 {
185 // TODO
186 return true;
187 }

Referenced by addAppointment().

+ Here is the caller graph for this function:

◆ export()

ilCalendarExport::export ( )

Definition at line 106 of file class.ilCalendarExport.php.

107 {
108 $this->writer->addLine('BEGIN:VCALENDAR');
109 $this->writer->addLine('VERSION:2.0');
110 $this->writer->addLine('METHOD:PUBLISH');
111 $this->writer->addLine('PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
112
113 $this->addTimezone();
114
115 switch($this->getExportType())
116 {
118 $this->addCategories();
119 break;
120
122 $this->addAppointments();
123 break;
124 }
125 $this->writer->addLine('END:VCALENDAR');
126 }

References addAppointments(), addCategories(), addTimezone(), EXPORT_APPOINTMENTS, EXPORT_CALENDARS, and getExportType().

+ Here is the call graph for this function:

◆ getAppointments()

ilCalendarExport::getAppointments ( )

Definition at line 86 of file class.ilCalendarExport.php.

References $appointments.

Referenced by addAppointments().

+ Here is the caller graph for this function:

◆ getCalendarIds()

ilCalendarExport::getCalendarIds ( )

Definition at line 96 of file class.ilCalendarExport.php.

97 {
98 return (array) $this->calendars;
99 }

References $calendars.

◆ getExportString()

ilCalendarExport::getExportString ( )

Definition at line 318 of file class.ilCalendarExport.php.

319 {
320 return $this->writer->__toString();
321 }

◆ getExportType()

ilCalendarExport::getExportType ( )

Definition at line 101 of file class.ilCalendarExport.php.

102 {
103 return $this->export_type;
104 }

References $export_type.

Referenced by export().

+ Here is the caller graph for this function:

◆ getUserSettings()

ilCalendarExport::getUserSettings ( )

Get user settings.

Returns
ilCalendarUserSettings

Definition at line 70 of file class.ilCalendarExport.php.

References $user_settings.

Referenced by addTimezone(), and createVEVENT().

+ Here is the caller graph for this function:

◆ setAppointments()

ilCalendarExport::setAppointments (   $a_apps)

Definition at line 81 of file class.ilCalendarExport.php.

82 {
83 $this->appointments = $a_apps;
84 }

◆ setCalendarIds()

ilCalendarExport::setCalendarIds (   $a_cal_ids)

Definition at line 91 of file class.ilCalendarExport.php.

92 {
93 $this->calendars = $a_cal_ids;
94 }

◆ setExportType()

ilCalendarExport::setExportType (   $a_type)

Definition at line 76 of file class.ilCalendarExport.php.

77 {
78 $this->export_type = $a_type;
79 }
$a_type
Definition: workflow.php:93

References $a_type.

Field Documentation

◆ $appointments

ilCalendarExport::$appointments = array()
protected

Definition at line 52 of file class.ilCalendarExport.php.

Referenced by getAppointments().

◆ $calendars

ilCalendarExport::$calendars = array()
protected

Definition at line 50 of file class.ilCalendarExport.php.

Referenced by getCalendarIds().

◆ $export_type

ilCalendarExport::$export_type = self::EXPORT_CALENDARS
protected

Definition at line 42 of file class.ilCalendarExport.php.

Referenced by getExportType().

◆ $logger

ilCalendarExport::$logger = null
private

Definition at line 47 of file class.ilCalendarExport.php.

◆ $user_settings

ilCalendarExport::$user_settings = NULL
protected

Definition at line 51 of file class.ilCalendarExport.php.

Referenced by getUserSettings().

◆ $writer

ilCalendarExport::$writer = null
protected

Definition at line 53 of file class.ilCalendarExport.php.

◆ EXPORT_APPOINTMENTS

const ilCalendarExport::EXPORT_APPOINTMENTS = 2

Definition at line 40 of file class.ilCalendarExport.php.

Referenced by ilCalendarMailNotification\addAttachment(), and export().

◆ EXPORT_CALENDARS

const ilCalendarExport::EXPORT_CALENDARS = 1

Definition at line 39 of file class.ilCalendarExport.php.

Referenced by export().


The documentation for this class was generated from the following file: