Apply date offset from exceptions to recurring occurrences (#4386)
This commit is contained in:
parent
4d534ea786
commit
f7e7df62a2
2 changed files with 20 additions and 7 deletions
|
@ -297,7 +297,7 @@ class kolab_calendar extends kolab_storage_folder_api
|
||||||
$exdate = $exception['recurrence_date'] ? $exception['recurrence_date']->format('Ymd') : substr($exception['_instance'], 0, 8);
|
$exdate = $exception['recurrence_date'] ? $exception['recurrence_date']->format('Ymd') : substr($exception['_instance'], 0, 8);
|
||||||
if ($exdate == $event_date) {
|
if ($exdate == $event_date) {
|
||||||
$event['_instance'] = $exception['_instance'];
|
$event['_instance'] = $exception['_instance'];
|
||||||
kolab_driver::merge_event_data($event, $exception);
|
kolab_driver::merge_exception_data($event, $exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,7 +641,7 @@ class kolab_calendar extends kolab_storage_folder_api
|
||||||
$rec_event['_instance'] = $instance_id;
|
$rec_event['_instance'] = $instance_id;
|
||||||
|
|
||||||
if ($overlay_data || $exdata[$datestr]) // copy data from exception
|
if ($overlay_data || $exdata[$datestr]) // copy data from exception
|
||||||
kolab_driver::merge_event_data($rec_event, $exdata[$datestr] ?: $overlay_data);
|
kolab_driver::merge_exception_data($rec_event, $exdata[$datestr] ?: $overlay_data);
|
||||||
|
|
||||||
$rec_event['id'] = $rec_id;
|
$rec_event['id'] = $rec_id;
|
||||||
$rec_event['recurrence_id'] = $event['uid'];
|
$rec_event['recurrence_id'] = $event['uid'];
|
||||||
|
|
|
@ -928,6 +928,10 @@ class kolab_driver extends calendar_driver
|
||||||
if ($old['recurrence'] || $old['recurrence_id']) {
|
if ($old['recurrence'] || $old['recurrence_id']) {
|
||||||
$master = $old['recurrence_id'] ? $fromcalendar->get_event($old['recurrence_id']) : $old;
|
$master = $old['recurrence_id'] ? $fromcalendar->get_event($old['recurrence_id']) : $old;
|
||||||
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] ? 'current' : 'all');
|
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] ? 'current' : 'all');
|
||||||
|
|
||||||
|
// this-and-future on the first instance equals to 'all'
|
||||||
|
if (!$old['recurrence_id'] && $savemode == 'future')
|
||||||
|
$savemode = 'all';
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if update affects scheduling and update attendee status accordingly
|
// check if update affects scheduling and update attendee status accordingly
|
||||||
|
@ -1135,7 +1139,7 @@ class kolab_driver extends calendar_driver
|
||||||
// merge the new event properties onto future exceptions
|
// merge the new event properties onto future exceptions
|
||||||
if ($savemode == 'future' && $exception['_instance'] >= $old['_instance']) {
|
if ($savemode == 'future' && $exception['_instance'] >= $old['_instance']) {
|
||||||
unset($event['thisandfuture']);
|
unset($event['thisandfuture']);
|
||||||
self::merge_event_data($master['recurrence']['EXCEPTIONS'][$i], $event);
|
self::merge_exception_data($master['recurrence']['EXCEPTIONS'][$i], $event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -1171,19 +1175,28 @@ class kolab_driver extends calendar_driver
|
||||||
* @param array The event object to be altered
|
* @param array The event object to be altered
|
||||||
* @param array The overlay event object to be merged over $event
|
* @param array The overlay event object to be merged over $event
|
||||||
*/
|
*/
|
||||||
public static function merge_event_data(&$event, $overlay)
|
public static function merge_exception_data(&$event, $overlay)
|
||||||
{
|
{
|
||||||
static $forbidden = array('id','uid','recurrence','recurrence_date','thisandfuture','organizer','_attachments');
|
static $forbidden = array('id','uid','recurrence','recurrence_date','thisandfuture','organizer','_attachments');
|
||||||
|
|
||||||
|
// compute date offset from the exception
|
||||||
|
if ($overlay['start'] instanceof DateTime && $overlay['recurrence_date'] instanceof DateTime) {
|
||||||
|
$date_offset = $overlay['recurrence_date']->diff($overlay['start']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($overlay as $prop => $value) {
|
foreach ($overlay as $prop => $value) {
|
||||||
// adjust time of the recurring event instance
|
|
||||||
if ($prop == 'start' || $prop == 'end') {
|
if ($prop == 'start' || $prop == 'end') {
|
||||||
if (is_object($event[$prop]) && is_a($event[$prop], 'DateTime')) {
|
if (is_object($event[$prop]) && $event[$prop] instanceof DateTime) {
|
||||||
$event[$prop]->setTime($value->format('G'), intval($value->format('i')), intval($value->format('s')));
|
|
||||||
// set date value if overlay is an exception of the current instance
|
// set date value if overlay is an exception of the current instance
|
||||||
if (substr($overlay['_instance'], 0, 8) == substr($event['_instance'], 0, 8)) {
|
if (substr($overlay['_instance'], 0, 8) == substr($event['_instance'], 0, 8)) {
|
||||||
$event[$prop]->setDate(intval($value->format('Y')), intval($value->format('n')), intval($value->format('j')));
|
$event[$prop]->setDate(intval($value->format('Y')), intval($value->format('n')), intval($value->format('j')));
|
||||||
}
|
}
|
||||||
|
// apply date offset
|
||||||
|
else if ($date_offset) {
|
||||||
|
$event[$prop]->add($date_offset);
|
||||||
|
}
|
||||||
|
// adjust time of the recurring event instance
|
||||||
|
$event[$prop]->setTime($value->format('G'), intval($value->format('i')), intval($value->format('s')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($prop == 'thisandfuture' && $overlay['_instance'] == $event['_instance']) {
|
else if ($prop == 'thisandfuture' && $overlay['_instance'] == $event['_instance']) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue