summaryrefslogtreecommitdiffstats
path: root/apps/calendar
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-08-23 21:42:15 +0200
committerJakob Sack <kde@jakobsack.de>2011-08-23 21:42:15 +0200
commit84761b1518c54e9f43eae3a831c9456c0daad3ca (patch)
tree4214e37f0c401919b92ea2796c7ac85579f4209c /apps/calendar
parentcdf0d010ebe31b3f81a8d3070e674193046e360e (diff)
downloadnextcloud-server-84761b1518c54e9f43eae3a831c9456c0daad3ca.tar.gz
nextcloud-server-84761b1518c54e9f43eae3a831c9456c0daad3ca.zip
CalDAV seems to work now
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/lib/calendar.php110
1 files changed, 69 insertions, 41 deletions
diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php
index 1bd203151cf..5e93d784a89 100644
--- a/apps/calendar/lib/calendar.php
+++ b/apps/calendar/lib/calendar.php
@@ -166,26 +166,18 @@ class OC_Calendar_Calendar{
public static function addCalendarObject($id,$data){
$object = Sabre_VObject_Reader::read($data);
- list($startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
+ list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
- $uri = null;
- if(is_null($uri)){
+ if(is_null($uid)){
$uid = self::createUID();
$object->add('UID',$uid);
$data = $object->serialize();
- $uri = $uid.'.ics';
- }
- else{
- $uri = $uid.'.ics';
}
- $start = is_null($startdate)?null:$startdate->format('Y-m-d H:i:s');
- $end = is_null($enddate)?null:$enddate->format('Y-m-d H:i:s');
- $type = $object->name;
- $time = time();
-
+ $uri = 'owncloud-'.md5($data.rand().time()).'.ics';
+
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' );
- $result = $stmt->execute(array($id,$type,$start,$end,$repeating,$summary,$data,$uri,$time));
+ $result = $stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time()));
self::touchCalendar($id);
@@ -194,16 +186,10 @@ class OC_Calendar_Calendar{
public static function addCalendarObjectFromDAVData($id,$uri,$data){
$object = Sabre_VObject_Reader::read($data);
- list($startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
-
- $start = is_null($startdate)?null:$startdate->format('Y-m-d H:i:s');
- $end = is_null($enddate)?null:$enddate->format('Y-m-d H:i:s');
- $type = $object->name;
- $time = time();
+ list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)' );
- // $result = $stmt->execute(array($id,$type,$start,$end,$repeating,$summary,$data,$uri,$time));
- $result = $stmt->execute(array($id,$type,'2011-08-17 14:00:00','2011-08-17 15:00:00',0,'baum',$data,$uri,$time));
+ $result = $stmt->execute(array($id,$type,$startdate,$enddate,$repeating,$summary,$data,$uri,time()));
self::touchCalendar($id);
@@ -214,10 +200,10 @@ class OC_Calendar_Calendar{
$oldobject = self::findCard($id);
$object = Sabre_VObject_Reader::read($data);
- list($startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
+ list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
- $result = $stmt->execute(array($object->name,(is_null($startdate)?null:$startdate->format('Y-m-d H:i:s')),(is_null($enddate)?null:$enddate->format('Y-m-d H:i:s')),$repeating,$summary,$data,time(),$id));
+ $result = $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$id));
self::touchCalendar($id);
@@ -228,10 +214,10 @@ class OC_Calendar_Calendar{
$oldobject = self::findCardWhereDAVDataIs($cid,$uri);
$object = Sabre_VObject_Reader::read($data);
- list($startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
+ list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
- $result = $stmt->execute(array($object->name,(is_null($startdate)?null:$startdate->format('Y-m-d H:i:s')),(is_null($enddate)?null:$enddate->format('Y-m-d H:i:s')),$repeating,$summary,$data,time(),$oldobject['id']));
+ $result = $stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$oldobject['id']));
self::touchCalendar($oldobject['calendarid']);
@@ -273,24 +259,66 @@ class OC_Calendar_Calendar{
}
protected static function extractData($object){
- $return = array(null,null,'',false,null);
- foreach($object->children as $property){
- if($property->name == 'DTSTART'){
- $return[0] = $property->getDateTime();
- }
- elseif($property->name == 'DTEND'){
- $return[1] = $property->getDateTime();
- }
- elseif($property->name == 'SUMMARY'){
- $return[2] = $property->value;
- }
- elseif($property->name == 'RRULE'){
- $return[3] = true;
- }
- elseif($property->name == 'UID'){
- $return[4] = $property->value;
+ $return = array('',null,null,'',0,null);
+
+ // Child to use
+ $children = 0;
+ $use = null;
+ foreach($object->children as &$property){
+ if($property->name == 'VEVENT'){
+ $children++;
+ $thisone = true;
+
+ foreach($property->children as &$element){
+ if($element->name == 'RECURRENCE-ID'){
+ $thisone = false;
+ }
+ } unset($element);
+
+ if($thisone){
+ $use = $property;
+ }
}
+ } unset($property);
+
+ // find the data
+ if(!is_null($use)){
+ $return[0] = $use->name;
+ foreach($use->children as &$property){
+ if($property->name == 'DTSTART'){
+ $return[1] = self::getUTCforMDB($property->getDateTime());
+ }
+ elseif($property->name == 'DTEND'){
+ $return[2] = self::getUTCforMDB($property->getDateTime());
+ }
+ elseif($property->name == 'SUMMARY'){
+ $return[3] = $property->value;
+ }
+ elseif($property->name == 'RRULE'){
+ $return[4] = 1;
+ }
+ elseif($property->name == 'UID'){
+ $return[5] = $property->value;
+ }
+ } unset($property);
+ }
+
+ // More than one child means reoccuring!
+ if($children > 1){
+ $return[4] = 1;
}
return $return;
}
+
+ /**
+ * @brief DateTime to UTC string
+ * @param DateTime $datetime The date to convert
+ * @returns date as YYYY-MM-DD hh:mm
+ *
+ * This function creates a date string that can be used by MDB2.
+ * Furthermore it converts the time to UTC.
+ */
+ protected static function getUTCforMDB($datetime){
+ return date('Y-m-d H:i', $datetime->format('U') - $datetime->getOffset());
+ }
}