ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
ilCalendarExport Class Reference

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)
 
 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
 

Detailed Description

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 50 of file class.ilCalendarExport.php.

References $GLOBALS, and ilCalendarUserSettings\_getInstanceByUserId().

51  {
52  $this->calendars = $a_calendar_ids;
53  $this->writer = new ilICalWriter();
54 
55  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($GLOBALS['ilUser']->getId());
56  }
static _getInstanceByUserId($a_user_id)
get singleton instance
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:

Member Function Documentation

◆ addAppointment()

ilCalendarExport::addAppointment (   $a_app_id)
protected

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

References createVEVENT(), and createVTODO().

Referenced by addAppointments(), and addCategories().

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  }
Model for a calendar entry.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAppointments()

ilCalendarExport::addAppointments ( )
protected

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

References addAppointment(), and getAppointments().

Referenced by export().

155  {
156  foreach($this->getAppointments() as $app)
157  {
158  $this->addAppointment($app);
159  }
160  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCategories()

ilCalendarExport::addCategories ( )
protected

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

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

Referenced by export().

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  }
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTimezone()

ilCalendarExport::addTimezone ( )
protected

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

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

Referenced by export().

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  }
getUserSettings()
Get user settings.
static getZoneInfoFile($a_tz)
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ 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 306 of file class.ilCalendarExport.php.

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

Referenced by createVEVENT().

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  }
getEntryId()
get entry id
static _lookupCategories($a_cal_id)
lookup categories
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createRecurrences()

ilCalendarExport::createRecurrences (   $app)
protected

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

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

Referenced by createVEVENT().

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  }
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
static getExclusionDates($a_cal_id)
Read exclusion dates.
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVEVENT()

ilCalendarExport::createVEVENT (   $app)
protected

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

References $ilUser, 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().

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  }
getUserSettings()
Get user settings.
static _getFirstRecurrence($a_cal_id)
get first recurrence
const IL_CAL_UNIX
const IL_CAL_DAY
Calculates an ilDateList for a given calendar entry and recurrence rule.
buildAppointmentUrl(ilCalendarEntry $entry)
Build url from calendar entry.
const IL_CAL_FKT_DATE
const IL_CAL_DATE
global $ilUser
Definition: imgupload.php:15
static escapeText($a_text)
const IL_CAL_YEAR
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVTODO()

ilCalendarExport::createVTODO (   $app)
protected

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

Referenced by addAppointment().

176  {
177  // TODO
178  return true;
179  }
+ Here is the caller graph for this function:

◆ export()

ilCalendarExport::export ( )

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

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

Referenced by ilCalendarRemoteAccessHandler\handleRequest().

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  {
109  case self::EXPORT_CALENDARS:
110  $this->addCategories();
111  break;
112 
113  case self::EXPORT_APPOINTMENTS:
114  $this->addAppointments();
115  break;
116  }
117  $this->writer->addLine('END:VCALENDAR');
118  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppointments()

ilCalendarExport::getAppointments ( )

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

References $appointments.

Referenced by addAppointments().

79  {
80  return $this->appointments;
81  }
+ Here is the caller graph for this function:

◆ getCalendarIds()

ilCalendarExport::getCalendarIds ( )

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

References $calendars.

89  {
90  return (array) $this->calendars;
91  }

◆ getExportString()

ilCalendarExport::getExportString ( )

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

297  {
298  return $this->writer->__toString();
299  }

◆ getExportType()

ilCalendarExport::getExportType ( )

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

References $export_type.

Referenced by export().

94  {
95  return $this->export_type;
96  }
+ Here is the caller graph for this function:

◆ getUserSettings()

ilCalendarExport::getUserSettings ( )

Get user settings.

Returns
ilCalendarUserSettings

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

References $user_settings.

Referenced by addTimezone(), and createVEVENT().

63  {
64  return $this->user_settings;
65  }
+ Here is the caller graph for this function:

◆ setAppointments()

ilCalendarExport::setAppointments (   $a_apps)

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

74  {
75  $this->appointments = $a_apps;
76  }

◆ setCalendarIds()

ilCalendarExport::setCalendarIds (   $a_cal_ids)

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

84  {
85  $this->calendars = $a_cal_ids;
86  }

◆ setExportType()

ilCalendarExport::setExportType (   $a_type)

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

69  {
70  $this->export_type = $a_type;
71  }

Field Documentation

◆ $appointments

ilCalendarExport::$appointments = array()
protected

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

Referenced by getAppointments().

◆ $calendars

ilCalendarExport::$calendars = array()
protected

Definition at line 45 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().

◆ $user_settings

ilCalendarExport::$user_settings = NULL
protected

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

Referenced by getUserSettings().

◆ $writer

ilCalendarExport::$writer = null
protected

Definition at line 48 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().

◆ EXPORT_CALENDARS

const ilCalendarExport::EXPORT_CALENDARS = 1

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


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