plugins/calendar

Thomas Brüderli bruederli at kolabsys.com
Wed Jan 23 17:17:26 CET 2013


 plugins/calendar/drivers/kolab/kolab_calendar.php |    9 +++++-
 plugins/calendar/lib/calendar_recurrence.php      |   31 +++++++++++++++++++---
 2 files changed, 35 insertions(+), 5 deletions(-)

New commits:
commit 53c77796dd555ce573130a9f0a3ea04abda94f39
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Jan 23 11:36:55 2013 +0100

    Add fallback for recurrence computation when the kolabcalendaring php module isn't available

diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index f2c106e..45db638 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -414,7 +414,14 @@ class kolab_calendar
     }
 
     // use libkolab to compute recurring events
-    $recurrence = new kolab_date_recurrence($object);
+    if (class_exists('kolabcalendaring')) {
+        $recurrence = new kolab_date_recurrence($object);
+    }
+    else {
+        // fallback to local recurrence implementation
+        require_once($this->cal->home . '/lib/calendar_recurrence.php');
+        $recurrence = new calendar_recurrence($this->cal, $event);
+    }
 
     $i = 0;
     $events = array();
diff --git a/plugins/calendar/lib/calendar_recurrence.php b/plugins/calendar/lib/calendar_recurrence.php
index 03831c1..bf534f5 100644
--- a/plugins/calendar/lib/calendar_recurrence.php
+++ b/plugins/calendar/lib/calendar_recurrence.php
@@ -41,6 +41,10 @@ class calendar_recurrence
    */
   function __construct($cal, $event)
   {
+    // use Horde classes to compute recurring instances
+    // TODO: replace with something that has less than 6'000 lines of code
+    require_once(__DIR__ . '/Horde_Date_Recurrence.php');
+
     $this->cal = $cal;
     $this->event = $event;
     $this->next = new Horde_Date($event['start'], $cal->timezone->getName());
@@ -49,10 +53,6 @@ class calendar_recurrence
     if (is_object($event['start']) && is_object($event['end']))
       $this->duration = $event['start']->diff($event['end']);
 
-    // use Horde classes to compute recurring instances
-    // TODO: replace with something that has less than 6'000 lines of code
-    require_once($this->cal->home . '/lib/Horde_Date_Recurrence.php');
-
     $this->engine = new Horde_Date_Recurrence($event['start']);
     $this->engine->fromRRule20(libcalendaring::to_rrule($event['recurrence']));
 
@@ -83,4 +83,27 @@ class calendar_recurrence
     return $time;
   }
 
+  /**
+   * Get the next recurring instance of this event
+   *
+   * @return mixed Array with event properties or False if recurrence ended
+   */
+  public function next_instance()
+  {
+    if ($next_start = $this->next_start()) {
+      $next_end = clone $next_start;
+      $next_end->add($this->duration);
+
+      $next = $this->event;
+      $next['recurrence_id'] = $next_start->format('Y-m-d');
+      $next['start'] = $next_start;
+      $next['end'] = $next_end;
+      unset($next['_formatobj']);
+
+      return $next;
+    }
+
+    return false;
+  }
+
 }





More information about the commits mailing list