]> source.dussan.org Git - nextcloud-server.git/commitdiff
some work on repeating events caching
authorGeorg Ehrke <dev@georgswebsite.de>
Fri, 8 Jun 2012 20:22:16 +0000 (22:22 +0200)
committerGeorg Ehrke <dev@georgswebsite.de>
Fri, 8 Jun 2012 20:22:16 +0000 (22:22 +0200)
apps/calendar/appinfo/database.xml
apps/calendar/lib/repeat.php

index b065ab3f94ac49da841a388de98ba3ac15fa0121..5d2f415c7b3ee11a64185cf142362c130b8e7297 100644 (file)
 
  </table>
  
+ <table>
+
+  <name>*dbprefix*calendar_repeat</name>
+
+  <declaration>
+
+   <field>
+    <name>id</name>
+    <type>integer</type>
+    <default>0</default>
+    <notnull>true</notnull>
+    <autoincrement>1</autoincrement>
+    <unsigned>true</unsigned>
+    <length>4</length>
+   </field>
+  
+   <field>
+    <name>eventid</name>
+    <type>integer</type>
+    <default>0</default>
+    <notnull>true</notnull>
+    <unsigned>true</unsigned>
+    <length>4</length>
+   </field>
+  
+   <field>
+    <name>calid</name>
+    <type>integer</type>
+    <default>0</default>
+    <notnull>true</notnull>
+    <unsigned>true</unsigned>
+    <length>4</length>
+   </field>
+
+   <field>
+    <name>startdate</name>
+    <type>timestamp</type>
+    <default>0000-00-00 00:00:00</default>
+    <notnull>false</notnull>
+   </field>
+
+   <field>
+    <name>enddate</name>
+    <type>timestamp</type>
+    <default>0000-00-00 00:00:00</default>
+    <notnull>false</notnull>
+   </field>
+
+  </declaration>
+
+ </table>
 </database>
index 89cafa388c602e5edfc1c93510a12935e11dd124..3117d306c8a0ea739da18d706aaff14a002aebdb 100644 (file)
@@ -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