Merge branch 'master' of ssh://git.kolabsys.com/git/roundcube

This commit is contained in:
Thomas Bruederli 2013-01-09 16:36:21 +01:00
commit be2a51957e
3 changed files with 64 additions and 20 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 // 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_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'); $old_duration = $old['end']->format('U') - $old['start']->format('U');
$new_start_date = $event['start']->format('Y-m-d'); $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'); $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; $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); $this->events[$master_id] = $this->_to_rcube_event($record);
if (($master = $this->events[$master_id]) && $master['recurrence']) { if (($master = $this->events[$master_id]) && $master['recurrence']) {
$limit = clone $master['start']; $this->_get_recurring_events($record, $master['start'], null, $id);
$limit->add(new DateInterval('P10Y'));
$this->_get_recurring_events($record, $master['start'], $limit, $id);
} }
} }
@ -248,6 +246,20 @@ class kolab_calendar
// list events in requested time window // list events in requested time window
if ($event['start'] <= $end && $event['end'] >= $start) { if ($event['start'] <= $end && $event['end'] >= $start) {
unset($event['_attendees']); unset($event['_attendees']);
$add = true;
// skip the first instance of a recurring event if listed in exdate
if ($virtual && !empty($event['recurrence']['EXDATE'])) {
$event_date = $event['start']->format('Ymd');
foreach ($event['recurrence']['EXDATE'] as $exdate) {
if ($exdate->format('Ymd') == $event_date) {
$add = false;
break;
}
}
}
if ($add)
$events[] = $event; $events[] = $event;
} }
@ -372,8 +384,14 @@ class kolab_calendar
/** /**
* Create instances of a recurring event * 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']; $object = $event['_formatobj'];
if (!$object) { if (!$object) {
@ -383,6 +401,19 @@ class kolab_calendar
if (!is_object($object)) if (!is_object($object))
return array(); 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); $recurrence = new kolab_date_recurrence($object);
$i = 0; $i = 0;
@ -458,6 +489,10 @@ class kolab_calendar
if (is_array($record['categories'])) if (is_array($record['categories']))
$record['categories'] = $record['categories'][0]; $record['categories'] = $record['categories'][0];
// remove empty recurrence array
if (empty($record['recurrence']))
unset($record['recurrence']);
// remove internals // remove internals
unset($record['_mailbox'], $record['_msguid'], $record['_formatobj'], $record['_attachments']); unset($record['_mailbox'], $record['_msguid'], $record['_formatobj'], $record['_attachments']);

View file

@ -406,10 +406,10 @@ class kolab_driver extends calendar_driver
public function remove_event($event, $force = true) public function remove_event($event, $force = true)
{ {
$success = false; $success = false;
$_savemode = $event['_savemode']; $savemode = $event['_savemode'];
if (($storage = $this->calendars[$event['calendar']]) && ($event = $storage->get_event($event['id']))) { if (($storage = $this->calendars[$event['calendar']]) && ($event = $storage->get_event($event['id']))) {
$event['_savemode'] = $_savemode; $event['_savemode'] = $savemode;
$savemode = 'all'; $savemode = 'all';
$master = $event; $master = $event;
@ -427,9 +427,7 @@ class kolab_driver extends calendar_driver
// removing the first instance => just move to next occurence // removing the first instance => just move to next occurence
if ($master['id'] == $event['id']) { if ($master['id'] == $event['id']) {
$limit = clone $event['end']; $recurring = reset($storage->_get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
$limit->add(new DateInterval('P370D'));
$recurring = reset($storage->_get_recurring_events($event, $event['start'], $limit, $event['id'].'-1'));
$master['start'] = $recurring['start']; $master['start'] = $recurring['start'];
$master['end'] = $recurring['end']; $master['end'] = $recurring['end'];
if ($master['recurrence']['COUNT']) if ($master['recurrence']['COUNT'])
@ -584,13 +582,24 @@ class kolab_driver extends calendar_driver
break; break;
case 'current': case 'current':
// add exception to master event // modifying the first instance => just move to next occurence
if ($master['id'] == $event['id']) {
$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'])
$master['recurrence']['COUNT']--;
}
else { // add exception to master event
$master['recurrence']['EXDATE'][] = $old['start']; $master['recurrence']['EXDATE'][] = $old['start'];
}
$storage->update_event($master); $storage->update_event($master);
// insert new event for this occurence // insert new event for this occurence
$event += $old; $event += $old;
$event['recurrence'] = array(); $event['recurrence'] = array();
unset($event['recurrence_id']);
$event['uid'] = $this->cal->generate_uid(); $event['uid'] = $this->cal->generate_uid();
$success = $storage->insert_event($event); $success = $storage->insert_event($event);
break; break;
@ -628,11 +637,11 @@ class kolab_driver extends calendar_driver
// use start date from master but try to be smart on time or duration changes // 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_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'); $old_duration = $old['end']->format('U') - $old['start']->format('U');
$new_start_date = $event['start']->format('Y-m-d'); $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'); $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; $diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;