Mercurial > hg > rc1
comparison plugins/calendar/lib/calendar_recurrence.php @ 3:f6fe4b6ae66a
calendar plugin nearly as distributed
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 08:56:12 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:c828b0fd4a6e | 3:f6fe4b6ae66a |
---|---|
1 <?php | |
2 | |
3 require_once realpath(__DIR__ . '/../../libcalendaring/lib/libcalendaring_recurrence.php'); | |
4 | |
5 /** | |
6 * Recurrence computation class for the Calendar plugin | |
7 * | |
8 * Uitility class to compute instances of recurring events. | |
9 * | |
10 * @author Thomas Bruederli <bruederli@kolabsys.com> | |
11 * | |
12 * Copyright (C) 2012-2014, Kolab Systems AG <contact@kolabsys.com> | |
13 * | |
14 * This program is free software: you can redistribute it and/or modify | |
15 * it under the terms of the GNU Affero General Public License as | |
16 * published by the Free Software Foundation, either version 3 of the | |
17 * License, or (at your option) any later version. | |
18 * | |
19 * This program is distributed in the hope that it will be useful, | |
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 * GNU Affero General Public License for more details. | |
23 * | |
24 * You should have received a copy of the GNU Affero General Public License | |
25 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
26 */ | |
27 class calendar_recurrence extends libcalendaring_recurrence | |
28 { | |
29 private $event; | |
30 private $duration; | |
31 | |
32 /** | |
33 * Default constructor | |
34 * | |
35 * @param object calendar The calendar plugin instance | |
36 * @param array The event object to operate on | |
37 */ | |
38 function __construct($cal, $event) | |
39 { | |
40 parent::__construct($cal->lib); | |
41 | |
42 $this->event = $event; | |
43 | |
44 if (is_object($event['start']) && is_object($event['end'])) | |
45 $this->duration = $event['start']->diff($event['end']); | |
46 | |
47 $event['start']->_dateonly |= $event['allday']; | |
48 $this->init($event['recurrence'], $event['start']); | |
49 } | |
50 | |
51 /** | |
52 * Alias of libcalendaring_recurrence::next() | |
53 * | |
54 * @return mixed DateTime object or False if recurrence ended | |
55 */ | |
56 public function next_start() | |
57 { | |
58 return $this->next(); | |
59 } | |
60 | |
61 /** | |
62 * Get the next recurring instance of this event | |
63 * | |
64 * @return mixed Array with event properties or False if recurrence ended | |
65 */ | |
66 public function next_instance() | |
67 { | |
68 if ($next_start = $this->next()) { | |
69 $next = $this->event; | |
70 $next['start'] = $next_start; | |
71 | |
72 if ($this->duration) { | |
73 $next['end'] = clone $next_start; | |
74 $next['end']->add($this->duration); | |
75 } | |
76 | |
77 $next['recurrence_date'] = clone $next_start; | |
78 $next['_instance'] = libcalendaring::recurrence_instance_identifier($next, $this->event['allday']); | |
79 | |
80 unset($next['_formatobj']); | |
81 | |
82 return $next; | |
83 } | |
84 | |
85 return false; | |
86 } | |
87 | |
88 } |