/
Task.php
386 lines (355 loc) · 14.8 KB
/
Task.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
/**
* Horde_ActiveSync_Message_Task::
*
* Portions of this class were ported from the Z-Push project:
* File : wbxml.php
* Project : Z-Push
* Descr : WBXML mapping file
*
* Created : 01.10.2007
*
* � Zarafa Deutschland GmbH, www.zarafaserver.de
* This file is distributed under GPL-2.0.
* Consult COPYING file for details
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2010-2014 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*/
/**
* Horde_ActiveSync_Message_Task::
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2010-2014 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*
* @property boolean complete Completion flag
* @property Horde_Date datecompleted The date the task was completed, in UTC.
* @property Horde_Date utcduedate The date this task is due, in UTC.
* @property integer importance The importance flag.
* @property Horde_ActiveSync_Message_TaskRecurrence recurrence
* The recurrence object.
* @property integer sensitivity The sensitivity flag.
* @property Horde_Date utcstartdate The date this task starts, in UTC.
* @property string subject The task subject.
* @property array categories An array of categories.
* @property string body The task body (EAS Version < 12.0)
* @property boolean bodytruncated Truncation flag (EAS Version < 12.0)
* @property Horde_ActiveSync_Message_AirSyncBaseBody airsyncbasebody
* The task body (EAS Version >= 12.0)
*/
class Horde_ActiveSync_Message_Task extends Horde_ActiveSync_Message_Base
{
/* POOMTASKS */
const POOMTASKS_BODY = 'POOMTASKS:Body';
const POOMTASKS_BODYSIZE = 'POOMTASKS:BodySize';
const POOMTASKS_BODYTRUNCATED = 'POOMTASKS:BodyTruncated';
const POOMTASKS_CATEGORIES = 'POOMTASKS:Categories';
const POOMTASKS_CATEGORY = 'POOMTASKS:Category';
const POOMTASKS_COMPLETE = 'POOMTASKS:Complete';
const POOMTASKS_DATECOMPLETED = 'POOMTASKS:DateCompleted';
const POOMTASKS_DUEDATE = 'POOMTASKS:DueDate';
const POOMTASKS_UTCDUEDATE = 'POOMTASKS:UtcDueDate';
const POOMTASKS_IMPORTANCE = 'POOMTASKS:Importance';
const POOMTASKS_RECURRENCE = 'POOMTASKS:Recurrence';
const POOMTASKS_TYPE = 'POOMTASKS:Type';
const POOMTASKS_START = 'POOMTASKS:Start';
const POOMTASKS_UNTIL = 'POOMTASKS:Until';
const POOMTASKS_OCCURRENCES = 'POOMTASKS:Occurrences';
const POOMTASKS_INTERVAL = 'POOMTASKS:Interval';
const POOMTASKS_DAYOFWEEK = 'POOMTASKS:DayOfWeek';
const POOMTASKS_DAYOFMONTH = 'POOMTASKS:DayOfMonth';
const POOMTASKS_WEEKOFMONTH = 'POOMTASKS:WeekOfMonth';
const POOMTASKS_MONTHOFYEAR = 'POOMTASKS:MonthOfYear';
const POOMTASKS_REGENERATE = 'POOMTASKS:Regenerate';
const POOMTASKS_DEADOCCUR = 'POOMTASKS:DeadOccur';
const POOMTASKS_REMINDERSET = 'POOMTASKS:ReminderSet';
const POOMTASKS_REMINDERTIME = 'POOMTASKS:ReminderTime';
const POOMTASKS_SENSITIVITY = 'POOMTASKS:Sensitivity';
const POOMTASKS_STARTDATE = 'POOMTASKS:StartDate';
const POOMTASKS_UTCSTARTDATE = 'POOMTASKS:UtcStartDate';
const POOMTASKS_SUBJECT = 'POOMTASKS:Subject';
const POOMTASKS_RTF = 'POOMTASKS:Rtf';
// EAS 12.0
const POOMTASKS_ORDINALDATE = 'POOMTASKS:OrdinalDate';
const POOMTASKS_SUBORDINALDATE = 'POOMTASKS:SubOrdinalDate';
// EAS 14
const POOMTASKS_CALENDARTYPE = 'POOMTASKS:CalendarType';
const POOMTASKS_ISLEAPMONTH = 'POOMTASKS:IsLeapMonth';
const TASK_COMPLETE_TRUE = 1;
const TASK_COMPLETE_FALSE = 0;
const IMPORTANCE_LOW = 0;
const IMPORTANCE_NORMAL = 1;
const IMPORTANCE_HIGH = 2;
const REMINDER_SET_FALSE = 0;
const REMINDER_SET_TRUE = 1;
/**
* DOW mapping for DATE to MASK
*
* @var array
*/
protected $_dayOfWeekMap = array(
Horde_Date::DATE_SUNDAY => Horde_Date::MASK_SUNDAY,
Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY,
Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY,
Horde_Date::DATE_WEDNESDAY => Horde_Date::MASK_WEDNESDAY,
Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY,
Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY,
Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY,
);
/**
* Property mapping
*
* @var array
*/
protected $_mapping = array (
self::POOMTASKS_COMPLETE => array (self::KEY_ATTRIBUTE => 'complete'),
self::POOMTASKS_DATECOMPLETED => array (self::KEY_ATTRIBUTE => 'datecompleted', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_DUEDATE => array (self::KEY_ATTRIBUTE => 'duedate', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_UTCDUEDATE => array (self::KEY_ATTRIBUTE => 'utcduedate', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_IMPORTANCE => array (self::KEY_ATTRIBUTE => 'importance'),
self::POOMTASKS_RECURRENCE => array (self::KEY_ATTRIBUTE => 'recurrence', self::KEY_TYPE => 'Horde_ActiveSync_Message_TaskRecurrence'),
self::POOMTASKS_REGENERATE => array (self::KEY_ATTRIBUTE => 'regenerate'),
self::POOMTASKS_DEADOCCUR => array (self::KEY_ATTRIBUTE => 'deadoccur'),
self::POOMTASKS_REMINDERSET => array (self::KEY_ATTRIBUTE => 'reminderset'),
self::POOMTASKS_REMINDERTIME => array (self::KEY_ATTRIBUTE => 'remindertime', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_SENSITIVITY => array (self::KEY_ATTRIBUTE => 'sensitiviy'),
self::POOMTASKS_STARTDATE => array (self::KEY_ATTRIBUTE => 'startdate', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_UTCSTARTDATE => array (self::KEY_ATTRIBUTE => 'utcstartdate', self::KEY_TYPE => self::TYPE_DATE_DASHES),
self::POOMTASKS_SUBJECT => array (self::KEY_ATTRIBUTE => 'subject'),
self::POOMTASKS_CATEGORIES => array (self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMTASKS_CATEGORY),
);
/**
* Property values.
*
* @var array
*/
protected $_properties = array(
'subject' => false,
'importance' => false,
'categories' => array(),
'startdate' => false,
'duedate' => false,
'utcduedate' => false,
'complete' => false,
'datecompleted' => false,
'remindertime' => false,
'sensitiviy' => false,
'reminderset' => false,
'deadoccur' => false,
'recurrence' => false,
'regenerate' => false,
'sensitiviy' => false,
'utcstartdate' => false,
);
/**
* Const'r
*
* @see Horde_ActiveSync_Message_Base::__construct()
*/
public function __construct(array $options = array())
{
parent::__construct($options);
if ($this->_version < Horde_ActiveSync::VERSION_TWELVE) {
$this->_mapping += array(
self::POOMTASKS_BODY => array(self::KEY_ATTRIBUTE => 'body'),
self::POOMTASKS_RTF => array(self::KEY_ATTRIBUTE => 'rtf'),
self::POOMTASKS_BODYTRUNCATED => array(self::KEY_ATTRIBUTE => 'bodytruncated')
);
$this->_properties += array(
'body' => false,
'rtf' => false,
'bodytruncated' => 0,
);
} else {
$this->_mapping += array(
Horde_ActiveSync::AIRSYNCBASE_BODY => array(self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE=> 'Horde_ActiveSync_Message_AirSyncBaseBody'),
);
$this->_properties += array(
'airsyncbasebody' => false,
);
if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE) {
$this->_mapping += array(
self::POOMTASKS_CALENDARTYPE => array(self::KEY_ATTRIBUTE => 'calendartype'),
self::POOMTASKS_ISLEAPMONTH => array(self::KEY_ATTRIBUTE => 'isleapmonth')
);
$this->_properties += array(
'calendartype' => false,
'isleapmonth' => false
);
}
}
}
/**
* Set the importance
*
* @param integer $importance A IMPORTANCE_* flag
*/
public function setImportance($importance)
{
if (is_null($importance)) {
$importance = self::IMPORTANCE_NORMAL;
}
$this->_properties['importance'] = $importance;
}
/**
* Get the task importance level
*
* @return integer A IMPORTANCE_* constant
*/
public function getImportance()
{
return $this->_getAttribute('importance', self::IMPORTANCE_NORMAL);
}
/**
* Set the reminder datetime
*
* @param Horde_Date $datetime The time to trigger the alarm in local tz.
*/
public function setReminder(Horde_Date $datetime)
{
$this->_properties['remindertime'] = $datetime;
$this->_properties['reminderset'] = self::REMINDER_SET_TRUE;
}
/**
* Get the reminder time.
*
* @return Horde_Date in local tz
*/
public function getReminder()
{
if (!$this->_getAttribute('reminderset')) {
return false;
}
return $this->_getAttribute('remindertime');
}
/**
* Set recurrence information for this task
*
* @param Horde_Date_Recurrence $recurrence
*/
public function setRecurrence(Horde_Date_Recurrence $recurrence)
{
$r = Horde_ActiveSync::messageFactory('TaskRecurrence');
// Map the type fields
switch ($recurrence->recurType) {
case Horde_Date_Recurrence::RECUR_DAILY:
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY;
break;
case Horde_Date_Recurrence::RECUR_WEEKLY:
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY;
$r->dayofweek = $recurrence->getRecurOnDays();
break;
case Horde_Date_Recurrence::RECUR_MONTHLY_DATE:
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY;
break;
case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY;
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH;
$r->weekofmonth = ceil($recurrence->start->mday / 7);
$r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()];
break;
case Horde_Date_Recurrence::RECUR_YEARLY_DATE:
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY;
break;
case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY:
$r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH;
$r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()];
$r->weekofmonth = ceil($recurrence->start->mday / 7);
$r->monthofyear = $recurrence->start->month;
break;
}
if (!empty($recurrence->recurInterval)) {
$r->interval = $recurrence->recurInterval;
}
// AS messages can only have one or the other (or none), not both
if ($recurrence->hasRecurCount()) {
$r->occurrences = $recurrence->getRecurCount();
} elseif ($recurrence->hasRecurEnd()) {
$r->until = $recurrence->getRecurEnd();
}
$this->_properties['recurrence'] = $r;
}
/**
* Obtain a recurrence object. Note this returns a Horde_Date_Recurrence
* object, not Horde_ActiveSync_Message_Recurrence.
*
* @return Horde_Date_Recurrence
*/
public function getRecurrence()
{
if (!$recurrence = $this->_getAttribute('recurrence')) {
return false;
}
$d = clone($this->getDueDate());
// $d->setTimezone($this->getTimezone());
$rrule = new Horde_Date_Recurrence($d);
/* Map MS AS type field to Horde_Date_Recurrence types */
switch ($recurrence->type) {
case Horde_ActiveSync_Message_Recurrence::TYPE_DAILY:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_DAILY);
break;
case Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY);
$rrule->setRecurOnDay($recurrence->dayofweek);
break;
case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_DATE);
break;
case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY);
$rrule->setRecurOnDay($recurrence->dayofweek);
break;
case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_DATE);
break;
case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH:
$rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY);
$rrule->setRecurOnDay($recurrence->dayofweek);
break;
}
if ($rcnt = $recurrence->occurrences) {
$rrule->setRecurCount($rcnt);
}
if ($runtil = $recurrence->until) {
$rrule->setRecurEnd(new Horde_Date($runtil));
}
if ($interval = $recurrence->interval) {
$rrule->setRecurInterval($interval);
}
return $rrule;
}
/**
* Return this object's folder class
*
* @return string
*/
public function getClass()
{
return 'Tasks';
}
/**
* Check if a field should be sent to the device even if it is empty.
*
* @param string $tag The field tag.
*
* @return boolean
*/
protected function _checkSendEmpty($tag)
{
if ($tag == self::POOMTASKS_BODYTRUNCATED && $this->bodysize > 0) {
return true;
}
return false;
}
}