annotate plugins/calendar/lib/calendar_recurrence.php @ 38:ac106d4c8961 default tip

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