From d3c4d9d2dedaee2b917190c3157287e7aa79a715 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 28 Feb 2010 11:38:18 +1300 Subject: [PATCH] Hook the expansion code into the calendar query report. --- inc/caldav-REPORT-calquery.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php index 675efdcf..5b3c202b 100644 --- a/inc/caldav-REPORT-calquery.php +++ b/inc/caldav-REPORT-calquery.php @@ -1,5 +1,21 @@ GetElements('urn:ietf:params:xml:ns:caldav:expand'); + if ( isset($expansion[0]) ) { + $need_expansion = true; + $expand_range_start = $expansion[0]->GetAttribute('start'); + $expand_range_end = $expansion[0]->GetAttribute('end'); + if ( isset($expand_range_start) ) $expand_range_start = new RepeatRuleDateTime($expand_range_start); + if ( isset($expand_range_end) ) $expand_range_end = new RepeatRuleDateTime($expand_range_end); + } +} + /** * Build the array of properties to include in the report output */ @@ -8,15 +24,23 @@ $proptype = $qry_content[0]->GetTag(); $properties = array(); switch( $proptype ) { case 'DAV::prop': - $qry_props = $xmltree->GetPath('/urn:ietf:params:xml:ns:caldav:calendar-query/DAV::prop/*'); - foreach( $qry_props AS $k => $v ) { + $qry_props = $xmltree->GetPath('/urn:ietf:params:xml:ns:caldav:calendar-query/'.$proptype.'/*'); + foreach( $qry_content[0]->GetElements() AS $k => $v ) { $propertyname = preg_replace( '/^.*:/', '', $v->GetTag() ); $properties[$propertyname] = 1; + if ( $v->GetTag() == 'calendar-data' ) check_for_expansion($v); } break; case 'DAV::allprop': $properties['allprop'] = 1; + if ( $qry_content[1]->GetTag() == 'DAV::include' ) { + foreach( $qry_content[1]->GetElements() AS $k => $v ) { + $propertyname = preg_replace( '/^.*:/', '', $v->GetTag() ); + $properties[$propertyname] = 1; + if ( $v->GetTag() == 'urn:ietf:params:xml:ns:caldav:calendar-data' ) check_for_expansion($v); + } + } break; default: @@ -201,6 +225,10 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter = $success = SqlFilterFragment( $subfilter, $components, $property, $parameter ); if ( $success === false ) continue; else $sql .= $success; break; + + default: + dbg_error_log("calquery", "Could not handle unknown tag '%s' in calendar query report", $tag ); + break; } } dbg_error_log("calquery", "Generated SQL was '%s'", $sql ); @@ -260,6 +288,7 @@ $qry = new PgQuery( $sql ); if ( $qry->Exec("calquery",__LINE__,__FILE__) && $qry->rows > 0 ) { while( $calendar_object = $qry->Fetch() ) { if ( !$need_post_filter || apply_filter( $qry_filters, $calendar_object ) ) { + if ( $need_expansion ) expand_event_instances($ics, $expand_range_start, $expand_range_end); $responses[] = calendar_to_xml( $properties, $calendar_object ); } }