Improved search for pseudo exceptions

This commit is contained in:
Jörg Lehrke 2010-03-03 22:21:35 +00:00
parent 8368344f0f
commit 9e0f73f0dc
2 changed files with 30 additions and 25 deletions

View File

@ -176,7 +176,7 @@ class calendar_bo
*/ */
function __construct() function __construct()
{ {
if ($this->debug > 0) $this->debug_message('bocal::bocal() started',True,$param); if ($this->debug > 0) $this->debug_message('bocal::bocal() started',true);
$this->so = new calendar_so(); $this->so = new calendar_so();
$this->datetime = $GLOBALS['egw']->datetime; $this->datetime = $GLOBALS['egw']->datetime;

View File

@ -1187,7 +1187,6 @@ class calendar_boupdate extends calendar_bo
{ {
$matchingEvents = array(); $matchingEvents = array();
$query = array(); $query = array();
$recur_date = 0;
if ($this->log) if ($this->log)
{ {
@ -1197,14 +1196,6 @@ class calendar_boupdate extends calendar_bo
if ($filter == 'master') if ($filter == 'master')
{ {
if (isset($event['reference']))
{
$recur_date = $event['reference'];
}
elseif (isset($event['start']))
{
$recur_date = $event['start'];
}
$query[] = 'recur_type!='. MCAL_RECUR_NONE; $query[] = 'recur_type!='. MCAL_RECUR_NONE;
$query['cal_reference'] = 0; $query['cal_reference'] = 0;
} }
@ -1218,29 +1209,41 @@ class calendar_boupdate extends calendar_bo
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'(' . $event['id'] . ")[EventID]"); '(' . $event['id'] . ")[EventID]");
} }
if (($egwEvent = $this->read($event['id'], $recur_date, false, 'server'))) if (($egwEvent = $this->read($event['id'], 0, false, 'server')))
{ {
if ($this->log) if ($this->log)
{ {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'()[FOUND]:' . array2string($egwEvent)); '()[FOUND]:' . array2string($egwEvent));
} }
// Just a simple consistency check
if ($filter == 'exact' ||
$filter == 'master' && $egwEvent['recur_type'] != MCAL_RECUR_NONE ||
$filter != 'master' && strpos($egwEvent['title'], $event['title']) === 0)
{
$retval = $egwEvent['id'];
if ($egwEvent['recur_type'] != MCAL_RECUR_NONE && if ($egwEvent['recur_type'] != MCAL_RECUR_NONE &&
$event['recur_type'] == MCAL_RECUR_NONE && $event['reference'] != 0) (empty($event['uid']) || $event['uid'] == $egwEvent['uid']))
{ {
$retval .= ':' . (int)$event['reference']; if ($filter == 'master')
{
$matchingEvents[] = $egwEvent['id']; // we found the master
} }
$matchingEvents[] = $retval; if ($event['recur_type'] == $egwEvent['recur_type'])
return $matchingEvents; {
$matchingEvents[] = $egwEvent['id']; // we found the event
}
elseif ($event['recur_type'] == MCAL_RECUR_NONE &&
$event['reference'] != 0)
{
$exceptions = $this->so->get_recurrence_exceptions($egwEvent);
if (in_array($event['reference'], $exceptions))
{
$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['reference'];
} }
} }
if ($filter == 'exact') return array(); } elseif ($event['recur_type'] == $egwEvent['recur_type'] &&
$filter != 'master' &&
strpos($egwEvent['title'], $event['title']) === 0)
{
$matchingEvents[] = $egwEvent['id']; // we found the event
}
}
if (!empty($matchingEvents) || $filter == 'exact') return $matchingEvents;
} }
unset($event['id']); unset($event['id']);
@ -1382,7 +1385,7 @@ class calendar_boupdate extends calendar_bo
$matchingEvents[] = $egwEvent['id']; $matchingEvents[] = $egwEvent['id'];
break; break;
} }
if (!$egwEvent['reference']) if (!$egwEvent['reference'] && $event['reference'])
{ {
// We found the master // We found the master
if ($filter == 'master') if ($filter == 'master')
@ -1390,8 +1393,8 @@ class calendar_boupdate extends calendar_bo
$matchingEvents[] = $egwEvent['id']; $matchingEvents[] = $egwEvent['id'];
break; break;
} }
if (($egwEvent = $this->read($egwEvent['id'], $event['reference'], false, 'server')) $exceptions = $this->so->get_recurrence_exceptions($egwEvent);
&& $egwEvent['reference'] == $event['reference']) if (in_array($event['reference'], $exceptions))
{ {
// We found a pseudo exception // We found a pseudo exception
$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['reference']; $matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['reference'];
@ -1401,6 +1404,8 @@ class calendar_boupdate extends calendar_bo
continue; continue;
} }
if (!empty($event['uid']) && $filter == 'exact') beak;
// check times // check times
if ($filter != 'relax') if ($filter != 'relax')
{ {