break out recurrence parsing to it's own method.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 11 Jul 2010 14:06:36 +0000 (10:06 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 11 Jul 2010 14:08:05 +0000 (10:08 -0400)
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
kronolith/lib/Event/Ical.php

index a5d6075..8d670c8 100644 (file)
@@ -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;
     }
 
     /**
index d324d58..c41028d 100644 (file)
@@ -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']);
+                    }
+                }
+            }
+        }
+    }
+
 }