ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCalendarExport Class Reference

@classDescription 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 ($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
 
 $export_type = self::EXPORT_CALENDARS
 
 $logger = null
 
 $il_user
 
 $calendars
 
 $user_settings
 
 $appointments
 
 $str_writer_export
 
 $is_export_limited
 

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 ( array  $a_calendar_ids = [],
bool  $is_export_limited = false 
)
Parameters
int[]$a_calendar_ids

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

80 {
81 global $DIC;
82 $this->il_user = $DIC->user();
83 $this->logger = $DIC->logger()->cal();
84 $this->calendars = $a_calendar_ids;
85 $this->is_export_limited = $is_export_limited;
86 $this->appointments = [];
87 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->il_user->getId());
88 $this->str_writer_export = new ilICalWriter();
89 }
static _getInstanceByUserId($a_user_id)
get singleton instance
global $DIC
Definition: goto.php:24

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addAppointments()

ilCalendarExport::addAppointments ( )
protected

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

237 {
238 $str_builder_appointments = new ilICalWriter();
239 foreach ($this->getAppointments() as $app) {
240 $str_writer_appointment = $this->createAppointment($app);
241 $str_builder_appointments->append($str_writer_appointment);
242 }
243 return $str_builder_appointments;
244 }
createAppointment(ilCalendarEntry $appointment)
$app
Definition: cli.php:38

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

Referenced by export().

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

183 {
184 $single_appointments = [];
185 $str_writer_appointments = new ilICalWriter();
186
187 foreach ($this->calendars as $category_id) {
188 foreach (ilCalendarCategoryAssignments::_getAssignedAppointments(array($category_id)) as $app_id) {
189 $appointment = new ilCalendarEntry($app_id);
190 if ($this->isRepeatingAppointment($appointment)) {
191 $str_writer_appointment = $this->createAppointment($appointment);
192 $str_writer_appointments->append($str_writer_appointment);
193 continue;
194 }
195 $single_appointments[] = $appointment;
196 }
197 }
198
199 usort($single_appointments, function (ilCalendarEntry $a, ilCalendarEntry $b) {
200 return $a->getStart() > $b->getStart();
201 });
202
203 // Apply a filter on limited exports only
204 if ($this->is_export_limited) {
205 $single_appointments = array_filter($single_appointments, function (ilCalendarEntry $a) {
206 $time_now = new ilDateTime(time(), IL_CAL_UNIX);
207 $str_time_now = $time_now->get(IL_CAL_FKT_DATE, 'Ymd', ilTimeZone::UTC);
208 $str_time_start = $a->getStart()->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
209 $start = new DateTimeImmutable($str_time_start);
210 $now = new DateTimeImmutable($str_time_now);
211 $lower_bound = $now->sub(new DateInterval('P30D'));
212 return $lower_bound <= $start;
213 });
214 }
215
216 foreach ($single_appointments as $appointment) {
217 $str_writer_appointment = $this->createAppointment($appointment);
218 // Check byte count for limited exports only
219 if (
220 $this->is_export_limited &&
221 ($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
222 ) {
223 break;
224 }
225 $str_writer_appointments->append($str_writer_appointment);
226 }
227
228 return $str_writer_appointments;
229 }
const IL_CAL_UNIX
const IL_CAL_FKT_DATE
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
Model for a calendar entry.
isRepeatingAppointment(ilCalendarEntry $appointment)
@classDescription Date and time handling
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

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

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

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

347 {
348 $str_writer = new ilICalWriter();
351 );
352 if ($cat->getType() != ilCalendarCategory::TYPE_OBJ) {
353 $str_writer->addLine('URL;VALUE=URI:' . ILIAS_HTTP_PATH);
354 } else {
355 $refs = ilObject::_getAllReferences($cat->getObjId());
356 include_once './Services/Link/classes/class.ilLink.php';
357 $str_writer->addLine('URL;VALUE=URI:' . ilLink::_getLink(current($refs)));
358 }
359 return $str_writer;
360 }
static _lookupCategories($a_cal_id)
lookup categories
static getInstanceByCategoryId($a_cat_id)
Get instance by category 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:

◆ createAppointment()

ilCalendarExport::createAppointment ( ilCalendarEntry  $appointment)
protected

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

247 {
248 if ($appointment->isMilestone()) {
249 return $this->createVTODO($appointment);
250 } else {
251 return $this->createVEVENT($appointment);
252 }
253 }
createVTODO(ilCalendarEntry $app)
createVEVENT(ilCalendarEntry $app)

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

Referenced by addAppointments(), and addCategories().

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

