annotate plugins/calendar/lib/Horde_Date_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 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4 * This is a modified copy of Horde/Date/Recurrence.php
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5 * Pull the latest version of this file from the PEAR channel of the Horde
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6 * project at http://pear.horde.org by installing the Horde_Date package.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
7 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
8
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
9 if (!class_exists('Horde_Date'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
10 require_once(dirname(__FILE__) . '/Horde_Date.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
11
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
12 // minimal required implementation of Horde_Date_Translation to avoid a huge dependency nightmare
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
13 class Horde_Date_Translation
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
14 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
15 function t($arg) { return $arg; }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
16 function ngettext($sing, $plur, $num) { return ($num > 1 ? $plur : $sing); }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
17 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
18
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
19
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
20 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
21 * This file contains the Horde_Date_Recurrence class and according constants.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
22 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
23 * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
24 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
25 * See the enclosed file COPYING for license information (LGPL). If you
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
26 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
27 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
28 * @category Horde
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
29 * @package Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
30 */
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 * The Horde_Date_Recurrence class implements algorithms for calculating
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
34 * recurrences of events, including several recurrence types, intervals,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
35 * exceptions, and conversion from and to vCalendar and iCalendar recurrence
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
36 * rules.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
37 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
38 * All methods expecting dates as parameters accept all values that the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
39 * Horde_Date constructor accepts, i.e. a timestamp, another Horde_Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
40 * object, an ISO time string or a hash.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
41 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
42 * @author Jan Schneider <jan@horde.org>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
43 * @category Horde
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
44 * @package Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
45 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
46 class Horde_Date_Recurrence
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
47 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
48 /** No Recurrence **/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
49 const RECUR_NONE = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
50
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
51 /** Recurs daily. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
52 const RECUR_DAILY = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
53
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
54 /** Recurs weekly. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
55 const RECUR_WEEKLY = 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
56
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
57 /** Recurs monthly on the same date. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
58 const RECUR_MONTHLY_DATE = 3;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
59
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
60 /** Recurs monthly on the same week day. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
61 const RECUR_MONTHLY_WEEKDAY = 4;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
62
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
63 /** Recurs yearly on the same date. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
64 const RECUR_YEARLY_DATE = 5;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
65
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
66 /** Recurs yearly on the same day of the year. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
67 const RECUR_YEARLY_DAY = 6;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
68
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
69 /** Recurs yearly on the same week day. */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
70 const RECUR_YEARLY_WEEKDAY = 7;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
71
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
72 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
73 * The start time of the event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
74 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
75 * @var Horde_Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
76 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
77 public $start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
78
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
79 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
80 * The end date of the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
81 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
82 * @var Horde_Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
83 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
84 public $recurEnd = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
85
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
86 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
87 * The number of recurrences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
88 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
89 * @var integer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
90 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
91 public $recurCount = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
92
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
93 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
94 * The type of recurrence this event follows. RECUR_* constant.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
95 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
96 * @var integer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
97 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
98 public $recurType = self::RECUR_NONE;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
99
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
100 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
101 * The length of time between recurrences. The time unit depends on the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
102 * recurrence type.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
103 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
104 * @var integer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
105 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
106 public $recurInterval = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
107
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
108 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
109 * Any additional recurrence data.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
110 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
111 * @var integer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
112 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
113 public $recurData = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
114
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
115 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
116 * BYDAY recurrence number
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
117 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
118 * @var integer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
119 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
120 public $recurNthDay = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
121
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
122 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
123 * BYMONTH recurrence data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
124 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
125 * @var array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
126 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
127 public $recurMonths = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
128
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
129 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
130 * RDATE recurrence values
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
131 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
132 * @var array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
133 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
134 public $rdates = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
135
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
136 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
137 * All the exceptions from recurrence for this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
138 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
139 * @var array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
140 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
141 public $exceptions = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
142
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
143 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
144 * All the dates this recurrence has been marked as completed.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
145 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
146 * @var array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
147 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
148 public $completions = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
149
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
150 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
151 * Constructor.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
152 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
153 * @param Horde_Date $start Start of the recurring event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
154 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
155 public function __construct($start)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
156 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
157 $this->start = new Horde_Date($start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
158 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
159
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
160 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
161 * Resets the class properties.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
162 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
163 public function reset()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
164 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
165 $this->recurEnd = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
166 $this->recurCount = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
167 $this->recurType = self::RECUR_NONE;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
168 $this->recurInterval = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
169 $this->recurData = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
170 $this->exceptions = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
171 $this->completions = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
172 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
173
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
174 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
175 * Checks if this event recurs on a given day of the week.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
176 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
177 * @param integer $dayMask A mask consisting of Horde_Date::MASK_*
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
178 * constants specifying the day(s) to check.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
179 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
180 * @return boolean True if this event recurs on the given day(s).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
181 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
182 public function recurOnDay($dayMask)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
183 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
184 return ($this->recurData & $dayMask);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
185 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
186
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
187 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
188 * Specifies the days this event recurs on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
189 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
190 * @param integer $dayMask A mask consisting of Horde_Date::MASK_*
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
191 * constants specifying the day(s) to recur on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
192 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
193 public function setRecurOnDay($dayMask)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
194 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
195 $this->recurData = $dayMask;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
196 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
197
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
198 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
199 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
200 * @param integer $nthDay The nth weekday of month to repeat events on
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
201 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
202 public function setRecurNthWeekday($nth)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
203 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
204 $this->recurNthDay = (int)$nth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
205 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
206
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
207 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
208 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
209 * @return integer The nth weekday of month to repeat events.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
210 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
211 public function getRecurNthWeekday()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
212 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
213 return isset($this->recurNthDay) ? $this->recurNthDay : ceil($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
214 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
215
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
216 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
217 * Specifies the months for yearly (weekday) recurrence
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
218 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
219 * @param array $months List of months (integers) this event recurs on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
220 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
221 function setRecurByMonth($months)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
222 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
223 $this->recurMonths = (array)$months;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
225
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
226 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
227 * Returns a list of months this yearly event recurs on
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
228 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
229 * @return array List of months (integers) this event recurs on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
230 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
231 function getRecurByMonth()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
232 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
233 return $this->recurMonths;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
234 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
235
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
236 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
237 * Returns the days this event recurs on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
238 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
239 * @return integer A mask consisting of Horde_Date::MASK_* constants
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
240 * specifying the day(s) this event recurs on.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
241 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
242 public function getRecurOnDays()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
243 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
244 return $this->recurData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
245 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
247 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
248 * Returns whether this event has a specific recurrence type.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
249 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
250 * @param integer $recurrence RECUR_* constant of the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
251 * recurrence type to check for.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
252 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
253 * @return boolean True if the event has the specified recurrence type.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
254 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
255 public function hasRecurType($recurrence)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
256 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
257 return ($recurrence == $this->recurType);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
258 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
259
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
260 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
261 * Sets a recurrence type for this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
262 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
263 * @param integer $recurrence A RECUR_* constant.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
264 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
265 public function setRecurType($recurrence)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
266 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
267 $this->recurType = $recurrence;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
268 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
269
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
270 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
271 * Returns recurrence type of this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
272 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
273 * @return integer A RECUR_* constant.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
274 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
275 public function getRecurType()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
276 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
277 return $this->recurType;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
278 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
279
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
280 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
281 * Returns a description of this event's recurring type.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
282 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
283 * @return string Human readable recurring type.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
284 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
285 public function getRecurName()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
286 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
287 switch ($this->getRecurType()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
288 case self::RECUR_NONE: return Horde_Date_Translation::t("No recurrence");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
289 case self::RECUR_DAILY: return Horde_Date_Translation::t("Daily");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
290 case self::RECUR_WEEKLY: return Horde_Date_Translation::t("Weekly");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
291 case self::RECUR_MONTHLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
292 case self::RECUR_MONTHLY_WEEKDAY: return Horde_Date_Translation::t("Monthly");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
293 case self::RECUR_YEARLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
294 case self::RECUR_YEARLY_DAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
295 case self::RECUR_YEARLY_WEEKDAY: return Horde_Date_Translation::t("Yearly");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
296 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
297 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
298
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
299 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
300 * Sets the length of time between recurrences of this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
301 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
302 * @param integer $interval The time between recurrences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
303 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
304 public function setRecurInterval($interval)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
305 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
306 if ($interval > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
307 $this->recurInterval = $interval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
308 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
309 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
310
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
311 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
312 * Retrieves the length of time between recurrences of this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
313 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
314 * @return integer The number of seconds between recurrences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
315 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
316 public function getRecurInterval()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
317 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
318 return $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
319 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
320
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
321 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
322 * Sets the number of recurrences of this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
323 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
324 * @param integer $count The number of recurrences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
325 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
326 public function setRecurCount($count)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
327 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
328 if ($count > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
329 $this->recurCount = (int)$count;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
330 // Recurrence counts and end dates are mutually exclusive.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
331 $this->recurEnd = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
332 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
333 $this->recurCount = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
334 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
335 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
336
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
337 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
338 * Retrieves the number of recurrences of this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
339 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
340 * @return integer The number recurrences.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
341 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
342 public function getRecurCount()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
343 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
344 return $this->recurCount;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
345 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
346
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
347 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
348 * Returns whether this event has a recurrence with a fixed count.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
349 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
350 * @return boolean True if this recurrence has a fixed count.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
351 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
352 public function hasRecurCount()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
353 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
354 return isset($this->recurCount);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
355 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
356
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
357 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
358 * Sets the start date of the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
359 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
360 * @param Horde_Date $start The recurrence start.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
361 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
362 public function setRecurStart($start)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
363 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
364 $this->start = clone $start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
365 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
366
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
367 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
368 * Retrieves the start date of the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
369 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
370 * @return Horde_Date The recurrence start.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
371 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
372 public function getRecurStart()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
373 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
374 return $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
375 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
376
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
377 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
378 * Sets the end date of the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
379 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
380 * @param Horde_Date $end The recurrence end.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
381 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
382 public function setRecurEnd($end)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
383 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
384 if (!empty($end)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
385 // Recurrence counts and end dates are mutually exclusive.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
386 $this->recurCount = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
387 $this->recurEnd = clone $end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
388 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
389 $this->recurEnd = $end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
390 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
391 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
392
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
393 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
394 * Retrieves the end date of the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
395 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
396 * @return Horde_Date The recurrence end.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
397 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
398 public function getRecurEnd()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
399 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
400 return $this->recurEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
401 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
402
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
403 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
404 * Returns whether this event has a recurrence end.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
405 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
406 * @return boolean True if this recurrence ends.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
407 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
408 public function hasRecurEnd()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
409 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
410 return isset($this->recurEnd) && isset($this->recurEnd->year) &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
411 $this->recurEnd->year != 9999;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
412 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
413
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
414 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
415 * Finds the next recurrence of this event that's after $afterDate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
416 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
417 * @param Horde_Date|string $after Return events after this date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
418 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
419 * @return Horde_Date|boolean The date of the next recurrence or false
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
420 * if the event does not recur after
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
421 * $afterDate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
422 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
423 public function nextRecurrence($after)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
424 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
425 if (!($after instanceof Horde_Date)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
426 $after = new Horde_Date($after);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
427 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
428 $after = clone($after);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
429 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
430
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
431 // Make sure $after and $this->start are in the same TZ
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
432 $after->setTimezone($this->start->timezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
433 if ($this->start->compareDateTime($after) >= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
434 return clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
435 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
436
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
437 if ($this->recurInterval == 0 && empty($this->rdates)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
438 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
439 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
440
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
441 switch ($this->getRecurType()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
442 case self::RECUR_DAILY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
443 $diff = $this->start->diff($after);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
444 $recur = ceil($diff / $this->recurInterval);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
445 if ($this->recurCount && $recur >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
446 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
447 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
448
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
449 $recur *= $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
450 $next = $this->start->add(array('day' => $recur));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
451 if ((!$this->hasRecurEnd() ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
452 $next->compareDateTime($this->recurEnd) <= 0) &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
453 $next->compareDateTime($after) >= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
454 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
455 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
456 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
457
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
458 case self::RECUR_WEEKLY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
459 if (empty($this->recurData)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
460 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
461 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
462
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
463 $start_week = Horde_Date_Utils::firstDayOfWeek($this->start->format('W'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
464 $this->start->year);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
465 $start_week->timezone = $this->start->timezone;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
466 $start_week->hour = $this->start->hour;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
467 $start_week->min = $this->start->min;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
468 $start_week->sec = $this->start->sec;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
469
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
470 // Make sure we are not at the ISO-8601 first week of year while
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
471 // still in month 12...OR in the ISO-8601 last week of year while
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
472 // in month 1 and adjust the year accordingly.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
473 $week = $after->format('W');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
474 if ($week == 1 && $after->month == 12) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
475 $theYear = $after->year + 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
476 } elseif ($week >= 52 && $after->month == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
477 $theYear = $after->year - 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
478 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
479 $theYear = $after->year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
480 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
481
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
482 $after_week = Horde_Date_Utils::firstDayOfWeek($week, $theYear);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
483 $after_week->timezone = $this->start->timezone;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
484 $after_week_end = clone $after_week;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
485 $after_week_end->mday += 7;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
486
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
487 $diff = $start_week->diff($after_week);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
488 $interval = $this->recurInterval * 7;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
489 $repeats = floor($diff / $interval);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
490 if ($diff % $interval < 7) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
491 $recur = $diff;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
492 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
493 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
494 * If the after_week is not in the first week interval the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
495 * search needs to skip ahead a complete interval. The way it is
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
496 * calculated here means that an event that occurs every second
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
497 * week on Monday and Wednesday with the event actually starting
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
498 * on Tuesday or Wednesday will only have one incidence in the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
499 * first week.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
500 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
501 $recur = $interval * ($repeats + 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
502 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
503
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
504 if ($this->hasRecurCount()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
505 $recurrences = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
506 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
507 * Correct the number of recurrences by the number of events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
508 * that lay between the start of the start week and the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
509 * recurrence start.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
510 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
511 $next = clone $start_week;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
512 while ($next->compareDateTime($this->start) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
513 if ($this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
514 $recurrences--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
516 ++$next->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
517 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
518 if ($repeats > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
519 $weekdays = $this->recurData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
520 $total_recurrences_per_week = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
521 while ($weekdays > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
522 if ($weekdays % 2) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
523 $total_recurrences_per_week++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
524 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
525 $weekdays = ($weekdays - ($weekdays % 2)) / 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
526 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
527 $recurrences += $total_recurrences_per_week * $repeats;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
528 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
529 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
530
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
531 $next = clone $start_week;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
532 $next->mday += $recur;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
533 while ($next->compareDateTime($after) < 0 &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
534 $next->compareDateTime($after_week_end) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
535 if ($this->hasRecurCount()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
536 && $next->compareDateTime($after) < 0
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
537 && $this->recurOnDay((int)pow(2, $next->dayOfWeek()))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
538 $recurrences++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
539 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
540 ++$next->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
541 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
542 if ($this->hasRecurCount() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
543 $recurrences >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
544 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
545 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
546 if (!$this->hasRecurEnd() ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
547 $next->compareDateTime($this->recurEnd) <= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
548 if ($next->compareDateTime($after_week_end) >= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
549 return $this->nextRecurrence($after_week_end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
550 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
551 while (!$this->recurOnDay((int)pow(2, $next->dayOfWeek())) &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
552 $next->compareDateTime($after_week_end) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
553 ++$next->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
554 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
555 if (!$this->hasRecurEnd() ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
556 $next->compareDateTime($this->recurEnd) <= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
557 if ($next->compareDateTime($after_week_end) >= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
558 return $this->nextRecurrence($after_week_end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
559 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
560 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
561 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
562 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
563 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
564 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
565
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
566 case self::RECUR_MONTHLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
567 $start = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
568 if ($after->compareDateTime($start) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
569 $after = clone $start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
570 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
571 $after = clone $after;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
572 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
573
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
574 // If we're starting past this month's recurrence of the event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
575 // look in the next month on the day the event recurs.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
576 if ($after->mday > $start->mday) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
577 ++$after->month;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
578 $after->mday = $start->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
579 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
580
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
581 // Adjust $start to be the first match.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
582 $offset = ($after->month - $start->month) + ($after->year - $start->year) * 12;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
583 $offset = floor(($offset + $this->recurInterval - 1) / $this->recurInterval) * $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
584
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
585 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
586 ($offset / $this->recurInterval) >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
587 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
588 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
589 $start->month += $offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
590 $count = $offset / $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
591
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
592 do {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
593 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
594 $count++ >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
595 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
596 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
597
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
598 // Bail if we've gone past the end of recurrence.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
599 if ($this->hasRecurEnd() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
600 $this->recurEnd->compareDateTime($start) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
601 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
602 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
603 if ($start->isValid()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
604 return $start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
605 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
606
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
607 // If the interval is 12, and the date isn't valid, then we
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
608 // need to see if February 29th is an option. If not, then the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
609 // event will _never_ recur, and we need to stop checking to
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
610 // avoid an infinite loop.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
611 if ($this->recurInterval == 12 && ($start->month != 2 || $start->mday > 29)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
612 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
613 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
614
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
615 // Add the recurrence interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
616 $start->month += $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
617 } while (true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
618
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
619 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
620
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
621 case self::RECUR_MONTHLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
622 // Start with the start date of the event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
623 $estart = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
624
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
625 // What day of the week, and week of the month, do we recur on?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
626 if (isset($this->recurNthDay)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
627 $nth = $this->recurNthDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
628 $weekday = log($this->recurData, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
629 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
630 $nth = ceil($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
631 $weekday = $estart->dayOfWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
632 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
633
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
634 // Adjust $estart to be the first candidate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
635 $offset = ($after->month - $estart->month) + ($after->year - $estart->year) * 12;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
636 $offset = floor(($offset + $this->recurInterval - 1) / $this->recurInterval) * $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
637
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
638 // Adjust our working date until it's after $after.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
639 $estart->month += $offset - $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
640
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
641 $count = $offset / $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
642 do {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
643 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
644 $count++ >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
645 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
646 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
647
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
648 $estart->month += $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
649
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
650 $next = clone $estart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
651 $next->setNthWeekday($weekday, $nth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
652
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
653 if ($next->compareDateTime($after) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
654 // We haven't made it past $after yet, try again.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
655 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
656 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
657 if ($this->hasRecurEnd() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
658 $next->compareDateTime($this->recurEnd) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
659 // We've gone past the end of recurrence; we can give up
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
660 // now.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
661 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
662 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
663
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
664 // We have a candidate to return.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
665 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
666 } while (true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
667
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
668 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
669
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
670 case self::RECUR_YEARLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
671 // Start with the start date of the event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
672 $estart = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
673 $after = clone $after;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
674
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
675 if ($after->month > $estart->month ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
676 ($after->month == $estart->month && $after->mday > $estart->mday)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
677 ++$after->year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
678 $after->month = $estart->month;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
679 $after->mday = $estart->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
680 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
681
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
682 // Seperate case here for February 29th
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
683 if ($estart->month == 2 && $estart->mday == 29) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
684 while (!Horde_Date_Utils::isLeapYear($after->year)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
685 ++$after->year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
686 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
689 // Adjust $estart to be the first candidate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
690 $offset = $after->year - $estart->year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
691 if ($offset > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
692 $offset = floor(($offset + $this->recurInterval - 1) / $this->recurInterval) * $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
693 $estart->year += $offset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
694 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
695
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
696 // We've gone past the end of recurrence; give up.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
697 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
698 $offset >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
699 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
700 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
701 if ($this->hasRecurEnd() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
702 $this->recurEnd->compareDateTime($estart) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
703 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
704 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
706 return $estart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
707
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
708 case self::RECUR_YEARLY_DAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
709 // Check count first.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
710 $dayofyear = $this->start->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
711 $count = ($after->year - $this->start->year) / $this->recurInterval + 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
712 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
713 ($count > $this->recurCount ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
714 ($count == $this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
715 $after->dayOfYear() > $dayofyear))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
716 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
717 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
718
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
719 // Start with a rough interval.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
720 $estart = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
721 $estart->year += floor($count - 1) * $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
722
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
723 // Now add the difference to the required day of year.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
724 $estart->mday += $dayofyear - $estart->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
725
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
726 // Add an interval if the estimation was wrong.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
727 if ($estart->compareDate($after) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
728 $estart->year += $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
729 $estart->mday += $dayofyear - $estart->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
730 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
731
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
732 // We've gone past the end of recurrence; give up.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
733 if ($this->hasRecurEnd() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
734 $this->recurEnd->compareDateTime($estart) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
735 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
736 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
737
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
738 return $estart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
739
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
740 case self::RECUR_YEARLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
741 // Start with the start date of the event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
742 $estart = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
743
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
744 // What day of the week, and week of the month, do we recur on?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
745 if (isset($this->recurNthDay)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
746 $nth = $this->recurNthDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
747 $weekday = log($this->recurData, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
748 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
749 $nth = ceil($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
750 $weekday = $estart->dayOfWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
751 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
752
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
753 // Adjust $estart to be the first candidate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
754 $offset = floor(($after->year - $estart->year + $this->recurInterval - 1) / $this->recurInterval) * $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
755
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
756 // Adjust our working date until it's after $after.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
757 $estart->year += $offset - $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
758
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
759 $count = $offset / $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
760 do {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
761 if ($this->recurCount &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
762 $count++ >= $this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
763 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
764 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
765
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
766 $estart->year += $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
767
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
768 $next = clone $estart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
769 $next->setNthWeekday($weekday, $nth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
770
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
771 if ($next->compareDateTime($after) < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
772 // We haven't made it past $after yet, try again.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
773 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
774 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
775 if ($this->hasRecurEnd() &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
776 $next->compareDateTime($this->recurEnd) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
777 // We've gone past the end of recurrence; we can give up
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
778 // now.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
779 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
780 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
781
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
782 // We have a candidate to return.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
783 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
784 } while (true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
785
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
786 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
787 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
788
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
789 // fall-back to RDATE properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
790 if (!empty($this->rdates)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
791 $next = clone $this->start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
792 foreach ($this->rdates as $rdate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
793 $next->year = $rdate->year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
794 $next->month = $rdate->month;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
795 $next->mday = $rdate->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
796 if ($next->compareDateTime($after) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
797 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
798 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
799 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
800 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
801
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
802 // We didn't find anything, the recurType was bad, or something else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
803 // went wrong - return false.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
804 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
805 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
806
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
807 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
808 * Returns whether this event has any date that matches the recurrence
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
809 * rules and is not an exception.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
810 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
811 * @return boolean True if an active recurrence exists.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
812 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
813 public function hasActiveRecurrence()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
814 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
815 if (!$this->hasRecurEnd()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
816 return true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
817 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
818
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
819 $next = $this->nextRecurrence(new Horde_Date($this->start));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
820 while (is_object($next)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
821 if (!$this->hasException($next->year, $next->month, $next->mday) &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
822 !$this->hasCompletion($next->year, $next->month, $next->mday)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
823 return true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
824 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
825
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
826 $next = $this->nextRecurrence($next->add(array('day' => 1)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
827 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
828
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
829 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
830 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
831
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
832 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
833 * Returns the next active recurrence.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
834 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
835 * @param Horde_Date $afterDate Return events after this date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
836 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
837 * @return Horde_Date|boolean The date of the next active
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
838 * recurrence or false if the event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
839 * has no active recurrence after
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
840 * $afterDate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
841 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
842 public function nextActiveRecurrence($afterDate)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
843 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
844 $next = $this->nextRecurrence($afterDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
845 while (is_object($next)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
846 if (!$this->hasException($next->year, $next->month, $next->mday) &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
847 !$this->hasCompletion($next->year, $next->month, $next->mday)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
848 return $next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
849 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
850 $next->mday++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
851 $next = $this->nextRecurrence($next);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
852 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
853
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
854 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
855 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
856
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
857 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
858 * Adds an absolute recurrence date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
859 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
860 * @param integer $year The year of the instance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
861 * @param integer $month The month of the instance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
862 * @param integer $mday The day of the month of the instance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
863 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
864 public function addRDate($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
865 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
866 $this->rdates[] = new Horde_Date($year, $month, $mday);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
867 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
868
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
869 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
870 * Adds an exception to a recurring event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
871 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
872 * @param integer $year The year of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
873 * @param integer $month The month of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
874 * @param integer $mday The day of the month of the exception.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
875 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
876 public function addException($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
877 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
878 $this->exceptions[] = sprintf('%04d%02d%02d', $year, $month, $mday);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
879 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
880
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
881 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
882 * Deletes an exception from a recurring event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
883 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
884 * @param integer $year The year of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
885 * @param integer $month The month of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
886 * @param integer $mday The day of the month of the exception.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
887 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
888 public function deleteException($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
889 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
890 $key = array_search(sprintf('%04d%02d%02d', $year, $month, $mday), $this->exceptions);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
891 if ($key !== false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
892 unset($this->exceptions[$key]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
893 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
894 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
895
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
896 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
897 * Checks if an exception exists for a given reccurence of an event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
898 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
899 * @param integer $year The year of the reucrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
900 * @param integer $month The month of the reucrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
901 * @param integer $mday The day of the month of the reucrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
902 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
903 * @return boolean True if an exception exists for the given date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
904 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
905 public function hasException($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
906 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
907 return in_array(sprintf('%04d%02d%02d', $year, $month, $mday),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
908 $this->getExceptions());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
909 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
910
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
911 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
912 * Retrieves all the exceptions for this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
913 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
914 * @return array Array containing the dates of all the exceptions in
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
915 * YYYYMMDD form.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
916 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
917 public function getExceptions()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
918 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
919 return $this->exceptions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
920 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
921
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
922 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
923 * Adds a completion to a recurring event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
924 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
925 * @param integer $year The year of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
926 * @param integer $month The month of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
927 * @param integer $mday The day of the month of the completion.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
928 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
929 public function addCompletion($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
930 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
931 $this->completions[] = sprintf('%04d%02d%02d', $year, $month, $mday);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
932 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
933
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
934 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
935 * Deletes a completion from a recurring event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
936 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
937 * @param integer $year The year of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
938 * @param integer $month The month of the execption.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
939 * @param integer $mday The day of the month of the completion.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
940 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
941 public function deleteCompletion($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
942 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
943 $key = array_search(sprintf('%04d%02d%02d', $year, $month, $mday), $this->completions);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
944 if ($key !== false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
945 unset($this->completions[$key]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
946 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
947 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
948
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
949 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
950 * Checks if a completion exists for a given reccurence of an event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
951 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
952 * @param integer $year The year of the reucrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
953 * @param integer $month The month of the recurrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
954 * @param integer $mday The day of the month of the recurrance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
955 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
956 * @return boolean True if a completion exists for the given date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
957 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
958 public function hasCompletion($year, $month, $mday)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
959 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
960 return in_array(sprintf('%04d%02d%02d', $year, $month, $mday),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
961 $this->getCompletions());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
962 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
963
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
964 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
965 * Retrieves all the completions for this event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
966 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
967 * @return array Array containing the dates of all the completions in
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
968 * YYYYMMDD form.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
969 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
970 public function getCompletions()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
971 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
972 return $this->completions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
973 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
974
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
975 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
976 * Parses a vCalendar 1.0 recurrence rule.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
977 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
978 * @link http://www.imc.org/pdi/vcal-10.txt
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
979 * @link http://www.shuchow.com/vCalAddendum.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
980 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
981 * @param string $rrule A vCalendar 1.0 conform RRULE value.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
982 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
983 public function fromRRule10($rrule)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
984 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
985 $this->reset();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
986
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
987 if (!$rrule) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
988 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
989 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
990
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
991 if (!preg_match('/([A-Z]+)(\d+)?(.*)/', $rrule, $matches)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
992 // No recurrence data - event does not recur.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
993 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
994 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
995
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
996 // Always default the recurInterval to 1.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
997 $this->setRecurInterval(!empty($matches[2]) ? $matches[2] : 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
998
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
999 $remainder = trim($matches[3]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1000
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1001 switch ($matches[1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1002 case 'D':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1003 $this->setRecurType(self::RECUR_DAILY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1004 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1005
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1006 case 'W':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1007 $this->setRecurType(self::RECUR_WEEKLY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1008 if (!empty($remainder)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1009 $mask = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1010 while (preg_match('/^ ?[A-Z]{2} ?/', $remainder, $matches)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1011 $day = trim($matches[0]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1012 $remainder = substr($remainder, strlen($matches[0]));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1013 $mask |= $maskdays[$day];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1014 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1015 $this->setRecurOnDay($mask);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1016 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1017 // Recur on the day of the week of the original recurrence.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1018 $maskdays = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1019 Horde_Date::DATE_SUNDAY => Horde_Date::MASK_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1020 Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1021 Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1022 Horde_Date::DATE_WEDNESDAY => Horde_Date::MASK_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1023 Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1024 Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1025 Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1026 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1027 $this->setRecurOnDay($maskdays[$this->start->dayOfWeek()]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1028 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1029 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1030
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1031 case 'MP':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1032 $this->setRecurType(self::RECUR_MONTHLY_WEEKDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1033 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1034
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1035 case 'MD':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1036 $this->setRecurType(self::RECUR_MONTHLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1037 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1038
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1039 case 'YM':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1040 $this->setRecurType(self::RECUR_YEARLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1041 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1042
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1043 case 'YD':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1044 $this->setRecurType(self::RECUR_YEARLY_DAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1045 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1046 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1047
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1048 // We don't support modifiers at the moment, strip them.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1049 while ($remainder && !preg_match('/^(#\d+|\d{8})($| |T\d{6})/', $remainder)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1050 $remainder = substr($remainder, 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1051 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1052 if (!empty($remainder)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1053 if (strpos($remainder, '#') === 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1054 $this->setRecurCount(substr($remainder, 1));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1055 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1056 list($year, $month, $mday) = sscanf($remainder, '%04d%02d%02d');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1057 $this->setRecurEnd(new Horde_Date(array('year' => $year,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1058 'month' => $month,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1059 'mday' => $mday,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1060 'hour' => 23,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1061 'min' => 59,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1062 'sec' => 59)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1063 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1064 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1065 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1066
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1067 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1068 * Creates a vCalendar 1.0 recurrence rule.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1069 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1070 * @link http://www.imc.org/pdi/vcal-10.txt
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1071 * @link http://www.shuchow.com/vCalAddendum.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1072 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1073 * @param Horde_Icalendar $calendar A Horde_Icalendar object instance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1074 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1075 * @return string A vCalendar 1.0 conform RRULE value.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1076 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1077 public function toRRule10($calendar)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1078 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1079 switch ($this->recurType) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1080 case self::RECUR_NONE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1081 return '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1082
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1083 case self::RECUR_DAILY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1084 $rrule = 'D' . $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1085 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1086
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1087 case self::RECUR_WEEKLY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1088 $rrule = 'W' . $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1089 $vcaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1090
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1091 for ($i = 0; $i <= 7; ++$i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1092 if ($this->recurOnDay(pow(2, $i))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1093 $rrule .= ' ' . $vcaldays[$i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1094 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1095 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1096 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1097
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1098 case self::RECUR_MONTHLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1099 $rrule = 'MD' . $this->recurInterval . ' ' . trim($this->start->mday);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1100 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1101
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1102 case self::RECUR_MONTHLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1103 $nth_weekday = (int)($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1104 if (($this->start->mday % 7) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1105 $nth_weekday++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1106 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1107
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1108 $vcaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1109 $rrule = 'MP' . $this->recurInterval . ' ' . $nth_weekday . '+ ' . $vcaldays[$this->start->dayOfWeek()];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1110
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1111 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1112
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1113 case self::RECUR_YEARLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1114 $rrule = 'YM' . $this->recurInterval . ' ' . trim($this->start->month);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1115 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1116
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1117 case self::RECUR_YEARLY_DAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1118 $rrule = 'YD' . $this->recurInterval . ' ' . $this->start->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1119 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1120
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1121 default:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1122 return '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1123 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1124
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1125 if ($this->hasRecurEnd()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1126 $recurEnd = clone $this->recurEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1127 return $rrule . ' ' . $calendar->_exportDateTime($recurEnd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1128 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1129
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1130 return $rrule . ' #' . (int)$this->getRecurCount();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1131 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1132
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1133 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1134 * Parses an iCalendar 2.0 recurrence rule.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1135 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1136 * @link http://rfc.net/rfc2445.html#s4.3.10
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1137 * @link http://rfc.net/rfc2445.html#s4.8.5
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1138 * @link http://www.shuchow.com/vCalAddendum.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1139 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1140 * @param string $rrule An iCalendar 2.0 conform RRULE value.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1141 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1142 public function fromRRule20($rrule)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1143 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1144 $this->reset();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1145
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1146 // Parse the recurrence rule into keys and values.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1147 $rdata = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1148 $parts = explode(';', $rrule);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1149 foreach ($parts as $part) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1150 list($key, $value) = explode('=', $part, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1151 $rdata[strtoupper($key)] = $value;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1152 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1153
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1154 if (isset($rdata['FREQ'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1155 // Always default the recurInterval to 1.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1156 $this->setRecurInterval(isset($rdata['INTERVAL']) ? $rdata['INTERVAL'] : 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1157
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1158 $maskdays = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1159 'SU' => Horde_Date::MASK_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1160 'MO' => Horde_Date::MASK_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1161 'TU' => Horde_Date::MASK_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1162 'WE' => Horde_Date::MASK_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1163 'TH' => Horde_Date::MASK_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1164 'FR' => Horde_Date::MASK_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1165 'SA' => Horde_Date::MASK_SATURDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1166 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1167
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1168 switch (strtoupper($rdata['FREQ'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1169 case 'DAILY':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1170 $this->setRecurType(self::RECUR_DAILY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1171 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1172
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1173 case 'WEEKLY':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1174 $this->setRecurType(self::RECUR_WEEKLY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1175 if (isset($rdata['BYDAY'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1176 $days = explode(',', $rdata['BYDAY']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1177 $mask = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1178 foreach ($days as $day) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1179 $mask |= $maskdays[$day];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1180 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1181 $this->setRecurOnDay($mask);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1182 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1183 // Recur on the day of the week of the original
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1184 // recurrence.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1185 $maskdays = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1186 Horde_Date::DATE_SUNDAY => Horde_Date::MASK_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1187 Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1188 Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1189 Horde_Date::DATE_WEDNESDAY => Horde_Date::MASK_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1190 Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1191 Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1192 Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1193 $this->setRecurOnDay($maskdays[$this->start->dayOfWeek()]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1194 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1195 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1196
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1197 case 'MONTHLY':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1198 if (isset($rdata['BYDAY'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1199 $this->setRecurType(self::RECUR_MONTHLY_WEEKDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1200 if (preg_match('/(-?[1-4])([A-Z]+)/', $rdata['BYDAY'], $m)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1201 $this->setRecurOnDay($maskdays[$m[2]]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1202 $this->setRecurNthWeekday($m[1]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1203 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1204 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1205 $this->setRecurType(self::RECUR_MONTHLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1206 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1207 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1208
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1209 case 'YEARLY':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1210 if (isset($rdata['BYYEARDAY'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1211 $this->setRecurType(self::RECUR_YEARLY_DAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1212 } elseif (isset($rdata['BYDAY'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1213 $this->setRecurType(self::RECUR_YEARLY_WEEKDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1214 if (preg_match('/(-?[1-4])([A-Z]+)/', $rdata['BYDAY'], $m)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1215 $this->setRecurOnDay($maskdays[$m[2]]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1216 $this->setRecurNthWeekday($m[1]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1217 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1218 if ($rdata['BYMONTH']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1219 $months = explode(',', $rdata['BYMONTH']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1220 $this->setRecurByMonth($months);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1221 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1222 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1223 $this->setRecurType(self::RECUR_YEARLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1225 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1226 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1227
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1228 if (isset($rdata['UNTIL'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1229 list($year, $month, $mday) = sscanf($rdata['UNTIL'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1230 '%04d%02d%02d');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1231 $this->setRecurEnd(new Horde_Date(array('year' => $year,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1232 'month' => $month,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1233 'mday' => $mday,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1234 'hour' => 23,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1235 'min' => 59,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1236 'sec' => 59)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1237 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1238 if (isset($rdata['COUNT'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1239 $this->setRecurCount($rdata['COUNT']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1240 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1241 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1242 // No recurrence data - event does not recur.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1243 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1244 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1245 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1247 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1248 * Creates an iCalendar 2.0 recurrence rule.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1249 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1250 * @link http://rfc.net/rfc2445.html#s4.3.10
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1251 * @link http://rfc.net/rfc2445.html#s4.8.5
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1252 * @link http://www.shuchow.com/vCalAddendum.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1253 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1254 * @param Horde_Icalendar $calendar A Horde_Icalendar object instance.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1255 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1256 * @return string An iCalendar 2.0 conform RRULE value.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1257 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1258 public function toRRule20($calendar)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1259 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1260 switch ($this->recurType) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1261 case self::RECUR_NONE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1262 return '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1263
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1264 case self::RECUR_DAILY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1265 $rrule = 'FREQ=DAILY;INTERVAL=' . $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1266 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1267
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1268 case self::RECUR_WEEKLY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1269 $rrule = 'FREQ=WEEKLY;INTERVAL=' . $this->recurInterval . ';BYDAY=';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1270 $vcaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1271
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1272 for ($i = $flag = 0; $i <= 7; ++$i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1273 if ($this->recurOnDay(pow(2, $i))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1274 if ($flag) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1275 $rrule .= ',';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1276 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1277 $rrule .= $vcaldays[$i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1278 $flag = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1279 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1280 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1281 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1282
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1283 case self::RECUR_MONTHLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1284 $rrule = 'FREQ=MONTHLY;INTERVAL=' . $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1285 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1286
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1287 case self::RECUR_MONTHLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1288 if (isset($this->recurNthDay)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1289 $nth_weekday = $this->recurNthDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1290 $day_of_week = log($this->recurData, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1291 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1292 $day_of_week = $this->start->dayOfWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1293 $nth_weekday = (int)($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1294 if (($this->start->mday % 7) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1295 $nth_weekday++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1296 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1297 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1298 $vcaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1299 $rrule = 'FREQ=MONTHLY;INTERVAL=' . $this->recurInterval
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1300 . ';BYDAY=' . $nth_weekday . $vcaldays[$day_of_week];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1301 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1302
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1303 case self::RECUR_YEARLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1304 $rrule = 'FREQ=YEARLY;INTERVAL=' . $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1305 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1306
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1307 case self::RECUR_YEARLY_DAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1308 $rrule = 'FREQ=YEARLY;INTERVAL=' . $this->recurInterval
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1309 . ';BYYEARDAY=' . $this->start->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1310 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1311
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1312 case self::RECUR_YEARLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1313 if (isset($this->recurNthDay)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1314 $nth_weekday = $this->recurNthDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1315 $day_of_week = log($this->recurData, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1316 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1317 $day_of_week = $this->start->dayOfWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1318 $nth_weekday = (int)($this->start->mday / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1319 if (($this->start->mday % 7) > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1320 $nth_weekday++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1321 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1322 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1323 $months = !empty($this->recurMonths) ? join(',', $this->recurMonths) : $this->start->month;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1324 $vcaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1325 $rrule = 'FREQ=YEARLY;INTERVAL=' . $this->recurInterval
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1326 . ';BYDAY='
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1327 . $nth_weekday
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1328 . $vcaldays[$day_of_week]
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1329 . ';BYMONTH=' . $this->start->month;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1330 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1331 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1332
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1333 if ($this->hasRecurEnd()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1334 $recurEnd = clone $this->recurEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1335 $rrule .= ';UNTIL=' . $calendar->_exportDateTime($recurEnd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1336 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1337 if ($count = $this->getRecurCount()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1338 $rrule .= ';COUNT=' . $count;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1339 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1340 return $rrule;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1341 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1343 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1344 * Parses the recurrence data from a hash.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1345 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1346 * @param array $hash The hash to convert.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1347 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1348 * @return boolean True if the hash seemed valid, false otherwise.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1349 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1350 public function fromHash($hash)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1351 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1352 $this->reset();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1353
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1354 if (!isset($hash['interval']) || !isset($hash['cycle'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1355 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1356 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1357 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1358
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1359 $this->setRecurInterval((int)$hash['interval']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1360
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1361 $month2number = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1362 'january' => 1,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1363 'february' => 2,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1364 'march' => 3,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1365 'april' => 4,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1366 'may' => 5,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1367 'june' => 6,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1368 'july' => 7,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1369 'august' => 8,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1370 'september' => 9,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1371 'october' => 10,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1372 'november' => 11,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1373 'december' => 12,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1374 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1375
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1376 $parse_day = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1377 $set_daymask = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1378 $update_month = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1379 $update_daynumber = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1380 $update_weekday = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1381 $nth_weekday = -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1382
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1383 switch ($hash['cycle']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1384 case 'daily':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1385 $this->setRecurType(self::RECUR_DAILY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1386 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1387
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1388 case 'weekly':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1389 $this->setRecurType(self::RECUR_WEEKLY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1390 $parse_day = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1391 $set_daymask = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1392 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1393
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1394 case 'monthly':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1395 if (!isset($hash['daynumber'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1396 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1397 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1398 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1399
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1400 switch ($hash['type']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1401 case 'daynumber':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1402 $this->setRecurType(self::RECUR_MONTHLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1403 $update_daynumber = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1404 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1405
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1406 case 'weekday':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1407 $this->setRecurType(self::RECUR_MONTHLY_WEEKDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1408 $this->setRecurNthWeekday($hash['daynumber']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1409 $parse_day = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1410 $set_daymask = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1411 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1412 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1413 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1414
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1415 case 'yearly':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1416 if (!isset($hash['type'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1417 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1418 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1419 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1420
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1421 switch ($hash['type']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1422 case 'monthday':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1423 $this->setRecurType(self::RECUR_YEARLY_DATE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1424 $update_month = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1425 $update_daynumber = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1426 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1427
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1428 case 'yearday':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1429 if (!isset($hash['month'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1430 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1431 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1432 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1433
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1434 $this->setRecurType(self::RECUR_YEARLY_DAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1435 // Start counting days in January.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1436 $hash['month'] = 'january';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1437 $update_month = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1438 $update_daynumber = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1439 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1440
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1441 case 'weekday':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1442 if (!isset($hash['daynumber'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1443 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1444 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1445 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1446
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1447 $this->setRecurType(self::RECUR_YEARLY_WEEKDAY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1448 $this->setRecurNthWeekday($hash['daynumber']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1449 $parse_day = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1450 $set_daymask = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1451
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1452 if ($hash['month'] && isset($month2number[$hash['month']])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1453 $this->setRecurByMonth($month2number[$hash['month']]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1454 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1455 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1456 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1457 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1458
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1459 if (isset($hash['range-type']) && isset($hash['range'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1460 switch ($hash['range-type']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1461 case 'number':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1462 $this->setRecurCount((int)$hash['range']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1463 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1464
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1465 case 'date':
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1466 $recur_end = new Horde_Date($hash['range']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1467 $recur_end->hour = 23;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1468 $recur_end->min = 59;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1469 $recur_end->sec = 59;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1470 $this->setRecurEnd($recur_end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1471 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1472 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1473 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1474
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1475 // Need to parse <day>?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1476 $last_found_day = -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1477 if ($parse_day) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1478 if (!isset($hash['day'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1479 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1480 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1481 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1482
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1483 $mask = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1484 $bits = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1485 'monday' => Horde_Date::MASK_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1486 'tuesday' => Horde_Date::MASK_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1487 'wednesday' => Horde_Date::MASK_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1488 'thursday' => Horde_Date::MASK_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1489 'friday' => Horde_Date::MASK_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1490 'saturday' => Horde_Date::MASK_SATURDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1491 'sunday' => Horde_Date::MASK_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1492 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1493 $days = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1494 'monday' => Horde_Date::DATE_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1495 'tuesday' => Horde_Date::DATE_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1496 'wednesday' => Horde_Date::DATE_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1497 'thursday' => Horde_Date::DATE_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1498 'friday' => Horde_Date::DATE_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1499 'saturday' => Horde_Date::DATE_SATURDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1500 'sunday' => Horde_Date::DATE_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1501 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1502
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1503 foreach ($hash['day'] as $day) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1504 // Validity check.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1505 if (empty($day) || !isset($bits[$day])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1506 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1507 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1508
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1509 $mask |= $bits[$day];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1510 $last_found_day = $days[$day];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1511 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1512
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1513 if ($set_daymask) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1514 $this->setRecurOnDay($mask);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1516 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1517
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1518 if ($update_month || $update_daynumber || $update_weekday) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1519 if ($update_month) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1520 if (isset($month2number[$hash['month']])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1521 $this->start->month = $month2number[$hash['month']];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1522 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1523 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1524
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1525 if ($update_daynumber) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1526 if (!isset($hash['daynumber'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1527 $this->setRecurType(self::RECUR_NONE);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1528 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1529 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1530
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1531 $this->start->mday = $hash['daynumber'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1532 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1533
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1534 if ($update_weekday) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1535 $this->setNthWeekday($nth_weekday);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1536 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1537 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1538
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1539 // Exceptions.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1540 if (isset($hash['exceptions'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1541 $this->exceptions = $hash['exceptions'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1542 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1543
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1544 if (isset($hash['completions'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1545 $this->completions = $hash['completions'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1546 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1547
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1548 return true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1549 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1550
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1551 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1552 * Export this object into a hash.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1553 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1554 * @return array The recurrence hash.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1555 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1556 public function toHash()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1557 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1558 if ($this->getRecurType() == self::RECUR_NONE) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1559 return array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1560 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1561
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1562 $day2number = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1563 0 => 'sunday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1564 1 => 'monday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1565 2 => 'tuesday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1566 3 => 'wednesday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1567 4 => 'thursday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1568 5 => 'friday',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1569 6 => 'saturday'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1570 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1571 $month2number = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1572 1 => 'january',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1573 2 => 'february',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1574 3 => 'march',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1575 4 => 'april',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1576 5 => 'may',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1577 6 => 'june',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1578 7 => 'july',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1579 8 => 'august',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1580 9 => 'september',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1581 10 => 'october',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1582 11 => 'november',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1583 12 => 'december'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1584 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1585
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1586 $hash = array('interval' => $this->getRecurInterval());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1587 $start = $this->getRecurStart();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1588
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1589 switch ($this->getRecurType()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1590 case self::RECUR_DAILY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1591 $hash['cycle'] = 'daily';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1592 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1593
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1594 case self::RECUR_WEEKLY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1595 $hash['cycle'] = 'weekly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1596 $bits = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1597 'monday' => Horde_Date::MASK_MONDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1598 'tuesday' => Horde_Date::MASK_TUESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1599 'wednesday' => Horde_Date::MASK_WEDNESDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1600 'thursday' => Horde_Date::MASK_THURSDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1601 'friday' => Horde_Date::MASK_FRIDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1602 'saturday' => Horde_Date::MASK_SATURDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1603 'sunday' => Horde_Date::MASK_SUNDAY,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1604 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1605 $days = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1606 foreach ($bits as $name => $bit) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1607 if ($this->recurOnDay($bit)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1608 $days[] = $name;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1609 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1610 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1611 $hash['day'] = $days;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1612 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1613
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1614 case self::RECUR_MONTHLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1615 $hash['cycle'] = 'monthly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1616 $hash['type'] = 'daynumber';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1617 $hash['daynumber'] = $start->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1618 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1619
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1620 case self::RECUR_MONTHLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1621 $hash['cycle'] = 'monthly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1622 $hash['type'] = 'weekday';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1623 $hash['daynumber'] = $start->weekOfMonth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1624 $hash['day'] = array ($day2number[$start->dayOfWeek()]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1625 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1626
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1627 case self::RECUR_YEARLY_DATE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1628 $hash['cycle'] = 'yearly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1629 $hash['type'] = 'monthday';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1630 $hash['daynumber'] = $start->mday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1631 $hash['month'] = $month2number[$start->month];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1632 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1633
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1634 case self::RECUR_YEARLY_DAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1635 $hash['cycle'] = 'yearly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1636 $hash['type'] = 'yearday';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1637 $hash['daynumber'] = $start->dayOfYear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1638 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1639
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1640 case self::RECUR_YEARLY_WEEKDAY:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1641 $hash['cycle'] = 'yearly';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1642 $hash['type'] = 'weekday';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1643 $hash['daynumber'] = $start->weekOfMonth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1644 $hash['day'] = array ($day2number[$start->dayOfWeek()]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1645 $hash['month'] = $month2number[$start->month];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1646 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1647
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1648 if ($this->hasRecurCount()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1649 $hash['range-type'] = 'number';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1650 $hash['range'] = $this->getRecurCount();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1651 } elseif ($this->hasRecurEnd()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1652 $date = $this->getRecurEnd();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1653 $hash['range-type'] = 'date';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1654 $hash['range'] = $date->datestamp();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1655 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1656 $hash['range-type'] = 'none';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1657 $hash['range'] = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1658 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1659
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1660 // Recurrence exceptions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1661 $hash['exceptions'] = $this->exceptions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1662 $hash['completions'] = $this->completions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1663
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1664 return $hash;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1665 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1666
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1667 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1668 * Returns a simple object suitable for json transport representing this
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1669 * object.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1670 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1671 * Possible properties are:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1672 * - t: type
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1673 * - i: interval
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1674 * - e: end date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1675 * - c: count
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1676 * - d: data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1677 * - co: completions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1678 * - ex: exceptions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1679 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1680 * @return object A simple object.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1681 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1682 public function toJson()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1683 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1684 $json = new stdClass;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1685 $json->t = $this->recurType;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1686 $json->i = $this->recurInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1687 if ($this->hasRecurEnd()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1688 $json->e = $this->recurEnd->toJson();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1689 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1690 if ($this->recurCount) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1691 $json->c = $this->recurCount;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1692 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1693 if ($this->recurData) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1694 $json->d = $this->recurData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1695 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1696 if ($this->completions) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1697 $json->co = $this->completions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1698 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1699 if ($this->exceptions) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1700 $json->ex = $this->exceptions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1701 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1702 return $json;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1703 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1705 }