From 3f108b9144f73fb301435a5a3a9b336a2911c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Tue, 9 Mar 2010 17:03:52 +0000 Subject: [PATCH] Improve find_event() --- calendar/inc/class.calendar_boupdate.inc.php | 128 +++++++++---------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index 6a98f10862..3a2afc3a47 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1196,8 +1196,6 @@ class calendar_boupdate extends calendar_bo if ($filter == 'master') { - // No chance to find a master without [U]ID - if (emtpy($event['uid']) && empty($event['id'])) return $matchingEvents; $query[] = 'recur_type!='. MCAL_RECUR_NONE; $query['cal_reference'] = 0; } @@ -1249,6 +1247,9 @@ class calendar_boupdate extends calendar_bo } unset($event['id']); + // No chance to find a master without [U]ID + if ($filter == 'master' && empty($event['uid'])) return $matchingEvents; + // only query calendars of users, we have READ-grants from $users = array(); foreach(array_keys($this->grants) as $user) @@ -1336,7 +1337,15 @@ class calendar_boupdate extends calendar_bo $query[] = ('cal_start<' . ($event['start'] + 2)); } } - $matchFields = array('priority', 'public', 'non_blocking', 'reference'); + if ($filter == 'relax') + { + $matchFields = array(); + } + else + { + $matchFields = array('priority', 'public', 'non_blocking'); + } + $matchFields[] = 'reference'; foreach ($matchFields as $key) { if (isset($event[$key])) $query['cal_'.$key] = $event[$key]; @@ -1407,7 +1416,7 @@ class calendar_boupdate extends calendar_bo continue; } - if (!empty($event['uid']) && $filter == 'exact') break; + if (!empty($event['uid']) && $filter == 'exact' || $filter == 'master') break; // check times if ($filter != 'relax') @@ -1424,7 +1433,7 @@ class calendar_boupdate extends calendar_bo continue; } } - elseif ($filter != 'master') + else { if (abs($event['end'] - $egwEvent['end']) >= 120) { @@ -1439,15 +1448,10 @@ class calendar_boupdate extends calendar_bo } // check for real match - $matchFields = array('title'); - switch ($filter) + $matchFields = array('title', 'description'); + if ($filter != 'relax') { - case 'master': - break; - case 'relax': - $matchFields[] = 'location'; - default: - $matchFields[] = 'description'; + $matchFields[] = 'location'; } foreach ($matchFields as $key) { @@ -1464,7 +1468,7 @@ class calendar_boupdate extends calendar_bo } } - if ($filter != 'master' && is_array($event['category'])) + if (is_array($event['category'])) { // check categories $egwCategories = explode(',', $egwEvent['category']); @@ -1493,7 +1497,7 @@ class calendar_boupdate extends calendar_bo } } - if ($filter != 'relax' && $filter != 'master') + if ($filter != 'relax') { // check participants if (is_array($event['participants'])) @@ -1531,73 +1535,69 @@ class calendar_boupdate extends calendar_bo } } - if ($filter != 'master') + if ($event['recur_type'] == MCAL_RECUR_NONE) { - if ($event['recur_type'] == MCAL_RECUR_NONE) + if ($egwEvent['recur_type'] != MCAL_RECUR_NONE) { - if ($egwEvent['recur_type'] != MCAL_RECUR_NONE) - { - // We found a pseudo Exception - $start = $this->date2ts($event['start'], true); - $pseudos[] = $egwEvent['id'] . ':' . $start; - continue; - } + // We found a pseudo Exception + $start = $this->date2ts($event['start'], true); + $pseudos[] = $egwEvent['id'] . ':' . $start; + continue; } - elseif ($filter != 'relax') + } + elseif ($filter != 'relax') + { + // check exceptions + // $exceptions[$remote_ts] = $egw_ts + $exceptions = $this->so->get_recurrence_exceptions($egwEvent); + $exceptions = array_merge($egwEvent['recur_exception'], $exceptions); + if (is_array($event['recur_exception'])) { - // check exceptions - // $exceptions[$remote_ts] = $egw_ts - $exceptions = $this->so->get_recurrence_exceptions($egwEvent); - $exceptions = array_merge($egwEvent['recur_exception'], $exceptions); - if (is_array($event['recur_exception'])) + foreach ($event['recur_exception'] as $key => $day) { - foreach ($event['recur_exception'] as $key => $day) + if (isset($exceptions[$day])) { - if (isset($exceptions[$day])) - { - unset($exceptions[$day]); - } - else - { - if ($this->log) - { - error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. - "() additional event['recur_exception']: $day"); - } - continue 2; - } + unset($exceptions[$day]); } - if (!empty($exceptions)) + else { if ($this->log) { error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. - '() missing event[recur_exception]: ' . - array2string($event['recur_exception'])); - } - continue; - } - } - - // check recurrence information - foreach (array('recur_type', 'recur_interval', 'recur_enddate') as $key) - { - if (isset($event[$key]) - && $event[$key] != $egwEvent[$key]) - { - if ($this->log) - { - error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. - "() events[$key] differ: " . $event[$key] . - ' <> ' . $egwEvent[$key]); + "() additional event['recur_exception']: $day"); } continue 2; } } + if (!empty($exceptions)) + { + if ($this->log) + { + error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. + '() missing event[recur_exception]: ' . + array2string($event['recur_exception'])); + } + continue; + } + } + + // check recurrence information + foreach (array('recur_type', 'recur_interval', 'recur_enddate') as $key) + { + if (isset($event[$key]) + && $event[$key] != $egwEvent[$key]) + { + if ($this->log) + { + error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. + "() events[$key] differ: " . $event[$key] . + ' <> ' . $egwEvent[$key]); + } + continue 2; + } } } $matchingEvents[] = $egwEvent['id']; // exact match - if ($filter = 'master') break; } // append pseudos as last entries $matchingEvents = array_merge($matchingEvents, $pseudos);