326 {
327 $str_writer = new ilICalWriter();
328 include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
329 foreach (ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec) {
330 foreach (ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl) {
331 $str_writer->addLine($excl->toICal());
332 }
333 $recurrence_ical = $rec->toICal($this->il_user->getId());
334 if (strlen($recurrence_ical)) {
335 $str_writer->addLine($recurrence_ical);
336 }
337 }
338 return $str_writer;
339 }
static getExclusionDates($a_cal_id)
Read exclusion dates.
static _getRecurrences($a_cal_id)
get all recurrences of an appointment

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

Referenced by createVEVENT().

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

◆ createTimezones()

ilCalendarExport::createTimezones ( )
protected

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

161 {
162 $str_writer = new ilICalWriter();
163 if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
164 return $str_writer;
165 }
166
167 $str_writer->addLine('X-WR-TIMEZONE:' . $this->il_user->getTimeZone());
168
169 include_once './Services/Calendar/classes/class.ilCalendarUtil.php';
170 $tzid_file = ilCalendarUtil::getZoneInfoFile($this->il_user->getTimeZone());
171 if (!is_file($tzid_file)) {
172 $tzid_file = ilCalendarUtil::getZoneInfoFile('Europe/Berlin');
173 }
174 $reader = fopen($tzid_file, 'r');
175 while ($line = fgets($reader)) {
176 $line = str_replace("\n", '', $line);
177 $str_writer->addLine($line);
178 }
179 return $str_writer;
180 }
static getZoneInfoFile($a_tz)

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

◆ createVEVENT()

ilCalendarExport::createVEVENT ( ilCalendarEntry  $app)
protected

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

261 {
262 $str_writer = new ilICalWriter();
263 if (!$app->getStart() instanceof ilDateTime) {
264 $this->logger->notice('Cannot create appointment for app_id: ' . $app->getEntryId());
265 return $str_writer;
266 }
267 $test_date = $app->getStart()->get(IL_CAL_FKT_DATE, 'Ymd');
268 if (!strlen((string) $test_date)) {
269 return $str_writer;
270 }
271 $now = new ilDateTime(time(), IL_CAL_UNIX);
272
273 $str_writer->addLine('BEGIN:VEVENT');
274 $str_writer->addLine('DTSTAMP:'
275 . $now->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC));
276 $str_writer->addLine('UID:' . ilICalWriter::escapeText(
277 $app->getEntryId() . '_' . CLIENT_ID . '@' . ILIAS_HTTP_PATH
278 ));
279
280 $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
281 $str_writer->addLine('LAST-MODIFIED:' . $last_mod);
282
283 $startInit = $app->getStart();
284 $endInit = $app->getEnd();
285
286 // begin-patch aptar
287 if ($app->isFullday()) {
288 // According to RFC 5545 3.6.1 DTEND is not inclusive.
289 // But ILIAS stores inclusive dates in the database.
290 $endInit->increment(IL_CAL_DAY, 1);
291 $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
292 $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
293 $str_writer->addLine('DTSTART;VALUE=DATE:' . $start);
294 $str_writer->addLine('DTEND;VALUE=DATE:' . $end);
295 } else {
296 if ($this->getUserSettings()->getExportTimeZoneType() == ilCalendarUserSettings::CAL_EXPORT_TZ_UTC) {
297 $start = $app->getStart()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
298 $end = $app->getEnd()->get(IL_CAL_FKT_DATE, 'Ymd\THis\Z', ilTimeZone::UTC);
299 $str_writer->addLine('DTSTART:' . $start);
300 $str_writer->addLine('DTEND:' . $end);
301 } else {
302 $start = $startInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $this->il_user->getTimeZone());
303 $end = $endInit->get(IL_CAL_FKT_DATE, 'Ymd\THis', $this->il_user->getTimeZone());
304 $str_writer->addLine('DTSTART;TZID=' . $this->il_user->getTimezone() . ':' . $start);
305 $str_writer->addLine('DTEND;TZID=' . $this->il_user->getTimezone() . ':' . $end);
306 }
307 }
308 // end-patch aptar
309
310 $str_writer->append($this->createRecurrences($app));
311 $str_writer->addLine('SUMMARY:' . ilICalWriter::escapeText($app->getPresentationTitle(false)));
312 if (strlen($app->getDescription())) {
313 $str_writer->addLine('DESCRIPTION:' . ilICalWriter::escapeText($app->getDescription()));
314 }
315 if (strlen($app->getLocation())) {
316 $str_writer->addLine('LOCATION:' . ilICalWriter::escapeText($app->getLocation()));
317 }
318
319 // TODO: URL
320 $str_writer->append($this->buildAppointmentUrl($app));
321 $str_writer->addLine('END:VEVENT');
322 return $str_writer;
323 }
const IL_CAL_DAY
buildAppointmentUrl(ilCalendarEntry $entry)
createRecurrences(ilCalendarEntry $app)
static escapeText($a_text)
const CLIENT_ID
Definition: constants.php:39

