Add fallback for recurrence computation when the kolabcalendaring php module isn't available

This commit is contained in:
Thomas Bruederli 2013-01-23 11:36:55 +01:00
parent 1f9f09fe09
commit 53c77796dd
2 changed files with 35 additions and 5 deletions

View file

@ -414,7 +414,14 @@ class kolab_calendar
}
// use libkolab to compute recurring events
$recurrence = new kolab_date_recurrence($object);
if (class_exists('kolabcalendaring')) {
$recurrence = new kolab_date_recurrence($object);
}
else {
// fallback to local recurrence implementation
require_once($this->cal->home . '/lib/calendar_recurrence.php');
$recurrence = new calendar_recurrence($this->cal, $event);
}
$i = 0;
$events = array();

View file

@ -41,6 +41,10 @@ class calendar_recurrence
*/
function __construct($cal, $event)
{
// use Horde classes to compute recurring instances
// TODO: replace with something that has less than 6'000 lines of code
require_once(__DIR__ . '/Horde_Date_Recurrence.php');
$this->cal = $cal;
$this->event = $event;
$this->next = new Horde_Date($event['start'], $cal->timezone->getName());
@ -49,10 +53,6 @@ class calendar_recurrence
if (is_object($event['start']) && is_object($event['end']))
$this->duration = $event['start']->diff($event['end']);
// use Horde classes to compute recurring instances
// TODO: replace with something that has less than 6'000 lines of code
require_once($this->cal->home . '/lib/Horde_Date_Recurrence.php');
$this->engine = new Horde_Date_Recurrence($event['start']);
$this->engine->fromRRule20(libcalendaring::to_rrule($event['recurrence']));
@ -83,4 +83,27 @@ class calendar_recurrence
return $time;
}
/**
* Get the next recurring instance of this event
*
* @return mixed Array with event properties or False if recurrence ended
*/
public function next_instance()
{
if ($next_start = $this->next_start()) {
$next_end = clone $next_start;
$next_end->add($this->duration);
$next = $this->event;
$next['recurrence_id'] = $next_start->format('Y-m-d');
$next['start'] = $next_start;
$next['end'] = $next_end;
unset($next['_formatobj']);
return $next;
}
return false;
}
}