ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCalendarExport Class Reference

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

+ Collaboration diagram for ilCalendarExport:

Public Member Functions

 __construct (array $a_calendar_ids=[], bool $is_export_limited=false)
 
 getUserSettings ()
 
 setAppointments (array $a_apps)
 
 getAppointments ()
 
 setCalendarIds (array $a_cal_ids)
 
 getCalendarIds ()
 
 setExportType (int $a_type)
 
 getExportType ()
 
 export ()
 
 getExportString ()
 

Data Fields

const EXPORT_CALENDARS = 1
 
const EXPORT_APPOINTMENTS = 2
 

Protected Member Functions

 createTimezones ()
 
 addCategories (int $remaining_bytes)
 
 isRepeatingAppointment (ilCalendarEntry $appointment)
 
 addAppointments ()
 
 createAppointment (ilCalendarEntry $appointment)
 
 createVTODO (ilCalendarEntry $app)
 
 createVEVENT (ilCalendarEntry $app)
 
 createRecurrences (ilCalendarEntry $app)
 
 buildAppointmentUrl (ilCalendarEntry $entry)
 

Protected Attributes

const BYTE_LIMIT = 1000000
 
int $export_type = self::EXPORT_CALENDARS
 
ilObjUser $il_user
 
array $calendars = array()
 
ilCalendarUserSettings $user_settings
 
array $appointments = array()
 
ilICalWriter $writer
 
ilICalWriter $str_writer_export
 
bool $is_export_limited
 

Private Attributes

ilLogger $logger
 

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

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

Constructor & Destructor Documentation

◆ __construct()

ilCalendarExport::__construct ( array  $a_calendar_ids = [],
bool  $is_export_limited = false 
)
Parameters
int[]$a_calendar_ids

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

References $DIC, $is_export_limited, ilCalendarUserSettings\_getInstanceByUserId(), and ILIAS\Repository\logger().

54  {
55  global $DIC;
56  $this->il_user = $DIC->user();
57  $this->logger = $DIC->logger()->cal();
58  $this->calendars = $a_calendar_ids;
59  $this->is_export_limited = $is_export_limited;
60  $this->appointments = [];
61  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->il_user->getId());
62  $this->str_writer_export = new ilICalWriter();
63  }
static _getInstanceByUserId(int $a_user_id)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addAppointments()

ilCalendarExport::addAppointments ( )
protected

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

References $app, createAppointment(), and getAppointments().

Referenced by export().

219  : ilICalWriter
220  {
221  $str_builder_appointments = new ilICalWriter();
222  foreach ($this->getAppointments() as $app) {
223  $str_writer_appointment = $this->createAppointment(new ilCalendarEntry($app));
224  $str_builder_appointments->append($str_writer_appointment);
225  }
226  return $str_builder_appointments;
227  }
$app
Definition: cli.php:39
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createAppointment(ilCalendarEntry $appointment)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addCategories()

ilCalendarExport::addCategories ( int  $remaining_bytes)
protected

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

References Vendor\Package\$a, Vendor\Package\$b, ilCalendarCategoryAssignments\_getAssignedAppointments(), createAppointment(), ilCalendarEntry\getStart(), IL_CAL_FKT_DATE, IL_CAL_UNIX, isRepeatingAppointment(), and ilTimeZone\UTC.

Referenced by export().

159  : ilICalWriter
160  {
161  $single_appointments = [];
162  $str_writer_appointments = new ilICalWriter();
163 
164  foreach ($this->calendars as $category_id) {
165  foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($category_id)) as $app_id) {
166  $appointment = new ilCalendarEntry($app_id);
167  if ($this->isRepeatingAppointment($appointment)) {
168  $str_writer_appointment = $this->createAppointment($appointment);
169  $str_writer_appointments->append($str_writer_appointment);
170  continue;
171  }
172  $single_appointments[] = $appointment;
173  }
174  }
175 
176  usort($single_appointments, function (ilCalendarEntry $a, ilCalendarEntry $b) {
177  if($a->getStart() === $b->getStart()) {
178  return 0;
179  }
180  return $a->getStart() > $b->getStart() ? 1 : -1;
181  });
182 
183  // Apply a filter on limited exports only
184  if ($this->is_export_limited) {
185  $single_appointments = array_filter($single_appointments, function (ilCalendarEntry $a) {
186  $time_now = new ilDateTime(time(), IL_CAL_UNIX);
187  $str_time_now = $time_now->get(IL_CAL_FKT_DATE, 'Ymd', ilTimeZone::UTC);
188  $str_time_start = $a->getStart()->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
189  if ($str_time_start === null) {
190  return false;
191  }
192  $start = new DateTimeImmutable($str_time_start);
193  $now = new DateTimeImmutable($str_time_now);
194  $lower_bound = $now->sub(new DateInterval('P30D'));
195  return $lower_bound <= $start;
196  });
197  }
198 
199  foreach ($single_appointments as $appointment) {
200  $str_writer_appointment = $this->createAppointment($appointment);
201  // Check byte count for limited exports only
202  if (
203  $this->is_export_limited &&
204  ($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
205  ) {
206  break;
207  }
208  $str_writer_appointments->append($str_writer_appointment);
209  }
210 
211  return $str_writer_appointments;
212  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
createAppointment(ilCalendarEntry $appointment)
const IL_CAL_FKT_DATE
getStart()
Get start of date period.
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
isRepeatingAppointment(ilCalendarEntry $appointment)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildAppointmentUrl()

ilCalendarExport::buildAppointmentUrl ( ilCalendarEntry  $entry)
protected

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

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

Referenced by createVEVENT().

329  : ilICalWriter
330  {
331  $str_writer = new ilICalWriter();
334  );
335  if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) {
336  $str_writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH);
337  } else {
338  $refs = ilObject::_getAllReferences($cat->getObjId());
339  include_once './Services/Link/classes/class.ilLink.php';
340  $str_writer->addLine('URL;VALUE=URI:' . ilLink::_getLink(current($refs)));
341  }
342  return $str_writer;
343  }
static _getAllReferences(int $id)
get all reference ids for object ID
static getInstanceByCategoryId(int $a_cat_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createAppointment()

ilCalendarExport::createAppointment ( ilCalendarEntry  $appointment)
protected

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

References createVEVENT(), createVTODO(), and ilCalendarEntry\isMilestone().

Referenced by addAppointments(), and addCategories().

229  : ilICalWriter
230  {
231  if ($appointment->isMilestone()) {
232  return $this->createVTODO($appointment);
233  } else {
234  return $this->createVEVENT($appointment);
235  }
236  }
createVEVENT(ilCalendarEntry $app)
createVTODO(ilCalendarEntry $app)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createRecurrences()

ilCalendarExport::createRecurrences ( ilCalendarEntry  $app)
protected

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

References ilCalendarRecurrences\_getRecurrences(), ilCalendarEntry\getEntryId(), and ilCalendarRecurrenceExclusions\getExclusionDates().

Referenced by createVEVENT().

308  : ilICalWriter
309  {
310  $str_writer = new ilICalWriter();
311  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
312  foreach (ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec) {
314  $str_writer->addLine($excl->toICal());
315  }
316  $recurrence_ical = $rec->toICal($this->il_user->getId());
317  if (strlen($recurrence_ical)) {
318  $str_writer->addLine($recurrence_ical);
319  }
320  }
321  return $str_writer;
322  }
static _getRecurrences(int $a_cal_id)
get all recurrences of an appointment
static getExclusionDates($a_cal_id)
Read exclusion dates.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTimezones()

ilCalendarExport::createTimezones ( )
protected

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

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

Referenced by export().

139  : ilICalWriter
140  {
141  $str_writer = new ilICalWriter();
142  if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
143  return $str_writer;
144  }
145 
146  $str_writer->addLine('X-WR-TIMEZONE:' . $this->il_user->getTimeZone());
147  $tzid_file = ilCalendarUtil::getZoneInfoFile($this->il_user->getTimeZone());
148  if (!is_file($tzid_file)) {
149  $tzid_file = ilCalendarUtil::getZoneInfoFile('Europe/Berlin');
150  }
151  $reader = fopen($tzid_file, 'r');
152  while ($line = fgets($reader)) {
153  $line = str_replace("\n", '', $line);
154  $str_writer->addLine($line);
155  }
156  return $str_writer;
157  }
static getZoneInfoFile($a_tz)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVEVENT()

ilCalendarExport::createVEVENT ( ilCalendarEntry  $app)
protected

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