References $app, buildAppointmentUrl(), ilCalendarUserSettings\CAL_EXPORT_TZ_UTC, CLIENT_ID, createRecurrences(), ilICalWriter\escapeText(), getUserSettings(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_UNIX, and ilTimeZone\UTC.

Referenced by createAppointment().

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

256 {
257 return new ilICalWriter();
258 }

Referenced by createAppointment().

+ Here is the caller graph for this function:

◆ export()

ilCalendarExport::export ( )

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

132 : void
133 {
134 $this->str_writer_export->clear();
135 $str_writer_prefix = new ilICalWriter();
136 $str_writer_prefix->addLine('BEGIN:VCALENDAR');
137 $str_writer_prefix->addLine('VERSION:2.0');
138 $str_writer_prefix->addLine('METHOD:PUBLISH');
139 $str_writer_prefix->addLine('PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
140 $str_writer_prefix->append($this->createTimezones());
141 $str_writer_suffix = new ilICalWriter();
142 $str_writer_suffix->addLine('END:VCALENDAR');
143 $this->str_writer_export->append($str_writer_prefix);
144 switch ($this->getExportType()) {
146 $byte_sum = $str_writer_prefix->byteCount() + $str_writer_suffix->byteCount();
147 $remaining_bytes = self::BYTE_LIMIT - $byte_sum;
148 $str_builder_body = $this->addCategories($remaining_bytes);
149 $this->str_writer_export->append($str_builder_body);
150 break;
151
153 $str_builder_body = $this->addAppointments();
154 $this->str_writer_export->append($str_builder_body);
155 break;
156 }
157 $this->str_writer_export->append($str_writer_suffix);
158 }
addCategories(int $remaining_bytes)

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

+ Here is the call graph for this function:

◆ getAppointments()

ilCalendarExport::getAppointments ( )

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

101 : array
102 {
103 return $this->appointments;
104 }

References $appointments.

Referenced by addAppointments().

+ Here is the caller graph for this function:

◆ getCalendarIds()

ilCalendarExport::getCalendarIds ( )
Returns
int[]

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

117 : array
118 {
119 return $this->calendars;
120 }

References $calendars.

◆ getExportString()

ilCalendarExport::getExportString ( )

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

341 : string
342 {
343 return $this->str_writer_export->__toString();
344 }

◆ getExportType()

ilCalendarExport::getExportType ( )

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

127 : int
128 {
129 return $this->export_type;
130 }

References $export_type.

Referenced by export().

+ Here is the caller graph for this function:

◆ getUserSettings()

ilCalendarExport::getUserSettings ( )

Definition at line 91 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 231 of file class.ilCalendarExport.php.

231 : bool
232 {
233 return count(ilCalendarRecurrences::_getRecurrences($appointment->getEntryId())) > 0;
234 }

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

Referenced by addCategories().

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

◆ setAppointments()

ilCalendarExport::setAppointments (   $a_apps)

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

96 : void
97 {
98 $this->appointments = $a_apps;
99 }

◆ setCalendarIds()

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

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

109 : void
110 {
111 $this->calendars = $a_cal_ids;
112 }

◆ setExportType()

ilCalendarExport::setExportType ( int  $a_type)

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

122 : void
123 {
124 $this->export_type = $a_type;
125 }

Field Documentation

◆ $appointments

ilCalendarExport::$appointments
protected

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

Referenced by getAppointments().

◆ $calendars

ilCalendarExport::$calendars
protected

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

Referenced by getCalendarIds().

◆ $export_type

ilCalendarExport::$export_type = self::EXPORT_CALENDARS
protected

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

Referenced by getExportType().

◆ $il_user

ilCalendarExport::$il_user
protected

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

◆ $is_export_limited

ilCalendarExport::$is_export_limited
protected

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

Referenced by __construct().

◆ $logger

ilCalendarExport::$logger = null
protected

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

◆ $str_writer_export

ilCalendarExport::$str_writer_export
protected

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

◆ $user_settings

ilCalendarExport::$user_settings
protected

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

Referenced by getUserSettings().

◆ BYTE_LIMIT

const ilCalendarExport::BYTE_LIMIT = 1000000
protected

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

◆ EXPORT_APPOINTMENTS

const ilCalendarExport::EXPORT_APPOINTMENTS = 2

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

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

◆ EXPORT_CALENDARS

const ilCalendarExport::EXPORT_CALENDARS = 1

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

Referenced by export().


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