From 755d7cebd4191d74755041595e327eacb694cf69 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 11 Jul 2010 10:06:36 -0400 Subject: [PATCH] break out recurrence parsing to it's own method. Give Ical event's their own recurrence parsing code, we don't want to query the persistent storage for any events. Bug: 9133 --- kronolith/lib/Event.php | 14 ++++++++++++-- kronolith/lib/Event/Ical.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index a5d60755d..8d670c8eb 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -1011,6 +1011,18 @@ abstract class Kronolith_Event } } + $this->_handlevEventRecurrence($vEvent); + + $this->initialized = true; + } + + /** + * Handle parsing recurrence related fields. + * + * @param Horde_iCalendar $vEvent + */ + protected function _handlevEventRecurrence($vEvent) + { // Recurrence. $rrule = $vEvent->getAttribute('RRULE'); if (!is_array($rrule) && !($rrule instanceof PEAR_Error)) { @@ -1064,8 +1076,6 @@ abstract class Kronolith_Event $originaldt->format('d')); $originalEvent->save(); } - - $this->initialized = true; } /** diff --git a/kronolith/lib/Event/Ical.php b/kronolith/lib/Event/Ical.php index d324d5892..c41028dae 100644 --- a/kronolith/lib/Event/Ical.php +++ b/kronolith/lib/Event/Ical.php @@ -84,4 +84,37 @@ class Kronolith_Event_Ical extends Kronolith_Event return parent::getViewUrl($params, $full, $encoded); } + /** + * Parses the various exception related fields. Only deal with the EXDATE + * field here. + * + * @param Horde_iCalendar $vEvent The vEvent part. + */ + protected function _handlevEventRecurrence($vEvent) + { + // Recurrence. + $rrule = $vEvent->getAttribute('RRULE'); + if (!is_array($rrule) && !($rrule instanceof PEAR_Error)) { + $this->recurrence = new Horde_Date_Recurrence($this->start); + if (strpos($rrule, '=') !== false) { + $this->recurrence->fromRRule20($rrule); + } else { + $this->recurrence->fromRRule10($rrule); + } + + // Exceptions. EXDATE represents deleted events, just add the + // exception, no new event is needed. + $exdates = $vEvent->getAttributeValues('EXDATE'); + if (is_array($exdates)) { + foreach ($exdates as $exdate) { + if (is_array($exdate)) { + $this->recurrence->addException((int)$exdate['year'], + (int)$exdate['month'], + (int)$exdate['mday']); + } + } + } + } + } + } -- 2.11.0