References buildAppointmentUrl(), ilCalendarUserSettings\CAL_EXPORT_TZ_UTC, CLIENT_ID, createRecurrences(), ilICalWriter\escapeText(), ilCalendarEntry\getDescription(), ilCalendarEntry\getEnd(), ilCalendarEntry\getEntryId(), ilCalendarEntry\getLastUpdate(), ilCalendarEntry\getLocation(), ilCalendarEntry\getPresentationTitle(), ilCalendarEntry\getStart(), getUserSettings(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_UNIX, ilCalendarEntry\isFullday(), ILIAS\Repository\logger(), and ilTimeZone\UTC.

Referenced by createAppointment().

243  : ilICalWriter
244  {
245  $str_writer = new ilICalWriter();
246  if (!$app->getStart() instanceof ilDateTime) {
247  $this->logger->notice('Cannot create appointment for app_id: ' . $app->getEntryId());
248  return $str_writer;
249  }
250  $test_date = $app->getStart()->get(IL_CAL_FKT_DATE, 'Ymd');
251  if (!strlen((string) $test_date)) {
252  return $str_writer;
253  }
254  $now = new ilDateTime(time(), IL_CAL_UNIX);
255 
256  $str_writer->addLine('BEGIN:VEVENT');
257  $str_writer->addLine('DTSTAMP:'
258  . $now->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC));
259  $str_writer->addLine('UID:' . ilICalWriter::escapeText(
260  $app->getEntryId() . '_' . CLIENT_ID . '@' . ILIAS_HTTP_PATH
261  ));
262 
263  $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
264  $str_writer->addLine('LAST-MODIFIED:' . $last_mod);
265 
266  $startInit = $app->getStart();
267  $endInit = $app->getEnd();
268 
269  // begin-patch aptar
270  if ($app->isFullday()) {
271  // According to RFC 5545 3.6.1 DTEND is not inclusive.
272  // But ILIAS stores inclusive dates in the database.
273  $endInit->increment(IL_CAL_DAY, 1);
274  $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
275  $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
276  $str_writer->addLine('DTSTART;VALUE=DATE:' . $start);
277  $str_writer->addLine('DTEND;VALUE=DATE:' . $end);
278  } else {
279  if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
280  $start = $app->getStart()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
281  $end = $app->getEnd()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
282  $str_writer->addLine('DTSTART:' . $start);
283  $str_writer->addLine('DTEND:' . $end);
284  } else {
285  $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $this->il_user->getTimeZone());
286  $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $this->il_user->getTimeZone());
287  $str_writer->addLine('DTSTART;TZID=' . $this->il_user->getTimezone() . ':' . $start);
288  $str_writer->addLine('DTEND;TZID=' . $this->il_user->getTimezone() . ':' . $end);
289  }
290  }
291  // end-patch aptar
292 
293  $str_writer->append($this->createRecurrences($app));
294  $str_writer->addLine('SUMMARY:' . ilICalWriter::escapeText($app->getPresentationTitle(false)));
295  if (strlen($app->getDescription())) {
296  $str_writer->addLine('DESCRIPTION:' . ilICalWriter::escapeText($app->getDescription()));
297  }
298  if (strlen($app->getLocation())) {
299  $str_writer->addLine('LOCATION:' . ilICalWriter::escapeText($app->getLocation()));
300  }
301 
302  // TODO: URL
303  $str_writer->append($this->buildAppointmentUrl($app));
304  $str_writer->addLine('END:VEVENT');
305  return $str_writer;
306  }
static escapeText(string $a_text)
const IL_CAL_UNIX
getPresentationTitle(bool $a_shorten=true)
const IL_CAL_DAY
getEnd()
Get end of period.
createRecurrences(ilCalendarEntry $app)
buildAppointmentUrl(ilCalendarEntry $entry)
isFullday()
is event a fullday period
const CLIENT_ID
Definition: constants.php:41
const IL_CAL_FKT_DATE
getStart()
Get start of date period.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createVTODO()

ilCalendarExport::createVTODO ( ilCalendarEntry  $app)
protected

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

Referenced by createAppointment().

238  : ilICalWriter
239  {
240  return new ilICalWriter();
241  }
+ Here is the caller graph for this function:

◆ export()

ilCalendarExport::export ( )

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

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

Referenced by ilCalendarRemoteAccessHandler\handleRequest().

