Fix modification of recurring events (#1499)

This commit is contained in:
Thomas Bruederli 2013-01-09 11:49:12 +01:00
parent 5f06d62ceb
commit 8d3f1803cc
3 changed files with 27 additions and 14 deletions

View file

@ -363,11 +363,11 @@ class database_driver extends calendar_driver
// use start date from master but try to be smart on time or duration changes
$old_start_date = $old['start']->format('Y-m-d');
$old_start_time = $old['start']->format('H:i');
$old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
$old_duration = $old['end']->format('U') - $old['start']->format('U');
$new_start_date = $event['start']->format('Y-m-d');
$new_start_time = $event['start']->format('H:i');
$new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
$new_duration = $event['end']->format('U') - $event['start']->format('U');
$diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;

View file

@ -181,9 +181,7 @@ class kolab_calendar
$this->events[$master_id] = $this->_to_rcube_event($record);
if (($master = $this->events[$master_id]) && $master['recurrence']) {
$limit = clone $master['start'];
$limit->add(new DateInterval('P10Y'));
$this->_get_recurring_events($record, $master['start'], $limit, $id);
$this->_get_recurring_events($record, $master['start'], null, $id);
}
}
@ -386,8 +384,14 @@ class kolab_calendar
/**
* Create instances of a recurring event
*
* @param array Hash array with event properties
* @param object DateTime Start date of the recurrence window
* @param object DateTime End date of the recurrence window
* @param string ID of a specific recurring event instance
* @return array List of recurring event instances
*/
public function _get_recurring_events($event, $start, $end, $event_id = null)
public function _get_recurring_events($event, $start, $end = null, $event_id = null)
{
$object = $event['_formatobj'];
if (!$object) {
@ -397,6 +401,19 @@ class kolab_calendar
if (!is_object($object))
return array();
// determine a reasonable end date if none given
if (!$end) {
switch ($event['recurrence']['FREQ']) {
case 'YEARLY': $intvl = 'P100Y'; break;
case 'MONTHLY': $intvl = 'P20Y'; break;
default: $intvl = 'P10Y'; break;
}
$end = clone $event['start'];
$end->add(new DateInterval($intvl));
}
// use libkolab to compute recurring events
$recurrence = new kolab_date_recurrence($object);
$i = 0;

View file

@ -427,9 +427,7 @@ class kolab_driver extends calendar_driver
// removing the first instance => just move to next occurence
if ($master['id'] == $event['id']) {
$limit = clone $event['end'];
$limit->add(new DateInterval('P370D'));
$recurring = reset($storage->_get_recurring_events($event, $event['start'], $limit, $event['id'].'-1'));
$recurring = reset($storage->_get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
$master['start'] = $recurring['start'];
$master['end'] = $recurring['end'];
if ($master['recurrence']['COUNT'])
@ -586,9 +584,7 @@ class kolab_driver extends calendar_driver
case 'current':
// modifying the first instance => just move to next occurence
if ($master['id'] == $event['id']) {
$limit = clone $old['end'];
$limit->add(new DateInterval('P370D'));
$recurring = reset($storage->_get_recurring_events($event, $event['start'], $limit, $event['id'].'-1'));
$recurring = reset($storage->_get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
$master['start'] = $recurring['start'];
$master['end'] = $recurring['end'];
if ($master['recurrence']['COUNT'])
@ -641,11 +637,11 @@ class kolab_driver extends calendar_driver
// use start date from master but try to be smart on time or duration changes
$old_start_date = $old['start']->format('Y-m-d');
$old_start_time = $old['start']->format('H:i');
$old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
$old_duration = $old['end']->format('U') - $old['start']->format('U');
$new_start_date = $event['start']->format('Y-m-d');
$new_start_time = $event['start']->format('H:i');
$new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
$new_duration = $event['end']->format('U') - $event['start']->format('U');
$diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;