Add a filterEventsByCalendar() method to Kronolith_Driver. Takes an
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 May 2009 13:53:40 +0000 (09:53 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 May 2009 13:53:40 +0000 (09:53 -0400)
array of event uids and an array of calendar ids and returns only those
event uids that exist within the specified calendar ids.

kronolith/lib/Driver.php
kronolith/lib/Driver/Sql.php

index 21bae88..f2b2eb3 100644 (file)
@@ -311,7 +311,7 @@ class Kronolith_Driver
      */
     public function deleteEvent($eventId)
     {
-        return PEAR::raiseError('Not supported');
+
     }
 
     /**
@@ -322,4 +322,11 @@ class Kronolith_Driver
         return PEAR::raiseError(_("Removing user data is not supported with the current calendar storage backend."));
     }
 
+    /**
+     * Stub to be overridden in the child class if it can implement.
+     */
+    public function filterEventsByCalendar($uids, $calendar)
+    {
+        return PEAR::raiseError('Not supported');
+    }
 }
index ddf59eb..fd5d437 100644 (file)
@@ -896,4 +896,25 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         return true;
     }
 
+    /**
+     * Filter an array of event_uids to return only the events that belong to
+     * one of the $calendars.
+     *
+     * @param array $uids      An array of event_uid values.
+     * @param array $calendar  An array of calendar_ids.
+     *
+     * @return An array of event_uid values filtered by calendar_ids || PEAR_Error
+     */
+    public function filterEventsByCalendar($uids, $calendar)
+    {
+        $sql = 'SELECT event_uid FROM kronolith_events WHERE calendar_id IN (' . str_repeat('?, ', count($calendar) - 1) . '?) '
+            . 'AND event_uid IN (' . str_repeat('?,', count($uids) - 1) . '?)';
+
+        /* Log the query at a DEBUG log level. */
+        Horde::logMessage(sprintf('Kronolith_Driver_Sql::filterEventsByCalendar(): %s', $sql),
+                          __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+        return $this->_db->getCol($sql, 0, array_merge($calendar, $uids));
+    }
+
 }