diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-06-20 20:15:07 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-06-20 20:15:07 +0200 |
commit | 40e7b567833ae74051e9d14adc3335a79732ca04 (patch) | |
tree | 740ae29e8099cb247d7ab10e6e3e967c3436a654 /apps/calendar | |
parent | c1d205cbf53f0844bbfe734ea9213761de5f99f1 (diff) | |
parent | 0f13cbb47daf46a2a2d121364529fd6082a74cc1 (diff) | |
download | nextcloud-server-40e7b567833ae74051e9d14adc3335a79732ca04.tar.gz nextcloud-server-40e7b567833ae74051e9d14adc3335a79732ca04.zip |
Merge branch 'master' into calendar_export
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/ajax/cache/rescan.php | 15 | ||||
-rw-r--r-- | apps/calendar/ajax/cache/status.php | 22 | ||||
-rw-r--r-- | apps/calendar/ajax/events.php | 4 | ||||
-rw-r--r-- | apps/calendar/appinfo/app.php | 8 | ||||
-rw-r--r-- | apps/calendar/appinfo/database.xml | 52 | ||||
-rw-r--r-- | apps/calendar/appinfo/update.php | 7 | ||||
-rw-r--r-- | apps/calendar/appinfo/version | 2 | ||||
-rw-r--r-- | apps/calendar/js/settings.js | 20 | ||||
-rw-r--r-- | apps/calendar/lib/app.php | 113 | ||||
-rw-r--r-- | apps/calendar/lib/calendar.php | 12 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 40 | ||||
-rw-r--r-- | apps/calendar/lib/repeat.php | 204 | ||||
-rw-r--r-- | apps/calendar/templates/settings.php | 8 |
13 files changed, 416 insertions, 91 deletions
diff --git a/apps/calendar/ajax/cache/rescan.php b/apps/calendar/ajax/cache/rescan.php new file mode 100644 index 00000000000..3417f1ae4b4 --- /dev/null +++ b/apps/calendar/ajax/cache/rescan.php @@ -0,0 +1,15 @@ +<?php +/** + * Copyright (c) 2012 Georg Ehrke <georg@ownCloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('calendar'); +$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); +foreach($calendars as $calendar){ + OC_Calendar_Repeat::cleancalendar($calendar['id']); + OC_Calendar_Repeat::generatecalendar($calendar['id']); +} +OCP\JSON::success();
\ No newline at end of file diff --git a/apps/calendar/ajax/cache/status.php b/apps/calendar/ajax/cache/status.php new file mode 100644 index 00000000000..d2806d47895 --- /dev/null +++ b/apps/calendar/ajax/cache/status.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright (c) 2012 Georg Ehrke <georg@ownCloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('calendar'); +$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); +$allcached = true; +foreach($calendars as $calendar){ + if(!OC_Calendar_Repeat::is_calendar_cached($calendar['id'])){ + $allcached = false; + } +} +$l = new OC_L10N('calendar'); +if(!$allcached){ + OCP\JSON::error(array('message'=>'Not all calendars are completely cached', 'l10n'=>$l->t('Not all calendars are completely cached'))); +}else{ + OCP\JSON::success(array('message'=>'Everything seems to be completely cached', 'l10n'=>$l->t('Everything seems to be completely cached'))); +}
\ No newline at end of file diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 845cea8df82..7178358c7b5 100644 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -5,10 +5,6 @@ * later. * See the COPYING-README file. */ - - -require_once('when/When.php'); - OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('calendar'); session_write_close(); diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 48192be6e76..22b91a41efe 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -5,10 +5,16 @@ OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php'; OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php'; OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; +OC::$CLASSPATH['OC_Calendar_Repeat'] = 'apps/calendar/lib/repeat.php'; OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php'; OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php'; OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); +OCP\Util::connectHook('OC_Calendar', 'addEvent', 'OC_Calendar_Repeat', 'generate'); +OCP\Util::connectHook('OC_Calendar', 'editEvent', 'OC_Calendar_Repeat', 'update'); +OCP\Util::connectHook('OC_Calendar', 'deleteEvent', 'OC_Calendar_Repeat', 'clean'); +OCP\Util::connectHook('OC_Calendar', 'moveEvent', 'OC_Calendar_Repeat', 'update'); +OCP\Util::connectHook('OC_Calendar', 'deleteCalendar', 'OC_Calendar_Repeat', 'cleanCalendar'); OCP\Util::addscript('calendar','loader'); OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min"); OCP\Util::addStyle("3rdparty", "chosen/chosen"); @@ -19,4 +25,4 @@ OCP\App::addNavigationEntry( array( 'icon' => OCP\Util::imagePath( 'calendar', 'icon.svg' ), 'name' => $l->t('Calendar'))); OCP\App::registerPersonal('calendar', 'settings'); -OC_Search::registerProvider('OC_Search_Provider_Calendar');
\ No newline at end of file +OC_Search::registerProvider('OC_Search_Provider_Calendar'); diff --git a/apps/calendar/appinfo/database.xml b/apps/calendar/appinfo/database.xml index 5a3ad32dc24..73457e6c6cc 100644 --- a/apps/calendar/appinfo/database.xml +++ b/apps/calendar/appinfo/database.xml @@ -290,4 +290,56 @@ </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> diff --git a/apps/calendar/appinfo/update.php b/apps/calendar/appinfo/update.php index ce7f304a499..98159c33831 100644 --- a/apps/calendar/appinfo/update.php +++ b/apps/calendar/appinfo/update.php @@ -14,4 +14,11 @@ if (version_compare($installedVersion, '0.2.1', '<')) { $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET calendarcolor=? WHERE id=?' ); $r = $stmt->execute(array($color,$id)); } +} +if (version_compare($installedVersion, '0.5', '<')) { + $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); + foreach($calendars as $calendar){ + OC_Calendar_Repeat::cleanCalendar($calendar['id']); + OC_Calendar_Repeat::generateCalendar($calendar['id']); + } }
\ No newline at end of file diff --git a/apps/calendar/appinfo/version b/apps/calendar/appinfo/version index 267577d47e4..2eb3c4fe4ee 100644 --- a/apps/calendar/appinfo/version +++ b/apps/calendar/appinfo/version @@ -1 +1 @@ -0.4.1 +0.5 diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index c768a47a797..03e4217573d 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -44,4 +44,24 @@ $(document).ready(function(){ $('#' + jsondata.firstday).attr('selected',true); $('#firstday').chosen(); }); + $('#cleancalendarcache').click(function(){ + $.getJSON(OC.filePath('calendar', 'ajax/cache', 'rescan.php'), function(){ + calendarcachecheck(); + }); + }); + calendarcachecheck(); }); +function calendarcachecheck(){ + $.getJSON(OC.filePath('calendar', 'ajax/cache', 'status.php'), function(jsondata, status) { + $('#cleancalendarcache').attr('title', jsondata.l10n.text); + if(jsondata.status == 'success'){ + $('#cleancalendarcache').css('background', '#90EE90'); + $('#cleancalendarcache').css('color', '#333'); + $('#cleancalendarcache').css('text-shadow', '#fff 0 1px 0'); + }else{ + $('#cleancalendarcache').css('background', '#DC143C'); + $('#cleancalendarcache').css('color', '#FFFFFF'); + $('#cleancalendarcache').css('text-shadow', '0px 0px 0px #fff, 0px 0px #fff'); + } + }); +}
\ No newline at end of file diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index 74cf9f01037..167382a5e7d 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -116,8 +116,7 @@ class OC_Calendar_App{ * @brief returns the default categories of ownCloud * @return (array) $categories */ - protected static function getDefaultCategories() - { + protected static function getDefaultCategories(){ return array( self::$l10n->t('Birthday'), self::$l10n->t('Business'), @@ -152,8 +151,7 @@ class OC_Calendar_App{ * @brief returns the categories of the vcategories object * @return (array) $categories */ - public static function getCategoryOptions() - { + public static function getCategoryOptions(){ $categories = self::getVCategories()->categories(); return $categories; } @@ -359,94 +357,57 @@ class OC_Calendar_App{ /* * @brief generates the output for an event which will be readable for our js * @param (mixed) $event - event object / array - * @param (int) $start - unixtimestamp of start - * @param (int) $end - unixtimestamp of end + * @param (int) $start - DateTime object of start + * @param (int) $end - DateTime object of end * @return (array) $output - readable output */ public static function generateEventOutput($event, $start, $end){ - $output = array(); - if(isset($event['calendardata'])){ $object = OC_VObject::parse($event['calendardata']); $vevent = $object->VEVENT; }else{ $vevent = $event['vevent']; } - + $return = array(); + $id = $event['id']; + $allday = ($vevent->DTSTART->getDateType() == Sabre_VObject_Element_DateTime::DATE)?true:false; $last_modified = @$vevent->__get('LAST-MODIFIED'); $lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0; - - $output = array('id'=>(int)$event['id'], - 'title' => ($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed'), - 'description' => isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'', - 'lastmodified'=>$lastmodified); - - $dtstart = $vevent->DTSTART; - $start_dt = $dtstart->getDateTime(); - $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); - $end_dt = $dtend->getDateTime(); - - if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){ - $output['allDay'] = true; - }else{ - $output['allDay'] = false; - $start_dt->setTimezone(new DateTimeZone(self::$tz)); - $end_dt->setTimezone(new DateTimeZone(self::$tz)); - } - - // Handle exceptions to recurring events - $exceptionDateObjects = $vevent->select('EXDATE'); - $exceptionDateMap = Array(); - foreach ($exceptionDateObjects as $exceptionObject) { - foreach($exceptionObject->getDateTimes() as $datetime) { - $ts = $datetime->getTimestamp(); - $exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true; - } - } - - $return = array(); - if($event['repeating'] == 1){ - $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U'); - $r = new When(); - $r->recur($start_dt)->rrule((string) $vevent->RRULE); - /*$r = new iCal_Repeat_Generator(array('RECUR' => $start_dt, - * 'RRULE' => (string)$vevent->RRULE - * 'RDATE' => (string)$vevent->RDATE - * 'EXRULE' => (string)$vevent->EXRULE - * 'EXDATE' => (string)$vevent->EXDATE));*/ - while($result = $r->next()){ - if($result < $start){ - continue; - } - if($result > $end){ - break; - } - // Check for exceptions to recurring events - $ts = $result->getTimestamp(); - if (isset($exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)])) { - continue; - } - unset($ts); - - if($output['allDay'] == true){ - $output['start'] = $result->format('Y-m-d'); - $output['end'] = date('Y-m-d', $result->format('U') + --$duration); + $staticoutput = array('id'=>(int)$event['id'], + 'title' => htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed')), + 'description' => isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'', + 'lastmodified'=>$lastmodified, + 'allDay'=>$allday); + if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)){ + $cachedinperiod = OC_Calendar_Repeat::get_inperiod($id, $start, $end); + foreach($cachedinperiod as $cachedevent){ + $dynamicoutput = array(); + if($allday){ + $start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC')); + $end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC')); + $dynamicoutput['start'] = $start_dt->format('Y-m-d'); + $dynamicoutput['end'] = $end_dt->format('Y-m-d'); }else{ - $output['start'] = $result->format('Y-m-d H:i:s'); - $output['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration); + $start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC')); + $end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC')); + $start_dt->setTimezone(new DateTimeZone(self::$tz)); + $end_dt->setTimezone(new DateTimeZone(self::$tz)); + $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s'); + $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s'); } - $return[] = $output; + $return[] = array_merge($staticoutput, $dynamicoutput); } }else{ - if($output['allDay'] == true){ - $output['start'] = $start_dt->format('Y-m-d'); - $end_dt->modify('-1 sec'); - $output['end'] = $end_dt->format('Y-m-d'); - }else{ - $output['start'] = $start_dt->format('Y-m-d H:i:s'); - $output['end'] = $end_dt->format('Y-m-d H:i:s'); + if(OC_Calendar_Object::isrepeating($id)){ + $object->expand($start, $end); + } + foreach($object->getComponents() as $singleevent){ + if(!($singleevent instanceof Sabre_VObject_Component_VEvent)){ + continue; + } + $dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz); + $return[] = array_merge($staticoutput, $dynamicoutput); } - $return[] = $output; } return $return; } diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 0a54e7a32a6..b725898858d 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -109,7 +109,10 @@ class OC_Calendar_Calendar{ $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' ); $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); - return OCP\DB::insertid('*PREFIX*calendar_calendars'); + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + + return $insertid; } /** @@ -129,7 +132,10 @@ class OC_Calendar_Calendar{ $stmt = OCP\DB::prepare( 'INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)' ); $result = $stmt->execute(array($userid,$name,$uri,1,$order,$color,$timezone,$components)); - return OCP\DB::insertid('*PREFIX*calendar_calendars'); + $insertid = OCP\DB::insertid('*PREFIX*calendar_calendars'); + OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid); + + return $insertid; } /** @@ -158,6 +164,7 @@ class OC_Calendar_Calendar{ $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET displayname=?,calendarorder=?,calendarcolor=?,timezone=?,components=?,ctag=ctag+1 WHERE id=?' ); $result = $stmt->execute(array($name,$order,$color,$timezone,$components,$id)); + OCP\Util::emitHook('OC_Calendar', 'editCalendar', $id); return true; } @@ -198,6 +205,7 @@ class OC_Calendar_Calendar{ $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ?' ); $stmt->execute(array($id)); + OCP\Util::emitHook('OC_Calendar', 'deleteCalendar', $id); if(count(self::allCalendars()) == 0) { self::addCalendar(OCP\USER::getUser(),'Default calendar'); } diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 4212bf5a32c..a6ae6590080 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -108,7 +108,7 @@ class OC_Calendar_Object{ $object_id = OCP\DB::insertid('*PREFIX*calendar_objects'); OC_Calendar_Calendar::touchCalendar($id); - + OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id); return $object_id; } @@ -128,7 +128,7 @@ class OC_Calendar_Object{ $object_id = OCP\DB::insertid('*PREFIX*calendar_objects'); OC_Calendar_Calendar::touchCalendar($id); - + OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id); return $object_id; } @@ -149,6 +149,7 @@ class OC_Calendar_Object{ $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$id)); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); + OCP\Util::emitHook('OC_Calendar', 'editEvent', $id); return true; } @@ -170,6 +171,7 @@ class OC_Calendar_Object{ $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$oldobject['id'])); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); + OCP\Util::emitHook('OC_Calendar', 'editEvent', $oldobject['id']); return true; } @@ -184,6 +186,7 @@ class OC_Calendar_Object{ $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE id = ?' ); $stmt->execute(array($id)); OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']); + OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $id); return true; } @@ -195,9 +198,11 @@ class OC_Calendar_Object{ * @return boolean */ public static function deleteFromDAVData($cid,$uri){ + $oldobject = self::findWhereDAVDataIs($cid, $uri); $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*calendar_objects WHERE calendarid = ? AND uri=?' ); $stmt->execute(array($cid,$uri)); OC_Calendar_Calendar::touchCalendar($cid); + OCP\Util::emitHook('OC_Calendar', 'deleteEvent', $oldobject['id']); return true; } @@ -207,6 +212,7 @@ class OC_Calendar_Object{ $stmt->execute(array($calendarid,$id)); OC_Calendar_Calendar::touchCalendar($id); + OCP\Util::emitHook('OC_Calendar', 'moveEvent', $id); return true; } @@ -294,12 +300,11 @@ class OC_Calendar_Object{ * This function creates a date string that can be used by MDB2. * Furthermore it converts the time to UTC. */ - protected static function getUTCforMDB($datetime){ + public static function getUTCforMDB($datetime){ return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset()); } - public static function getDTEndFromVEvent($vevent) - { + public static function getDTEndFromVEvent($vevent){ if ($vevent->DTEND) { $dtend = $vevent->DTEND; }else{ @@ -796,4 +801,29 @@ class OC_Calendar_Object{ $event = self::find($id); return $event['calendarid']; } + + public static function isrepeating($id){ + $event = self::find($id); + return ($event['repeating'] == 1)?true:false; + } + + public static function generateStartEndDate($dtstart, $dtend, $allday, $tz){ + $start_dt = $dtstart->getDateTime(); + $end_dt = $dtend->getDateTime(); + $return = array(); + if($allday){ + $return['start'] = $start_dt->format('Y-m-d'); + $end_dt->modify('-1 minute'); + while($start_dt->format('U') >= $end_dt->format('U')){ + $end_dt->modify('+1 day'); + } + $return['end'] = $end_dt->format('Y-m-d'); + }else{ + $start_dt->setTimezone(new DateTimeZone($tz)); + $end_dt->setTimezone(new DateTimeZone($tz)); + $return['start'] = $start_dt->format('Y-m-d H:i:s'); + $return['end'] = $end_dt->format('Y-m-d H:i:s'); + } + return $return; + } } diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php new file mode 100644 index 00000000000..204f96a5a2a --- /dev/null +++ b/apps/calendar/lib/repeat.php @@ -0,0 +1,204 @@ +<?php +/** + * Copyright (c) 2012 Georg Ehrke <ownclouddev@georgswebsite.de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +/* + * This class manages the caching of repeating events + * Events will be cached for the current year ± 5 years + */ +class OC_Calendar_Repeat{ + /* + * @brief returns the cache of an event + * @param (int) $id - id of the event + * @return (array) + */ + public static function get($id){ + $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*calendar_repeat WHERE eventid = ?'); + $result = $stmt->execute(array($id)); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; + } + /* + * @brief returns the cache of an event in a specific peroid + * @param (int) $id - id of the event + * @param (DateTime) $from - start for period in UTC + * @param (DateTime) $until - end for period in UTC + * @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, + OC_Calendar_Object::getUTCforMDB($from), OC_Calendar_Object::getUTCforMDB($until), + OC_Calendar_Object::getUTCforMDB($from), OC_Calendar_Object::getUTCforMDB($until))); + $return = array(); + while($row = $result->fetchRow()){ + $return[] = $row; + } + return $return; + } + /* + * @brief returns the cache of all repeating events of a calendar + * @param (int) $id - id of the calendar + * @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('01-01-' . date('Y') . ' 00:00:00', new DateTimeZone('UTC')); + $start->modify('-5 years'); + $end = new DateTime('31-12-' . date('Y') . ' 23:59:59', new DateTimeZone('UTC')); + $end->modify('+5 years'); + $object->expand($start, $end); + foreach($object->getComponents() as $vevent){ + if(!($vevent instanceof Sabre_VObject_Component_VEvent)){ + continue; + } + $startenddate = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), ($vevent->DTSTART->getDateType() == Sabre_VObject_Element_DateTime::DATE)?true:false, 'UTC'); + $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)'); + $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startenddate['start'],$startenddate['end'])); + } + return true; + } + /* + * @brief generates the cache the first time for all repeating event of an calendar + * @param (int) id - id of the calendar + * @return (bool) + */ + public static function generateCalendar($id){ + $allobjects = OC_Calendar_Object::all($id); + foreach($allobjects as $event){ + self::generate($event['id']); + } + return true; + } + /* + * @brief updates an event that is already cached + * @param (int) id - id of the event + * @return (bool) + */ + public static function update($id){ + self::clean($id); + self::generate($id); + return true; + } + /* + * @brief updates all repating events of a calendar that are already cached + * @param (int) id - id of the calendar + * @return (bool) + */ + public static function updateCalendar($id){ + self::cleanCalendar($id); + self::generateCalendar($id); + return true; + } + /* + * @brief checks if an event is already cached + * @param (int) id - id of the event + * @return (bool) + */ + public static function is_cached($id){ + if(count(self::get($id)) != 0){ + return true; + }else{ + return false; + } + } + /* + * @brief checks if an event is already cached in a specific period + * @param (int) id - id of the event + * @param (DateTime) $from - start for period in UTC + * @param (DateTime) $until - end for period in UTC + * @return (bool) + */ + public static function is_cached_inperiod($id, $start, $end){ + if(count(self::get_inperiod($id, $start, $end)) != 0){ + return true; + }else{ + return false; + } + + } + /* + * @brief checks if a whole calendar is already cached + * @param (int) id - id of the calendar + * @return (bool) + */ + public static function is_calendar_cached($id){ + $cachedevents = count(self::getCalendar($id)); + $repeatingevents = 0; + $allevents = OC_Calendar_Object::all($id); + foreach($allevents as $event){ + if($event['repeating'] === 1){ + $repeatingevents++; + } + } + if($cachedevents < $repeatingevents){ + return false; + }else{ + return true; + } + } + /* + * @brief removes the cache of an event + * @param (int) id - id of the event + * @return (bool) + */ + public static function clean($id){ + $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*calendar_repeat WHERE eventid = ?'); + $stmt->execute(array($id)); + } + /* + * @brief removes the cache of all events of a calendar + * @param (int) id - id of the calendar + * @return (bool) + */ + public static function cleanCalendar($id){ + $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*calendar_repeat WHERE calid = ?'); + $stmt->execute(array($id)); + } +}
\ No newline at end of file diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php index feb06655120..6d018f15110 100644 --- a/apps/calendar/templates/settings.php +++ b/apps/calendar/templates/settings.php @@ -1,7 +1,7 @@ <?php /** * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> - * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -44,7 +44,11 @@ </select> </td></tr> - </table> + <tr><td><label for="" class="bold"><?php echo $l->t('Cache');?></label></td><td> + <input id="cleancalendarcache" type="button" class="button" value="<?php echo $l->t('Clear cache for repeating events');?>"> + </td></tr> + + </table> <?php echo $l->t('Calendar CalDAV syncing addresses'); ?> (<a href="http://owncloud.org/synchronisation/" target="_blank"><?php echo $l->t('more info'); ?></a>) <dl> |