From ac74d87e3eef1e53f168d350f7e38e495e0746f0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 8 Jun 2012 22:22:16 +0200 Subject: [PATCH] some work on repeating events caching --- apps/calendar/appinfo/database.xml | 52 ++++++++++++++++++++++++++++++ apps/calendar/lib/repeat.php | 47 ++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/apps/calendar/appinfo/database.xml b/apps/calendar/appinfo/database.xml index b065ab3f94a..5d2f415c7b3 100644 --- a/apps/calendar/appinfo/database.xml +++ b/apps/calendar/appinfo/database.xml @@ -290,4 +290,56 @@ + + + *dbprefix*calendar_repeat + + + + + id + integer + 0 + true + 1 + true + 4 + + + + eventid + integer + 0 + true + true + 4 + + + + calid + integer + 0 + true + true + 4 + + + + startdate + timestamp + 0000-00-00 00:00:00 + false + + + + enddate + timestamp + 0000-00-00 00:00:00 + false + + + + +
+ diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 89cafa388c6..3117d306c8a 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -32,7 +32,17 @@ class OC_Calendar_Repeat{ * @return (array) */ public static function get_inperiod($id, $from, $until){ - + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_repeat WHERE eventid = ?' + .' AND ((startdate >= ? AND startdate <= ?)' + .' OR (enddate >= ? AND enddate <= ?)'); + $result = $stmt->execute(array($id, + $from, $until, + $from, $until)); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; } /* * @brief returns the cache of all repeating events of a calendar @@ -40,22 +50,51 @@ class OC_Calendar_Repeat{ * @return (array) */ public static function getcalendar($id){ - + $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_repeat WHERE calid = ?'); + $result = $stmt->execute(array($id)); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; } /* * @brief returns the cache of all repeating events of a calendar in a specific period * @param (int) $id - id of the event * @param (string) $from - start for period in UTC * @param (string) $until - end for period in UTC + * @return (array) */ public static function getcalendar_inperiod($id, $from, $until){ - + $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*calendar_repeat WHERE calid = ?' + .' AND ((startdate >= ? AND startdate <= ?)' + .' OR (enddate >= ? AND enddate <= ?)'); + $result = $stmt->execute(array($id, + $from, $until, + $from, $until)); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; } /* * @brief generates the cache the first time + * @param (int) id - id of the event + * @return (bool) */ public static function generate($id){ - + $event = OC_Calendar_Object::find(id); + if($event['repeating'] == 0){ + return false; + } + $object = OC_VObject::parse($event['calendardata']); + $start = new DateTime('first day of January', new DateTimeZone('UTC')); + $start->modify('-5 years'); + $end = new DateTime('last day of December', new DateTimeZone('UTC')); + $end->modify('+5 years'); + $object->expand($start, $end); + } /* * @brief generates the cache the first time for all repeating event of an calendar -- 2.39.5