From 15ee25376aed7339fe1cfde2159d00fc29cdcdc1 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 18 Jun 2008 22:09:41 +1200 Subject: [PATCH] Further refinement to selection of REPORT items. --- inc/caldav-REPORT-calquery.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php index 4c63eb6e..b411403f 100644 --- a/inc/caldav-REPORT-calquery.php +++ b/inc/caldav-REPORT-calquery.php @@ -119,11 +119,20 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter = $finish_column = 'dtstart'; // The column we compare against the END attribute $start = $v->GetAttribute("START"); $finish = $v->GetAttribute("END"); - if ( isset($start) ) { + if ( isset($start) && isset($finish) ) { + $sql .= sprintf( "AND ( (%s >= %s::timestamp with time zone AND %s <= %s::timestamp with time zone) ", + $start_column, qpg($start), $finish_column, qpg($finish)); + $sql .= sprintf( "OR (calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone ", qpg($start), $start_column, qpg($start) ); + $sql .= sprintf( "AND calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone ", qpg($finish), $finish_column, qpg($finish) ); + $sql .= sprintf( "AND calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= ", qpg($start), $start_column ); + $sql .= sprintf( " calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) ) ", qpg($finish), $finish_column ); + $sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) ) " ); + } + else if ( isset($start) ) { $sql .= sprintf( "AND (%s >= %s::timestamp with time zone ", $start_column, qpg($start)); $sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone) ", qpg($start), $start_column, qpg($start) ); } - if ( isset( $report[$i]['end'] ) ) { + else if ( isset( $finish ) ) { $sql .= sprintf( "AND %s <= %s::timestamp with time zone ", $finish_column, qpg($finish) ); } break; @@ -264,5 +273,3 @@ if ( $qry->Exec("calquery",__LINE__,__FILE__) && $qry->rows > 0 ) { $multistatus = new XMLElement( "multistatus", $responses, array('xmlns'=>'DAV:') ); $request->XMLResponse( 207, $multistatus ); - -?> \ No newline at end of file