Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/lib/calendar_recurrence.php
Show All 20 Lines | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU Affero General Public License for more details. | * GNU Affero General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU Affero General Public License | * 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/>. | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
class calendar_recurrence extends libcalendaring_recurrence | class calendar_recurrence extends libcalendaring_recurrence | ||||
{ | { | ||||
private $event; | private $event; | ||||
private $duration; | private $duration; | ||||
/** | /** | ||||
* Default constructor | * Default constructor | ||||
* | * | ||||
* @param object calendar The calendar plugin instance | * @param calendar $cal The calendar plugin instance | ||||
* @param array The event object to operate on | * @param array $event The event object to operate on | ||||
*/ | */ | ||||
function __construct($cal, $event) | function __construct($cal, $event) | ||||
{ | { | ||||
parent::__construct($cal->lib); | parent::__construct($cal->lib); | ||||
$this->event = $event; | $this->event = $event; | ||||
if (is_object($event['start']) && is_object($event['end'])) | if (is_object($event['start']) && is_object($event['end'])) { | ||||
$this->duration = $event['start']->diff($event['end']); | $this->duration = $event['start']->diff($event['end']); | ||||
} | |||||
$event['start']->_dateonly = !empty($event['allday']); | |||||
$event['start']->_dateonly |= $event['allday']; | |||||
$this->init($event['recurrence'], $event['start']); | $this->init($event['recurrence'], $event['start']); | ||||
} | } | ||||
/** | /** | ||||
* Alias of libcalendaring_recurrence::next() | * Alias of libcalendaring_recurrence::next() | ||||
* | * | ||||
* @return mixed DateTime object or False if recurrence ended | * @return mixed DateTime object or False if recurrence ended | ||||
*/ | */ | ||||
public function next_start() | public function next_start() | ||||
{ | { | ||||
return $this->next(); | return $this->next(); | ||||
} | } | ||||
/** | /** | ||||
* Get the next recurring instance of this event | * Get the next recurring instance of this event | ||||
* | * | ||||
* @return mixed Array with event properties or False if recurrence ended | * @return mixed Array with event properties or False if recurrence ended | ||||
*/ | */ | ||||
public function next_instance() | public function next_instance() | ||||
{ | { | ||||
if ($next_start = $this->next()) { | if ($next_start = $this->next()) { | ||||
$next = $this->event; | $next = $this->event; | ||||
$next['start'] = $next_start; | $next['start'] = $next_start; | ||||
if ($this->duration) { | if ($this->duration) { | ||||
$next['end'] = clone $next_start; | $next['end'] = clone $next_start; | ||||
$next['end']->add($this->duration); | $next['end']->add($this->duration); | ||||
} | } | ||||
$next['recurrence_date'] = clone $next_start; | $next['recurrence_date'] = clone $next_start; | ||||
$next['_instance'] = libcalendaring::recurrence_instance_identifier($next, $this->event['allday']); | $next['_instance'] = libcalendaring::recurrence_instance_identifier($next, $this->event['allday']); | ||||
unset($next['_formatobj']); | unset($next['_formatobj']); | ||||
return $next; | return $next; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} | } |