From ca5de9531bbe1b542197fe1f2700c360e8cd6002 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 7 May 2009 09:53:40 -0400 Subject: [PATCH] Add a filterEventsByCalendar() method to Kronolith_Driver. Takes an 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 | 9 ++++++++- kronolith/lib/Driver/Sql.php | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 21bae88d5..f2b2eb32d 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -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'); + } } diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index ddf59eb11..fd5d43798 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -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)); + } + } -- 2.11.0