Code cleanup: get recurrence instance identifiers from utility functions
This commit is contained in:
parent
738cdb7017
commit
60205136ee
9 changed files with 62 additions and 30 deletions
|
@ -463,7 +463,7 @@ abstract class calendar_driver
|
||||||
|
|
||||||
$rcmail = rcmail::get_instance();
|
$rcmail = rcmail::get_instance();
|
||||||
$recurrence = new calendar_recurrence($rcmail->plugins->get_plugin('calendar'), $event);
|
$recurrence = new calendar_recurrence($rcmail->plugins->get_plugin('calendar'), $event);
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
||||||
|
|
||||||
// determine a reasonable end date if none given
|
// determine a reasonable end date if none given
|
||||||
if (!$end) {
|
if (!$end) {
|
||||||
|
|
|
@ -388,10 +388,9 @@ class database_driver extends calendar_driver
|
||||||
|
|
||||||
// set exception to first instance (= master)
|
// set exception to first instance (= master)
|
||||||
if ($event['id'] == $master['id']) {
|
if ($event['id'] == $master['id']) {
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
|
||||||
$event += $old;
|
$event += $old;
|
||||||
$event['recurrence_id'] = $master['id'];
|
$event['recurrence_id'] = $master['id'];
|
||||||
$event['_instance'] = $old['start']->format($recurrence_id_format);
|
$event['_instance'] = libcalendaring::recurrence_instance_identifier($old);
|
||||||
$event['isexception'] = 1;
|
$event['isexception'] = 1;
|
||||||
$event_id = $this->_insert_event($event);
|
$event_id = $this->_insert_event($event);
|
||||||
return $event_id;
|
return $event_id;
|
||||||
|
@ -463,7 +462,7 @@ class database_driver extends calendar_driver
|
||||||
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
|
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
|
||||||
if (is_array($event['recurrence']) && ($old_start_date != $new_start_date || $old_start_time != $new_start_time)
|
if (is_array($event['recurrence']) && ($old_start_date != $new_start_date || $old_start_time != $new_start_time)
|
||||||
&& ($exceptions = $this->_load_exceptions($old))) {
|
&& ($exceptions = $this->_load_exceptions($old))) {
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
||||||
foreach ($exceptions as $exception) {
|
foreach ($exceptions as $exception) {
|
||||||
$recurrence_id = rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
|
$recurrence_id = rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
|
||||||
if (is_a($recurrence_id, 'DateTime')) {
|
if (is_a($recurrence_id, 'DateTime')) {
|
||||||
|
@ -764,8 +763,9 @@ class database_driver extends calendar_driver
|
||||||
$recurrence = new calendar_recurrence($this->cal, $event);
|
$recurrence = new calendar_recurrence($this->cal, $event);
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
$event['allday'] = $event['all_day'];
|
||||||
$duration = $event['start']->diff($event['end']);
|
$duration = $event['start']->diff($event['end']);
|
||||||
$recurrence_id_format = $event['all_day'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
||||||
while ($next_start = $recurrence->next_start()) {
|
while ($next_start = $recurrence->next_start()) {
|
||||||
$instance = $next_start->format($recurrence_id_format);
|
$instance = $next_start->format($recurrence_id_format);
|
||||||
$datestr = substr($instance, 0, 8);
|
$datestr = substr($instance, 0, 8);
|
||||||
|
@ -1075,8 +1075,7 @@ class database_driver extends calendar_driver
|
||||||
}
|
}
|
||||||
// check for exception on first instance
|
// check for exception on first instance
|
||||||
else {
|
else {
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$instance = libcalendaring::recurrence_instance_identifier($event);
|
||||||
$instance = $event['start']->format($recurrence_id_format);
|
|
||||||
$exceptions = $this->_load_exceptions($event, $instance);
|
$exceptions = $this->_load_exceptions($event, $instance);
|
||||||
if ($exceptions && is_array($exceptions[$instance])) {
|
if ($exceptions && is_array($exceptions[$instance])) {
|
||||||
$event = $exceptions[$instance];
|
$event = $exceptions[$instance];
|
||||||
|
|
|
@ -616,14 +616,12 @@ class kolab_calendar extends kolab_storage_folder_api
|
||||||
$events = array();
|
$events = array();
|
||||||
$exdata = array();
|
$exdata = array();
|
||||||
$futuredata = array();
|
$futuredata = array();
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
||||||
|
|
||||||
if (is_array($event['recurrence']['EXCEPTIONS'])) {
|
if (is_array($event['recurrence']['EXCEPTIONS'])) {
|
||||||
foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
|
foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
|
||||||
if (!$exception['_instance'] && is_a($exception['recurrence_date'], 'DateTime'))
|
if (!$exception['_instance'])
|
||||||
$exception['_instance'] = $exception['recurrence_date']->format($recurrence_id_format);
|
$exception['_instance'] = libcalendaring::recurrence_instance_identifier($exception);
|
||||||
else if (!$exception['_instance'] && is_a($exception['start'], 'DateTime'))
|
|
||||||
$exception['_instance'] = $exception['start']->format($recurrence_id_format);
|
|
||||||
|
|
||||||
$rec_event = $this->_to_driver_event($exception);
|
$rec_event = $this->_to_driver_event($exception);
|
||||||
$rec_event['id'] = $event['uid'] . '-' . $exception['_instance'];
|
$rec_event['id'] = $event['uid'] . '-' . $exception['_instance'];
|
||||||
|
@ -717,7 +715,7 @@ class kolab_calendar extends kolab_storage_folder_api
|
||||||
}
|
}
|
||||||
|
|
||||||
// add instance identifier to first occurrence (master event)
|
// add instance identifier to first occurrence (master event)
|
||||||
$recurrence_id_format = $record['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($record);
|
||||||
if (!$noinst && $record['recurrence'] && !$record['recurrence_id'] && !$record['_instance']) {
|
if (!$noinst && $record['recurrence'] && !$record['recurrence_id'] && !$record['_instance']) {
|
||||||
$record['_instance'] = $record['start']->format($recurrence_id_format);
|
$record['_instance'] = $record['start']->format($recurrence_id_format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -791,8 +791,7 @@ class kolab_driver extends calendar_driver
|
||||||
$_SESSION['calendar_restore_event_data'] = $master;
|
$_SESSION['calendar_restore_event_data'] = $master;
|
||||||
|
|
||||||
// removing the first instance => just move to next occurence
|
// removing the first instance => just move to next occurence
|
||||||
$recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
|
if ($master['recurrence'] && $event['_instance'] == libcalendaring::recurrence_instance_identifier($master)) {
|
||||||
if ($master['recurrence'] && $event['_instance'] == $master['start']->format($recurrence_id_format)) {
|
|
||||||
$recurring = reset($storage->get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
|
$recurring = reset($storage->get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
|
||||||
|
|
||||||
// no future instances found: delete the master event (bug #1677)
|
// no future instances found: delete the master event (bug #1677)
|
||||||
|
@ -822,8 +821,7 @@ class kolab_driver extends calendar_driver
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'future':
|
case 'future':
|
||||||
$recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
|
$master['_instance'] = libcalendaring::recurrence_instance_identifier($master);
|
||||||
$master['_instance'] = $master['start']->format($recurrence_id_format);
|
|
||||||
if ($master['_instance'] != $event['_instance']) {
|
if ($master['_instance'] != $event['_instance']) {
|
||||||
$_SESSION['calendar_restore_event_data'] = $master;
|
$_SESSION['calendar_restore_event_data'] = $master;
|
||||||
|
|
||||||
|
@ -952,8 +950,7 @@ class kolab_driver extends calendar_driver
|
||||||
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] || $old['isexception'] ? 'current' : 'all');
|
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] || $old['isexception'] ? 'current' : 'all');
|
||||||
|
|
||||||
// this-and-future on the first instance equals to 'all'
|
// this-and-future on the first instance equals to 'all'
|
||||||
$recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
|
if ($savemode == 'future' && $master['start'] && $old['_instance'] == libcalendaring::recurrence_instance_identifier($master))
|
||||||
if ($savemode == 'future' && $master['start'] && $old['_instance'] == $master['start']->format($recurrence_id_format))
|
|
||||||
$savemode = 'all';
|
$savemode = 'all';
|
||||||
// force 'current' mode for single occurrences stored as exception
|
// force 'current' mode for single occurrences stored as exception
|
||||||
else if (!$old['recurrence'] && !$old['recurrence_id'] && $old['isexception'])
|
else if (!$old['recurrence'] && !$old['recurrence_id'] && $old['isexception'])
|
||||||
|
@ -1176,7 +1173,7 @@ class kolab_driver extends calendar_driver
|
||||||
|
|
||||||
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
|
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
|
||||||
if ($old_start_date != $new_start_date || $old_start_time != $new_start_time) {
|
if ($old_start_date != $new_start_date || $old_start_time != $new_start_time) {
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
||||||
foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
||||||
$recurrence_id = is_a($exception['recurrence_date'], 'DateTime') ? $exception['recurrence_date'] :
|
$recurrence_id = is_a($exception['recurrence_date'], 'DateTime') ? $exception['recurrence_date'] :
|
||||||
rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
|
rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
|
||||||
|
@ -1337,8 +1334,7 @@ class kolab_driver extends calendar_driver
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$event['_instance'] && is_a($event['recurrence_date'], 'DateTime')) {
|
if (!$event['_instance'] && is_a($event['recurrence_date'], 'DateTime')) {
|
||||||
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
$event['_instance'] = libcalendaring::recurrence_instance_identifier($event);
|
||||||
$event['_instance'] = $event['recurrence_date']->format($recurrence_id_format);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($master['exceptions']) && is_array($master['recurrence']['EXCEPTIONS'])) {
|
if (!is_array($master['exceptions']) && is_array($master['recurrence']['EXCEPTIONS'])) {
|
||||||
|
|
|
@ -74,9 +74,8 @@ class calendar_recurrence extends libcalendaring_recurrence
|
||||||
$next['end']->add($this->duration);
|
$next['end']->add($this->duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
$recurrence_id_format = $next['allday'] ? 'Ymd' : 'Ymd\THis';
|
|
||||||
$next['recurrence_date'] = clone $next_start;
|
$next['recurrence_date'] = clone $next_start;
|
||||||
$next['_instance'] = $next_start->format($recurrence_id_format);
|
$next['_instance'] = libcalendaring::recurrence_instance_identifier($next);
|
||||||
|
|
||||||
unset($next['_formatobj']);
|
unset($next['_formatobj']);
|
||||||
|
|
||||||
|
|
|
@ -1427,8 +1427,7 @@ class libcalendaring extends rcube_plugin
|
||||||
}
|
}
|
||||||
// set instance and 'savemode' according to recurrence-id
|
// set instance and 'savemode' according to recurrence-id
|
||||||
else if (!empty($object['recurrence_date']) && is_a($object['recurrence_date'], 'DateTime')) {
|
else if (!empty($object['recurrence_date']) && is_a($object['recurrence_date'], 'DateTime')) {
|
||||||
$recurrence_id_format = $object['allday'] ? 'Ymd' : 'Ymd\THis';
|
$object['_instance'] = self::recurrence_instance_identifier($object);
|
||||||
$object['_instance'] = $object['recurrence_date']->format($recurrence_id_format);
|
|
||||||
$object['_savemode'] = $object['thisandfuture'] ? 'future' : 'current';
|
$object['_savemode'] = $object['thisandfuture'] ? 'future' : 'current';
|
||||||
}
|
}
|
||||||
else if (!empty($object['recurrence_id']) && !empty($object['_instance'])) {
|
else if (!empty($object['recurrence_id']) && !empty($object['_instance'])) {
|
||||||
|
@ -1441,6 +1440,36 @@ class libcalendaring extends rcube_plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a date() format string to render identifiers for recurrence instances
|
||||||
|
*
|
||||||
|
* @param array Hash array with event properties
|
||||||
|
* @return string Format string
|
||||||
|
*/
|
||||||
|
public static function recurrence_id_format($event)
|
||||||
|
{
|
||||||
|
return $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the identifer for the given instance of a recurring event
|
||||||
|
*
|
||||||
|
* @param array Hash array with event properties
|
||||||
|
* @return mixed Format string or null if identifier cannot be generated
|
||||||
|
*/
|
||||||
|
public static function recurrence_instance_identifier($event)
|
||||||
|
{
|
||||||
|
$instance_date = $event['recurrence_date'] ?: $event['start'];
|
||||||
|
|
||||||
|
if ($instance_date && is_a($instance_date, 'DateTime')) {
|
||||||
|
$recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
||||||
|
return $instance_date->format($recurrence_id_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/********* Attendee handling functions *********/
|
/********* Attendee handling functions *********/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -90,7 +90,7 @@ class kolab_date_recurrence
|
||||||
$next['start'] = $next_start;
|
$next['start'] = $next_start;
|
||||||
$next['end'] = $next_end;
|
$next['end'] = $next_end;
|
||||||
|
|
||||||
$recurrence_id_format = $next['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libkolab::recurrence_id_format($next);
|
||||||
$next['recurrence_date'] = clone $next_start;
|
$next['recurrence_date'] = clone $next_start;
|
||||||
$next['_instance'] = $next_start->format($recurrence_id_format);
|
$next['_instance'] = $next_start->format($recurrence_id_format);
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ class kolab_format_event extends kolab_format_xcal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($object['exceptions'])) {
|
if (is_array($object['exceptions'])) {
|
||||||
$recurrence_id_format = $object['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libkolab::recurrence_id_format($object);
|
||||||
$vexceptions = new vectorevent;
|
$vexceptions = new vectorevent;
|
||||||
foreach ($object['exceptions'] as $i => $exception) {
|
foreach ($object['exceptions'] as $i => $exception) {
|
||||||
$exevent = new kolab_format_event;
|
$exevent = new kolab_format_event;
|
||||||
|
@ -210,7 +210,7 @@ class kolab_format_event extends kolab_format_xcal
|
||||||
// read exception event objects
|
// read exception event objects
|
||||||
if (($exceptions = $this->obj->exceptions()) && is_object($exceptions) && $exceptions->size()) {
|
if (($exceptions = $this->obj->exceptions()) && is_object($exceptions) && $exceptions->size()) {
|
||||||
$recurrence_exceptions = array();
|
$recurrence_exceptions = array();
|
||||||
$recurrence_id_format = $object['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libkolab::recurrence_id_format($object);
|
||||||
for ($i=0; $i < $exceptions->size(); $i++) {
|
for ($i=0; $i < $exceptions->size(); $i++) {
|
||||||
if (($exobj = $exceptions->get($i))) {
|
if (($exobj = $exceptions->get($i))) {
|
||||||
$exception = new kolab_format_event($exobj);
|
$exception = new kolab_format_event($exobj);
|
||||||
|
@ -251,7 +251,7 @@ class kolab_format_event extends kolab_format_xcal
|
||||||
$result = null;
|
$result = null;
|
||||||
$object = $this->to_array();
|
$object = $this->to_array();
|
||||||
|
|
||||||
$recurrence_id_format = $object['allday'] ? 'Ymd' : 'Ymd\THis';
|
$recurrence_id_format = libkolab::recurrence_id_format($object);
|
||||||
$instance_id = $recurrence_id instanceof DateTime ? $recurrence_id->format($recurrence_id_format) : strval($recurrence_id);
|
$instance_id = $recurrence_id instanceof DateTime ? $recurrence_id->format($recurrence_id_format) : strval($recurrence_id);
|
||||||
|
|
||||||
if ($object['recurrence_date'] instanceof DateTime) {
|
if ($object['recurrence_date'] instanceof DateTime) {
|
||||||
|
|
|
@ -139,4 +139,15 @@ class libkolab extends rcube_plugin
|
||||||
$diff = new FineDiff($from, $to, FineDiff::$wordGranularity);
|
$diff = new FineDiff($from, $to, FineDiff::$wordGranularity);
|
||||||
return $diff->renderDiffToHTML();
|
return $diff->renderDiffToHTML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a date() format string to render identifiers for recurrence instances
|
||||||
|
*
|
||||||
|
* @param array Hash array with event properties
|
||||||
|
* @return string Format string
|
||||||
|
*/
|
||||||
|
public static function recurrence_id_format($event)
|
||||||
|
{
|
||||||
|
return $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue