"more RECURRENCE-ID stuff:

- disabling it on import, as we cant overwrite a cal_id with a timestamp
- fixing it on export, finding the closest exception to return it
- using array_merge to merge virtual and real exceptions, as + overwrites numeric keys"
This commit is contained in:
Ralf Becker 2009-07-17 12:08:45 +00:00
parent 81a4097818
commit 86db825cbf

View File

@ -137,7 +137,8 @@ class calendar_ical extends calendar_boupdate
* *
* @param array $_clientProperties client properties * @param array $_clientProperties client properties
*/ */
function __construct(&$_clientProperties = array()) { function __construct(&$_clientProperties = array())
{
parent::__construct(); parent::__construct();
$this->clientProperties = $_clientProperties; $this->clientProperties = $_clientProperties;
@ -456,6 +457,9 @@ class calendar_ical extends calendar_boupdate
case 'EXDATE': case 'EXDATE':
if ($event['recur_type'] == MCAL_RECUR_NONE) break; if ($event['recur_type'] == MCAL_RECUR_NONE) break;
$days = array(); $days = array();
// dont use "virtual" exceptions created by participant status for GroupDAV or file export
if (!in_array($this->productManufacturer,array('file','groupdav')))
{
$participants = $this->so->get_participants($event['id'], 0); $participants = $this->so->get_participants($event['id'], 0);
// Check if the stati for all participants are identical for all recurrences // Check if the stati for all participants are identical for all recurrences
@ -480,9 +484,10 @@ class calendar_ical extends calendar_boupdate
break; break;
} }
} }
}
if (is_array($event['recur_exception'])) if (is_array($event['recur_exception']))
{ {
$days = $days + $event['recur_exception']; $days = array_merge($days,$event['recur_exception']); // can NOT use +, as it overwrites numeric indexes
} }
if (!empty($days)) if (!empty($days))
{ {
@ -569,11 +574,24 @@ class calendar_ical extends calendar_boupdate
elseif ($event['reference']) elseif ($event['reference'])
{ {
// $event['reference'] is a calendar_id, not a timestamp // $event['reference'] is a calendar_id, not a timestamp
$revent = $this->read($event['reference']); if (!($revent = $this->read($event['reference']))) break; // referenced event does not exist
// find recur_exception closest to $event['start'],
// as our db-model does NOT store for which recurrence the exception is
$exception_start = $exception_diff = null;
foreach($revent['recur_exception'] as $exception)
{
if (!isset($exception_start) || $exception_diff > abs($exception-$event['start']))
{
$exception_start = $exception;
$exception_diff = abs($exception-$event['start']);
}
}
if (!isset($exception_start)) break; // referenced event has no exception
if ($this->isWholeDay($revent)) if ($this->isWholeDay($revent))
{ {
$arr = $this->date2array($revent['start']); $arr = $this->date2array($exception_start);
$vevent->setAttribute('RECURRENCE-ID', array( $vevent->setAttribute('RECURRENCE-ID', array(
'year' => $arr['year'], 'year' => $arr['year'],
'month' => $arr['month'], 'month' => $arr['month'],
@ -585,11 +603,11 @@ class calendar_ical extends calendar_boupdate
{ {
if ($servertime) if ($servertime)
{ {
$attributes['RECURRENCE-ID'] = date('Ymd\THis', $revent['start']); $attributes['RECURRENCE-ID'] = date('Ymd\THis', $exception_start);
} }
else else
{ {
$attributes['RECURRENCE-ID'] = $revent['start']; $attributes['RECURRENCE-ID'] = $exception_start;
} }
} }
unset($revent); unset($revent);
@ -778,6 +796,7 @@ class calendar_ical extends calendar_boupdate
$Ok = false; // returning false, if file contains no components $Ok = false; // returning false, if file contains no components
$vcal = new Horde_iCalendar; $vcal = new Horde_iCalendar;
error_log(__LINE__.__METHOD__.__FILE__.print_r($_vcalData,true));
if (!$vcal->parsevCalendar($_vcalData)) if (!$vcal->parsevCalendar($_vcalData))
{ {
return $Ok; return $Ok;
@ -822,7 +841,7 @@ class calendar_ical extends calendar_boupdate
if ($event['recur_type'] != MCAL_RECUR_NONE) if ($event['recur_type'] != MCAL_RECUR_NONE)
{ {
// No RECCURENCE-ID for series events // No RECURRENCE-ID for series events
$event['reference'] = 0; $event['reference'] = 0;
} }
@ -1528,7 +1547,9 @@ class calendar_ical extends calendar_boupdate
$vcardData['end'] = $dtend_ts; $vcardData['end'] = $dtend_ts;
break; break;
case 'RECURRENCE-ID': case 'RECURRENCE-ID':
$vcardData['reference'] = $attributes['value']; // event['reference'] is a cal_id, not a date!
// setting it to a date makes no sense, not setting it keeps an existing correct reference
//$vcardData['reference'] = $attributes['value'];
break; break;
case 'LOCATION': case 'LOCATION':
$vcardData['location'] = $attributes['value']; $vcardData['location'] = $attributes['value'];