added support for recuring events for ical version 1.0

This commit is contained in:
Lars Kneschke 2006-03-09 16:49:56 +00:00
parent 6bdaedcd38
commit 1f782cf644

View File

@ -29,6 +29,16 @@
*/ */
var $supportedFields; var $supportedFields;
var $recur_days_1_0 = array(
MCAL_M_MONDAY => 'MO',
MCAL_M_TUESDAY => 'TU',
MCAL_M_WEDNESDAY => 'WE',
MCAL_M_THURSDAY => 'TH',
MCAL_M_FRIDAY => 'FR',
MCAL_M_SATURDAY => 'SA',
MCAL_M_SUNDAY => 'SU',
);
/** /**
* @var array $status_egw2ical conversation of the participant status egw => ical * @var array $status_egw2ical conversation of the participant status egw => ical
*/ */
@ -68,9 +78,9 @@
); );
/** /**
* @var array $recur_egw2ical converstaion of egw recur-type => ical FREQ * @var array $recur_egw2ical_2_0 converstaion of egw recur-type => ical FREQ
*/ */
var $recur_egw2ical = array( var $recur_egw2ical_2_0 = array(
MCAL_RECUR_DAILY => 'DAILY', MCAL_RECUR_DAILY => 'DAILY',
MCAL_RECUR_WEEKLY => 'WEEKLY', MCAL_RECUR_WEEKLY => 'WEEKLY',
MCAL_RECUR_MONTHLY_MDAY => 'MONTHLY', // BYMONHTDAY={1..31} MCAL_RECUR_MONTHLY_MDAY => 'MONTHLY', // BYMONHTDAY={1..31}
@ -78,6 +88,17 @@
MCAL_RECUR_YEARLY => 'YEARLY', MCAL_RECUR_YEARLY => 'YEARLY',
); );
/**
* @var array $recur_egw2ical_1_0 converstaion of egw recur-type => ical FREQ
*/
var $recur_egw2ical_1_0 = array(
MCAL_RECUR_DAILY => 'D',
MCAL_RECUR_WEEKLY => 'W',
MCAL_RECUR_MONTHLY_MDAY => 'MD', // BYMONHTDAY={1..31}
MCAL_RECUR_MONTHLY_WDAY => 'MP', // BYDAY={1..5}{MO..SO}
MCAL_RECUR_YEARLY => 'YM',
);
/** /**
* Exports one calendar event to an iCalendar item * Exports one calendar event to an iCalendar item
* *
@ -100,7 +121,7 @@
'EXDATE' => array('dbName' => 'recur_exception'), 'EXDATE' => array('dbName' => 'recur_exception'),
'PRIORITY' => array('dbName' => 'priority'), 'PRIORITY' => array('dbName' => 'priority'),
'TRANSP' => array('dbName' => 'non_blocking'), 'TRANSP' => array('dbName' => 'non_blocking'),
'CATEGORIES'=> array('dbName' => 'category'), 'CATEGORIES' => array('dbName' => 'category'),
); );
if(!is_array($this->supportedFields)) if(!is_array($this->supportedFields))
{ {
@ -182,7 +203,35 @@
case 'RRULE': case 'RRULE':
if ($event['recur_type'] == MCAL_RECUR_NONE) break; // no recuring event if ($event['recur_type'] == MCAL_RECUR_NONE) break; // no recuring event
$rrule = array('FREQ' => $this->recur_egw2ical[$event['recur_type']]); if ($version == '1.0') {
$interval = ($event['recur_interval'] > 1) ? $event['recur_interval'] : 1;
$rrule = array('FREQ' => $this->recur_egw2ical_1_0[$event['recur_type']].$interval);
switch ($event['recur_type'])
{
case MCAL_RECUR_WEEKLY:
$days = array();
foreach($this->recur_days_1_0 as $id => $day)
{
if ($event['recur_data'] & $id) $days[] = strtoupper(substr($day,0,2));
}
$rrule['BYDAY'] = implode(' ',$days);
$rrule['FREQ'] = $rrule['FREQ'].' '.$rrule['BYDAY'];
break;
case MCAL_RECUR_MONTHLY_MDAY: // date of the month: BYMONTDAY={1..31}
break;
case MCAL_RECUR_MONTHLY_WDAY: // weekday of the month: BDAY={1..5}{MO..SO}
$rrule['BYDAY'] = (1 + (int) ((date('d',$event['start'])-1) / 7)).'+ '.
strtoupper(substr(date('l',$event['start']),0,2));
$rrule['FREQ'] = $rrule['FREQ'].' '.$rrule['BYDAY'];
break;
}
$rrule['UNTIL'] = ($event['recur_enddate']) ? date('Ymd',$event['recur_enddate']) : '#0';
$attributes['RRULE'] = $rrule['FREQ'].' '.$rrule['UNTIL'];
} else {
$rrule = array('FREQ' => $this->recur_egw2ical_2_0[$event['recur_type']]);
switch ($event['recur_type']) switch ($event['recur_type'])
{ {
case MCAL_RECUR_WEEKLY: case MCAL_RECUR_WEEKLY:
@ -205,6 +254,7 @@
} }
if ($event['recur_interval'] > 1) $rrule['INTERVAL'] = $event['recur_interval']; if ($event['recur_interval'] > 1) $rrule['INTERVAL'] = $event['recur_interval'];
if ($event['recur_enddate']) $rrule['UNTIL'] = date('Ymd',$event['recur_enddate']); // only day is set in eGW if ($event['recur_enddate']) $rrule['UNTIL'] = date('Ymd',$event['recur_enddate']); // only day is set in eGW
// no idea how to get the Horde parser to produce a standard conformant // no idea how to get the Horde parser to produce a standard conformant
// RRULE:FREQ=... (note the double colon after RRULE, we cant use the $parameter array) // RRULE:FREQ=... (note the double colon after RRULE, we cant use the $parameter array)
// so we create one value manual ;-) // so we create one value manual ;-)
@ -213,6 +263,7 @@
$attributes['RRULE'][] = $name . '=' . $value; $attributes['RRULE'][] = $name . '=' . $value;
} }
$attributes['RRULE'] = implode(';',$attributes['RRULE']); $attributes['RRULE'] = implode(';',$attributes['RRULE']);
}
break; break;
case 'EXDATE': case 'EXDATE':
@ -381,16 +432,20 @@
{ {
$vcardData['recur_interval'] = $recurenceMatches[1]; $vcardData['recur_interval'] = $recurenceMatches[1];
$days = explode(' ',trim($recurenceMatches[2])); $days = explode(' ',trim($recurenceMatches[2]));
if($recurenceMatches[3] != '#0')
$vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[3]);
$recur_days = $this->recur_days_1_0;
} }
elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches)) // 2.0 elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches)) // 2.0
{ {
$days = explode(',',$recurenceMatches[1]); $days = explode(',',$recurenceMatches[1]);
$recur_days = $this->recur_days;
} }
if ($days) if ($days)
{ {
foreach($this->recur_days as $id => $day) foreach($recur_days as $id => $day)
{ {
if (in_array(strtoupper(substr($day,0,2)),$matches)) if (in_array(strtoupper(substr($day,0,2)),$days))
{ {
$vcardData['recur_data'] |= $id; $vcardData['recur_data'] |= $id;
} }
@ -402,6 +457,7 @@
case 'D': // 1.0 case 'D': // 1.0
if(!preg_match('/D(\d+) (.*)/',$recurence, $recurenceMatches)) break; if(!preg_match('/D(\d+) (.*)/',$recurence, $recurenceMatches)) break;
$vcardData['recur_interval'] = $recurenceMatches[1]; $vcardData['recur_interval'] = $recurenceMatches[1];
if($recurenceMatches[2] != '#0')
$vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[2]); $vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[2]);
// fall-through // fall-through
case 'DAILY': // 2.0 case 'DAILY': // 2.0
@ -412,12 +468,18 @@
if(preg_match('/MD(\d+) (.*)/',$recurence, $recurenceMatches)) if(preg_match('/MD(\d+) (.*)/',$recurence, $recurenceMatches))
{ {
$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_MDAY; $vcardData['recur_type'] = MCAL_RECUR_MONTHLY_MDAY;
if($recurenceMatches[1] > 1)
$vcardData['recur_interval'] = $recurenceMatches[1]; $vcardData['recur_interval'] = $recurenceMatches[1];
if($recurenceMatches[2] != '#0')
$vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[2]);
} }
elseif(preg_match('/MP(\d+) (.*) (.*) (.*)/',$recurence, $recurenceMatches)) elseif(preg_match('/MP(\d+) (.*) (.*) (.*)/',$recurence, $recurenceMatches))
{ {
$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_WDAY; $vcardData['recur_type'] = MCAL_RECUR_MONTHLY_WDAY;
if($recurenceMatches[1] > 1)
$vcardData['recur_interval'] = $recurenceMatches[1]; $vcardData['recur_interval'] = $recurenceMatches[1];
if($recurenceMatches[4] != '#0')
$vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[4]);
} }
break; break;
case 'MONTHLY': case 'MONTHLY':
@ -428,6 +490,8 @@
case 'Y': // 1.0 case 'Y': // 1.0
if(!preg_match('/YM(\d+) (.*)/',$recurence, $recurenceMatches)) break; if(!preg_match('/YM(\d+) (.*)/',$recurence, $recurenceMatches)) break;
$vcardData['recur_interval'] = $recurenceMatches[1]; $vcardData['recur_interval'] = $recurenceMatches[1];
if($recurenceMatches[2] != '#0')
$vcardData['recur_enddate'] = $vcal->_parseDateTime($recurenceMatches[2]);
// fall-through // fall-through
case 'YEARLY': // 2.0 case 'YEARLY': // 2.0
$vcardData['recur_type'] = MCAL_RECUR_YEARLY; $vcardData['recur_type'] = MCAL_RECUR_YEARLY;
@ -500,7 +564,7 @@
break; break;
} }
} }
if(isset($vcardData['recur_enddate'])) if(!empty($vcardData['recur_enddate']))
{ {
// reset recure_enddate to 00:00:00 on the last day // reset recure_enddate to 00:00:00 on the last day
$vcardData['recur_enddate'] = mktime(0, 0, 0, $vcardData['recur_enddate'] = mktime(0, 0, 0,