Fix occurrence count for recurring events

This commit is contained in:
Jörg Lehrke 2010-02-03 10:41:44 +00:00
parent 8ad9d0cde5
commit 8f71452859

View File

@ -303,9 +303,9 @@ class calendar_sif extends calendar_boupdate
case 'isrecurring': case 'isrecurring':
if ($value == 1) if ($value == 1)
{ {
$finalEvent['recur_exception'] = array();
if (is_array($this->event['recur_exception'])) if (is_array($this->event['recur_exception']))
{ {
$finalEvent['recur_exception'] = array();
foreach ($this->event['recur_exception'] as $day) foreach ($this->event['recur_exception'] as $day)
{ {
$finalEvent['recur_exception'][] = $this->vCalendar->_parseDateTime($day); $finalEvent['recur_exception'][] = $this->vCalendar->_parseDateTime($day);
@ -976,45 +976,31 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= "<$sifField>0</$sifField>"; $sifEvent .= "<$sifField>0</$sifField>";
break; break;
} }
$occurrences = 0;
if ($event['recur_enddate'] == 0) if ($event['recur_enddate'] == 0)
{ {
$sifEvent .= '<NoEndDate>1</NoEndDate>'; $sifEvent .= '<NoEndDate>1</NoEndDate>';
} }
else else
{ {
$time = new egw_time($event['recur_enddate'],egw_time::$server_timezone); $rriter = calendar_rrule::event2rrule($event, false, $tzid);
// all calculations in the event's timezone $rriter->rewind();
$time->setTimezone(self::$tz_cache[$event['tzid']]);
$time->setTime(23, 59, 59);
if ($tzid) while ($rriter->valid())
{ {
$time->setTimezone(self::$tz_cache[$tzid]); $occurrences++;
} $recur_date = $rriter->current();
else if (!$rriter->exceptions || !in_array($recur_date->format('Ymd'),$rriter->exceptions))
{ {
$time->setTimezone(egw_time::$user_timezone); $recur_end = $recur_date;
} }
$recurEndDate = egw_time::to($time,'server'); $rriter->next_no_exception();
}
$recurEndDate = egw_time::to($recur_end, 'server');
$sifEvent .= '<NoEndDate>0</NoEndDate>'; $sifEvent .= '<NoEndDate>0</NoEndDate>';
$sifEvent .= '<PatternEndDate>'. $this->vCalendar->_exportDateTime($recurEndDate) .'</PatternEndDate>'; $sifEvent .= '<PatternEndDate>'. self::getDateTime($recurEndDate,$tzid) .'</PatternEndDate>';
} }
$time = new egw_time($event['start'],egw_time::$server_timezone);
// all calculations in the event's timezone
$time->setTimezone(self::$tz_cache[$event['tzid']]);
$time->setTime(0, 0, 0);
if ($tzid)
{
$time->setTimezone(self::$tz_cache[$tzid]);
}
else
{
$time->setTimezone(egw_time::$user_timezone);
}
$recurStartDate = egw_time::to($time,'server');
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1); $eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
switch ($event['recur_type']) switch ($event['recur_type'])
@ -1024,11 +1010,9 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursDaily .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursDaily .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. self::getDateTime($event['start'],$tzid) .'</PatternStartDate>';
if ($event['recur_enddate']) if ($event['recur_enddate'])
{ {
$totalDays = ($recurEndDate - $recurStartDate) / 86400;
$occurrences = ceil($totalDays / $eventInterval);
$sifEvent .= '<Occurrences>'. $occurrences .'</Occurrences>'; $sifEvent .= '<Occurrences>'. $occurrences .'</Occurrences>';
} }
break; break;
@ -1037,41 +1021,10 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursWeekly .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursWeekly .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. self::getDateTime($event['start'],$tzid) .'</PatternStartDate>';
$sifEvent .= '<DayOfWeekMask>'. $event['recur_data'] .'</DayOfWeekMask>'; $sifEvent .= '<DayOfWeekMask>'. $event['recur_data'] .'</DayOfWeekMask>';
if ($event['recur_enddate']) if ($event['recur_enddate'])
{ {
$daysPerWeek = substr_count(decbin($event['recur_data']),'1');
$totalWeeks = floor(($recurEndDate - $recurStartDate) / (86400*7));
$occurrences = ceil($totalWeeks / $eventInterval) * $daysPerWeek;
for($i = $recurEndDate; $i > $recurStartDate + ($totalWeeks * 86400*7); $i = $i - 86400)
{
switch (date('w', $i-1))
{
case 0:
if ($event['recur_data'] & 1) $occurrences++;
break;
// monday
case 1:
if ($event['recur_data'] & 2) $occurrences++;
break;
case 2:
if ($event['recur_data'] & 4) $occurrences++;
break;
case 3:
if ($event['recur_data'] & 8) $occurrences++;
break;
case 4:
if ($event['recur_data'] & 16) $occurrences++;
break;
case 5:
if ($event['recur_data'] & 32) $occurrences++;
break;
case 6:
if ($event['recur_data'] & 64) $occurrences++;
break;
}
}
$sifEvent .= '<Occurrences>'. $occurrences .'</Occurrences>'; $sifEvent .= '<Occurrences>'. $occurrences .'</Occurrences>';
} }
break; break;
@ -1080,7 +1033,7 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursMonthly .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursMonthly .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. self::getDateTime($event['start'],$tzid) .'</PatternStartDate>';
break; break;
case MCAL_RECUR_MONTHLY_WDAY: case MCAL_RECUR_MONTHLY_WDAY:
@ -1090,7 +1043,7 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursMonthNth .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursMonthNth .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. self::getDateTime($event['start'],$tzid) .'</PatternStartDate>';
$sifEvent .= '<Instance>' . (1 + (int) ((date('d',$event['start'])-1) / 7)) . '</Instance>'; $sifEvent .= '<Instance>' . (1 + (int) ((date('d',$event['start'])-1) / 7)) . '</Instance>';
$sifEvent .= '<DayOfWeekMask>' . $weekMaskMap[date('D',$event['start'])] . '</DayOfWeekMask>'; $sifEvent .= '<DayOfWeekMask>' . $weekMaskMap[date('D',$event['start'])] . '</DayOfWeekMask>';
break; break;