ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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['ilUser']->getId());
64  }
static _getInstanceByUserId($a_user_id)
get singleton instance
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
+ 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(), addAppointment(), and array.

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  }
Create styles array
The data for the language used.
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['ilUser']->getTimeZone());
134 
135  include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
136  $tzid_file = ilCalendarUtil::getZoneInfoFile($GLOBALS['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.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getZoneInfoFile($a_tz)
+ 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 299 of file class.ilCalendarExport.php.

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

Referenced by createVEVENT().

300  {
303  );
304 
305  if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) {
306  $this->writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH);
307  } else {
308  $refs = ilObject::_getAllReferences($cat->getObjId());
309 
310  include_once './Services/Link/classes/class.ilLink.php';
311  $this->writer->addLine(
312  'URL;VALUE=URI:' . ilLink::_getLink(current((array) $refs))
313  );
314  }
315  }
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.
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createRecurrences()

ilCalendarExport::createRecurrences (   $app)
protected

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

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

Referenced by createVEVENT().

276  {
277  global $ilUser;
278 
279  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
280  foreach (ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec) {
281  foreach (ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl) {
282  $this->writer->addLine($excl->toICal());
283  }
284  $this->writer->addLine($rec->toICal($ilUser->getId()));
285  }
286  }
static _getRecurrences($a_cal_id)
get all recurrences of an appointment
$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 $end, $ilUser, 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, time, and ilTimeZone\UTC.

Referenced by addAppointment().

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

97  {
98  return (array) $this->calendars;
99  }
Create styles array
The data for the language used.

◆ getExportString()

ilCalendarExport::getExportString ( )

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

290  {
291  return $this->writer->__toString();
292  }

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