ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 Create VEVENT entry 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

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.

References $GLOBALS, and ilCalendarUserSettings\_getInstanceByUserId().

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['DIC']['ilUser']->getId());
64  }
static _getInstanceByUserId($a_user_id)
get singleton instance
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

Member Function Documentation

◆ addAppointment()

ilCalendarExport::addAppointment (   $a_app_id)
protected

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

References createVEVENT(), and createVTODO().

Referenced by addAppointments(), and addCategories().

164  {
165  $app = new ilCalendarEntry($a_app_id);
166  if ($app->isMilestone()) {
167  $this->createVTODO($app);
168  } else {
169  $this->createVEVENT($app);
170  }
171  }
Model for a calendar entry.
createVEVENT($app)
Create VEVENT entry ilObjUser $ilUser.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAppointments()

ilCalendarExport::addAppointments ( )
protected

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

References addAppointment(), and getAppointments().

Referenced by export().

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

◆ addCategories()

ilCalendarExport::addCategories ( )
protected

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

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

Referenced by export().

148  {
149  foreach ($this->calendars as $category_id) {
150  foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($category_id)) as $app_id) {
151  $this->addAppointment($app_id);
152  }
153  }
154  }
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 127 of file class.ilCalendarExport.php.

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

Referenced by export().

128  {
129  if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
130  return;
131  }
132 
133  $this->writer->addLine('X-WR-TIMEZONE:' . $GLOBALS['DIC']['ilUser']->getTimeZone());
134 
135  include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
136  $tzid_file = ilCalendarUtil::getZoneInfoFile($GLOBALS['DIC']['ilUser']->getTimeZone());
137  if (!is_file($tzid_file)) {
138  $tzid_file = ilCalendarUtil::getZoneInfoFile('Europe/Berlin');
139  }
140  $reader = fopen($tzid_file, 'r');
141  while ($line = fgets($reader)) {
142  $line = str_replace("\n", '', $line);
143  $this->writer->addLine($line);
144  }
145  }
getUserSettings()
Get user settings.
static getZoneInfoFile($a_tz)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 304 of file class.ilCalendarExport.php.

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

Referenced by createVEVENT().

305  {
308  );
309 
310  if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) {
311  $this->writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH);
312  } else {
313  $refs = ilObject::_getAllReferences($cat->getObjId());
314 
315  include_once './Services/Link/classes/class.ilLink.php';
316  $this->writer->addLine(
317  'URL;VALUE=URI:' . ilLink::_getLink(current((array) $refs))
318  );
319  }
320  }
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 278 of file class.ilCalendarExport.php.

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

Referenced by createVEVENT().

279  {
280  global $DIC;
281 
282  $ilUser = $DIC['ilUser'];
283 
284  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
285  foreach (ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec) {
286  foreach (ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl) {
287  $this->writer->addLine($excl->toICal());
288  }
289  $this->writer->addLine($rec->toICal($ilUser->getId()));
290  }
291  }
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
static getExclusionDates($a_cal_id)
Read exclusion dates.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVEVENT()

ilCalendarExport::createVEVENT (   $app)
protected

Create VEVENT entry ilObjUser $ilUser.

Parameters
ilCalendarEntry$app

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

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

Referenced by addAppointment().

185  {
186  global $DIC;
187 
188  $ilUser = $DIC['ilUser'];
189 
190  if (!$app->getStart() instanceof ilDateTime) {
191  $this->logger->notice('Cannot create appointment for app_id: ' . $app->getEntryId());
192  return false;
193  }
194 
195  $this->writer->addLine('BEGIN:VEVENT');
196 
197  $now = new ilDateTime(time(), IL_CAL_UNIX);
198  $this->writer->addLine('DTSTAMP:' . $now->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC));
199 
200  $this->writer->addLine('UID:' . ilICalWriter::escapeText(
201  $app->getEntryId() . '_' . CLIENT_ID . '@' . ILIAS_HTTP_PATH
202  ));
203 
204 
205  $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
206  #$last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',$ilUser->getTimeZone());
207  $this->writer->addLine('LAST-MODIFIED:' . $last_mod);
208 
209  // begin-patch aptar
210  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
211  if ($rec = ilCalendarRecurrences::_getFirstRecurrence($app->getEntryId())) {
212  // Set starting time to first appointment that matches the recurrence rule
213  include_once './Services/Calendar/classes/class.ilCalendarRecurrenceCalculator.php';
214  $calc = new ilCalendarRecurrenceCalculator($app, $rec);
215 
216  $pStart = $app->getStart();
217  $pEnd = clone $app->getStart();
218  $pEnd->increment(IL_CAL_YEAR, 5);
219  $appDiff = $app->getEnd()->get(IL_CAL_UNIX) - $app->getStart()->get(IL_CAL_UNIX);
220  $recs = $calc->calculateDateList($pStart, $pEnd);
221 
222  // defaults
223  $startInit = $app->getStart();
224  $endInit = $app->getEnd();
225  foreach ($recs as $dt) {
226  $startInit = $dt;
227  $endInit = clone($dt);
228  $endInit->setDate($startInit->get(IL_CAL_UNIX) + $appDiff, IL_CAL_UNIX);
229  break;
230  }
231  } else {
232  $startInit = $app->getStart();
233  $endInit = $app->getEnd();
234  }
235 
236 
237  if ($app->isFullday()) {
238  // According to RFC 5545 3.6.1 DTEND is not inclusive.
239  // But ILIAS stores inclusive dates in the database.
240  $endInit->increment(IL_CAL_DAY, 1);
241 
242  $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd', $ilUser->getTimeZone());
243  $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd', $ilUser->getTimeZone());
244 
245  $this->writer->addLine('DTSTART;VALUE=DATE:' . $start);
246  $this->writer->addLine('DTEND;VALUE=DATE:' . $end);
247  } else {
248  if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
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  } else {
254  $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $ilUser->getTimeZone());
255  $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $ilUser->getTimeZone());
256  $this->writer->addLine('DTSTART;TZID=' . $ilUser->getTimezone() . ':' . $start);
257  $this->writer->addLine('DTEND;TZID=' . $ilUser->getTimezone() . ':' . $end);
258  }
259  }
260  // end-patch aptar
261 
262  $this->createRecurrences($app);
263 
264  $this->writer->addLine('SUMMARY:' . ilICalWriter::escapeText($app->getPresentationTitle(false)));
265  if (strlen($app->getDescription())) {
266  $this->writer->addLine('DESCRIPTION:' . ilICalWriter::escapeText($app->getDescription()));
267  }
268  if (strlen($app->getLocation())) {
269  $this->writer->addLine('LOCATION:' . ilICalWriter::escapeText($app->getLocation()));
270  }
271 
272  // TODO: URL
273  $this->buildAppointmentUrl($app);
274 
275  $this->writer->addLine('END:VEVENT');
276  }
getUserSettings()
Get user settings.
global $DIC
Definition: saml.php:7
static _getFirstRecurrence($a_cal_id)
get first recurrence
const IL_CAL_UNIX
$start
Definition: bench.php:8
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
Date and time handling
$ilUser
Definition: imgupload.php:18
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 173 of file class.ilCalendarExport.php.

Referenced by addAppointment().

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

◆ export()

ilCalendarExport::export ( )

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

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

Referenced by ilCalendarRemoteAccessHandler\handleRequest().

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  case self::EXPORT_CALENDARS:
117  $this->addCategories();
118  break;
119 
120  case self::EXPORT_APPOINTMENTS:
121  $this->addAppointments();
122  break;
123  }
124  $this->writer->addLine('END:VCALENDAR');
125  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppointments()

ilCalendarExport::getAppointments ( )

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

References $appointments.

Referenced by addAppointments().

87  {
88  return $this->appointments;
89  }
+ Here is the caller graph for this function:

◆ getCalendarIds()

ilCalendarExport::getCalendarIds ( )

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

References $calendars.

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

◆ getExportString()

ilCalendarExport::getExportString ( )

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

295  {
296  return $this->writer->__toString();
297  }

◆ getExportType()

ilCalendarExport::getExportType ( )

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

References $export_type.

Referenced by export().

102  {
103  return $this->export_type;
104  }
+ 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().

71  {
72  return $this->user_settings;
73  }
+ 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.

References $a_type.

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

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

◆ 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: