mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-08-29 18:26:05 +00:00
Switch to using RRule SQL functions.
This commit is contained in:
parent
eccffa0502
commit
fd4639aba0
@ -119,20 +119,8 @@ 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) && isset($finish) ) {
|
||||
$sql .= sprintf( "AND ( (%s >= %s::timestamp with time zone AND %s <= %s::timestamp with time zone) ",
|
||||
$finish_column, qpg($start), $start_column, qpg($finish));
|
||||
$sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) <= %s::timestamp with time zone ", 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($finish) );
|
||||
$sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) )" );
|
||||
}
|
||||
else if ( isset($start) ) {
|
||||
$sql .= sprintf( "AND (%s >= %s::timestamp with time zone ", $finish_column, qpg($start));
|
||||
$sql .= sprintf( "OR calculate_later_timestamp(%s::timestamp with time zone,%s,rrule) >= %s::timestamp with time zone ", qpg($start), $finish_column, qpg($start) );
|
||||
$sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) )" );
|
||||
}
|
||||
else if ( isset( $finish ) ) {
|
||||
$sql .= sprintf( "AND (%s <= %s::timestamp with time zone ", $start_column, qpg($finish) );
|
||||
if ( isset($start) || isset($finish) ) {
|
||||
$sql .= "AND (rrule_event_overlaps( dtstart, dtend, rrule, ".qpg($start).", ".qpg($finish)." ) ";
|
||||
$sql .= sprintf( "OR event_has_exceptions(caldav_data.caldav_data) )" );
|
||||
}
|
||||
break;
|
||||
|
||||
@ -13,13 +13,7 @@ if ( ! ( isset($fbq_start) || isset($fbq_end) ) ) {
|
||||
$request->DoResponse( 400, 'All valid freebusy requests MUST contain a time-range filter' );
|
||||
}
|
||||
$where = " WHERE caldav_data.dav_name ~ ? ";
|
||||
if ( isset( $fbq_start ) ) {
|
||||
$where .= "AND (dtend >= ".qpg($fbq_start)."::timestamp with time zone ";
|
||||
$where .= "OR calculate_later_timestamp(".qpg($fbq_start)."::timestamp with time zone,dtend,rrule) >= ".qpg($fbq_start)."::timestamp with time zone) ";
|
||||
}
|
||||
if ( isset( $fbq_end ) ) {
|
||||
$where .= "AND dtstart <= ".qpg($fbq_end)."::timestamp with time zone ";
|
||||
}
|
||||
$where .= "AND rrule_event_overlaps( dtstart, dtend, rrule, ".qpg($fbq_start).", ".qpg($fbq_end)." ) ";
|
||||
$where .= "AND caldav_data.caldav_type IN ( 'VEVENT', 'VFREEBUSY' ) ";
|
||||
$where .= "AND (calendar_item.transp != 'TRANSPARENT' OR calendar_item.transp IS NULL) ";
|
||||
$where .= "AND (calendar_item.status != 'CANCELLED' OR calendar_item.status IS NULL) ";
|
||||
|
||||
@ -6,16 +6,12 @@ include_once("RRule.php");
|
||||
* We need to allow GET of start & finish so we can have a consistent regression test result set. And it might be useful
|
||||
* to people as well...
|
||||
*/
|
||||
if ( isset($_GET['start']) && preg_match( '/^[12][0-9]{3}(0[0-9]|1[012])[0123][0-9]T[0-2][0-9]([0-5][0-9]){2}$/', $_GET['start'] )) {
|
||||
$start = $_GET['start'];
|
||||
}
|
||||
else {
|
||||
param_to_global('start', '/^[12][0-9]{3}(0[0-9]|1[012])[0123][0-9]T[0-2][0-9]([0-5][0-9]){2}$/' );
|
||||
if ( !isset($start) ) {
|
||||
$start = date( "Ymd\THis", time() - (86400 * 30) );
|
||||
}
|
||||
if ( isset($_GET['finish']) && preg_match( '/^[12][0-9]{3}(0[0-9]|1[012])[0123][0-9]T[0-2][0-9]([0-5][0-9]){2}$/', $_GET['finish'] )) {
|
||||
$finish = $_GET['finish'];
|
||||
}
|
||||
else {
|
||||
param_to_global('finish', '/^[12][0-9]{3}(0[0-9]|1[012])[0123][0-9]T[0-2][0-9]([0-5][0-9]){2}$/' );
|
||||
if ( !isset($finish) ) {
|
||||
$finish = date( "Ymd\THis", time() + (86400 * 200) );
|
||||
}
|
||||
|
||||
@ -25,8 +21,7 @@ if ( isset($request->by_email) ) {
|
||||
else {
|
||||
$where = "WHERE caldav_data.user_no = $request->user_no AND caldav_data.dav_name ~ ".qpg("^".$request->path)." ";
|
||||
}
|
||||
$where .= "AND (dtend >= '$start'::timestamp with time zone OR calculate_later_timestamp('$start'::timestamp with time zone,dtend,rrule) >= '$start'::timestamp with time zone) ";
|
||||
$where .= "AND dtstart <= '$finish'::timestamp with time zone ";
|
||||
$where .= "AND rrule_event_overlaps( dtstart, dtend, rrule, ".qpg($start).", ".qpg($finish)." ) ";
|
||||
$where .= "AND caldav_data.caldav_type IN ( 'VEVENT', 'VFREEBUSY' ) ";
|
||||
$where .= "AND (calendar_item.transp != 'TRANSPARENT' OR calendar_item.transp IS NULL) ";
|
||||
$where .= "AND (calendar_item.status != 'CANCELLED' OR calendar_item.status IS NULL) ";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user