2011-10-14 11:58:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recurrence computation class for the Calendar plugin
|
|
|
|
*
|
|
|
|
* Uitility class to compute instances of recurring events.
|
|
|
|
*
|
2011-11-21 11:20:48 +01:00
|
|
|
* @version @package_version@
|
2011-12-07 12:51:23 +01:00
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
2011-11-21 11:20:48 +01:00
|
|
|
* @package @package_name@
|
2011-10-14 11:58:42 +02:00
|
|
|
*
|
2012-07-06 17:15:45 +02:00
|
|
|
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
|
2011-10-14 11:58:42 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2011-10-14 11:58:42 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-10-27 10:20:46 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2011-10-14 11:58:42 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-14 11:58:42 +02:00
|
|
|
*/
|
|
|
|
class calendar_recurrence
|
|
|
|
{
|
|
|
|
private $cal;
|
|
|
|
private $event;
|
2012-07-06 17:15:45 +02:00
|
|
|
private $next;
|
2011-10-14 11:58:42 +02:00
|
|
|
private $engine;
|
2012-07-06 17:15:45 +02:00
|
|
|
private $duration;
|
2011-10-14 11:58:42 +02:00
|
|
|
private $hour = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*
|
|
|
|
* @param object calendar The calendar plugin instance
|
|
|
|
* @param array The event object to operate on
|
|
|
|
*/
|
|
|
|
function __construct($cal, $event)
|
|
|
|
{
|
|
|
|
$this->cal = $cal;
|
2012-07-06 17:15:45 +02:00
|
|
|
$this->event = $event;
|
|
|
|
$this->next = new Horde_Date($event['start'], $cal->timezone->getName());
|
|
|
|
$this->hour = $this->next->hour;
|
|
|
|
|
|
|
|
if (is_object($event['start']) && is_object($event['end']))
|
|
|
|
$this->duration = $event['start']->diff($event['end']);
|
2011-10-14 11:58:42 +02:00
|
|
|
|
|
|
|
// 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(calendar::to_rrule($event['recurrence']));
|
|
|
|
|
|
|
|
if (is_array($event['recurrence']['EXDATE'])) {
|
|
|
|
foreach ($event['recurrence']['EXDATE'] as $exdate)
|
2012-07-06 17:15:45 +02:00
|
|
|
$this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j'));
|
2011-10-14 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-06 17:15:45 +02:00
|
|
|
* Get date/time of the next occurence of this event
|
2011-10-14 11:58:42 +02:00
|
|
|
*
|
2012-07-06 17:15:45 +02:00
|
|
|
* @return mixed DateTime object or False if recurrence ended
|
2011-10-14 11:58:42 +02:00
|
|
|
*/
|
|
|
|
public function next_start()
|
|
|
|
{
|
|
|
|
$time = false;
|
|
|
|
if ($this->next && ($next = $this->engine->nextActiveRecurrence(array('year' => $this->next->year, 'month' => $this->next->month, 'mday' => $this->next->mday + 1, 'hour' => $this->next->hour, 'min' => $this->next->min, 'sec' => $this->next->sec)))) {
|
|
|
|
if ($this->event['allday']) {
|
|
|
|
$next->hour = $this->hour; # fix time for all-day events
|
|
|
|
$next->min = 0;
|
|
|
|
}
|
2012-07-06 17:15:45 +02:00
|
|
|
|
|
|
|
$time = $next->toDateTime();
|
2011-10-14 11:58:42 +02:00
|
|
|
$this->next = $next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $time;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|