Fix free/busy generation.
authorJan Schneider <jan@horde.org>
Fri, 19 Nov 2010 14:17:44 +0000 (15:17 +0100)
committerJan Schneider <jan@horde.org>
Fri, 19 Nov 2010 14:18:11 +0000 (15:18 +0100)
kronolith/lib/FreeBusy.php

index 62a8024..80c755f 100644 (file)
@@ -31,23 +31,22 @@ class Kronolith_FreeBusy
             $calendars = array($calendars);
         }
 
-        if ($user) {
+        if (!$user) {
             /* Find a share and retrieve owner. */
             foreach ($calendars as $calendar) {
-                if (strpos($calendar, 'remote_') === 0) {
+                if (strpos($calendar, 'internal_') !== 0) {
                     continue;
                 }
+                $calendar = substr($calendar, 9);
                 try {
                     $share = $kronolith_shares->getShare($calendar);
                     $user = $share->get('owner');
                     break;
-                } catch (Horde_Share_Exception $e) {
+                } catch (Horde_Exception $e) {
                     /* Might be a Kronolith_Resource. */
                     if (Kronolith_Resource::isResourceCalendar($calendar)) {
                         $user = $calendar;
                         break;
-                    } else {
-                        throw ($e);
                     }
                 }
             }
@@ -78,11 +77,8 @@ class Kronolith_FreeBusy
         /* Fetch events. */
         $busy = array();
         foreach ($calendars as $calendar) {
-            if (strpos($calendar, 'remote_') === 0) {
-                $driver = Kronolith::getDriver('Ical', substr($calendar, 7));
-            } else {
-                $driver = Kronolith::getDriver(null, $calendar);
-            }
+            @list($type, $calendar) = explode('_', $calendar, 2);
+            $driver = Kronolith::getDriver($type, $calendar);
             $events = $driver->listEvents(new Horde_Date($startstamp),
                                           $enddate, true);
             Kronolith::mergeEvents($busy, $events);