111  : void
112  {
113  $this->str_writer_export->clear();
114  $str_writer_prefix = new ilICalWriter();
115  $str_writer_prefix->addLine('BEGIN:VCALENDAR');
116  $str_writer_prefix->addLine('VERSION:2.0');
117  $str_writer_prefix->addLine('METHOD:PUBLISH');
118  $str_writer_prefix->addLine('PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
119  $str_writer_prefix->append($this->createTimezones());
120  $str_writer_suffix = new ilICalWriter();
121  $str_writer_suffix->addLine('END:VCALENDAR');
122  $this->str_writer_export->append($str_writer_prefix);
123  switch ($this->getExportType()) {
124  case self::EXPORT_CALENDARS:
125  $byte_sum = $str_writer_prefix->byteCount() + $str_writer_suffix->byteCount();
126  $remaining_bytes = self::BYTE_LIMIT - $byte_sum;
127  $str_builder_body = $this->addCategories($remaining_bytes);
128  $this->str_writer_export->append($str_builder_body);
129  break;
130 
131  case self::EXPORT_APPOINTMENTS:
132  $str_builder_body = $this->addAppointments();
133  $this->str_writer_export->append($str_builder_body);
134  break;
135  }
136  $this->str_writer_export->append($str_writer_suffix);
137  }
addCategories(int $remaining_bytes)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAppointments()

ilCalendarExport::getAppointments ( )
Returns
int[]

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

References $appointments.

Referenced by addAppointments().

81  : array
82  {
83  return $this->appointments;
84  }
+ Here is the caller graph for this function:

◆ getCalendarIds()

ilCalendarExport::getCalendarIds ( )
Returns
int[]

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

References $calendars.

97  : array
98  {
99  return $this->calendars;
100  }

◆ getExportString()

ilCalendarExport::getExportString ( )

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

324  : string
325  {
326  return $this->str_writer_export->__toString();
327  }

◆ getExportType()

ilCalendarExport::getExportType ( )

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

References $export_type.

Referenced by export().

106  : int
107  {
108  return $this->export_type;
109  }
+ Here is the caller graph for this function:

◆ getUserSettings()

ilCalendarExport::getUserSettings ( )

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

References $user_settings.

Referenced by createTimezones(), and createVEVENT().

+ Here is the caller graph for this function:

◆ isRepeatingAppointment()

ilCalendarExport::isRepeatingAppointment ( ilCalendarEntry  $appointment)
protected

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

References ilCalendarRecurrences\_getRecurrences(), and ilCalendarEntry\getEntryId().

Referenced by addCategories().

214  : bool
215  {
216  return count(ilCalendarRecurrences::_getRecurrences($appointment->getEntryId())) > 0;
217  }
static _getRecurrences(int $a_cal_id)
get all recurrences of an appointment
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAppointments()

ilCalendarExport::setAppointments ( array  $a_apps)
Parameters
int[]$a_apps

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

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

◆ setCalendarIds()

ilCalendarExport::setCalendarIds ( array  $a_cal_ids)
Parameters
int[]$a_cal_ids

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

89  : void
90  {
91  $this->calendars = $a_cal_ids;
92  }

◆ setExportType()

ilCalendarExport::setExportType ( int  $a_type)

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

102  : void
103  {
104  $this->export_type = $a_type;
105  }

Field Documentation

◆ $appointments

array ilCalendarExport::$appointments = array()
protected

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

Referenced by getAppointments().

◆ $calendars

array ilCalendarExport::$calendars = array()
protected

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

Referenced by getCalendarIds().

◆ $export_type

int ilCalendarExport::$export_type = self::EXPORT_CALENDARS
protected

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

Referenced by getExportType().

◆ $il_user

ilObjUser ilCalendarExport::$il_user
protected

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

◆ $is_export_limited

bool ilCalendarExport::$is_export_limited
protected

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

Referenced by __construct().

◆ $logger

ilLogger ilCalendarExport::$logger
private

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

◆ $str_writer_export

ilICalWriter ilCalendarExport::$str_writer_export
protected

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

◆ $user_settings

ilCalendarUserSettings ilCalendarExport::$user_settings
protected

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

Referenced by getUserSettings().

◆ $writer

ilICalWriter ilCalendarExport::$writer
protected

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

◆ BYTE_LIMIT

const ilCalendarExport::BYTE_LIMIT = 1000000
protected

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

◆ EXPORT_APPOINTMENTS

const ilCalendarExport::EXPORT_APPOINTMENTS = 2

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

Referenced by ilCalendarMailNotification\addAttachment().

◆ EXPORT_CALENDARS

const ilCalendarExport::EXPORT_CALENDARS = 1

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


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