annotate plugins/libcalendaring/lib/Sabre/VObject/Component/VAlarm.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 888e774ee983
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 * VAlarm component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * This component contains some additional functionality specific for VALARMs.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 class VAlarm extends VObject\Component {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * Returns a DateTime object when this alarm is going to trigger.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * This ignores repeated alarm, only the first trigger is returned.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * @return DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 public function getEffectiveTriggerTime() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 $trigger = $this->TRIGGER;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 $parentComponent = $this->parent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 if ($related === 'START') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 if ($parentComponent->name === 'VTODO') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 $propName = 'DUE';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 $propName = 'DTSTART';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 $effectiveTrigger = clone $parentComponent->$propName->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 $effectiveTrigger->add($triggerDuration);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 if ($parentComponent->name === 'VTODO') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 $endProp = 'DUE';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 } elseif ($parentComponent->name === 'VEVENT') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 $endProp = 'DTEND';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 if (isset($parentComponent->$endProp)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 $effectiveTrigger = clone $parentComponent->$endProp->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 $effectiveTrigger->add($triggerDuration);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 } elseif (isset($parentComponent->DURATION)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 $effectiveTrigger->add($duration);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 $effectiveTrigger->add($triggerDuration);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 $effectiveTrigger->add($triggerDuration);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 $effectiveTrigger = $trigger->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 return $effectiveTrigger;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 * Returns true or false depending on if the event falls in the specified
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 * time-range. This is used for filtering purposes.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 * The rules used to determine if an event falls within the specified
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 * time-range is based on the CalDAV specification.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 * @param \DateTime $start
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 * @param \DateTime $end
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 public function isInTimeRange(\DateTime $start, \DateTime $end) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 $effectiveTrigger = $this->getEffectiveTriggerTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 if (isset($this->DURATION)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 $duration = VObject\DateTimeParser::parseDuration($this->DURATION);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 $repeat = (string)$this->repeat;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 if (!$repeat) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 $repeat = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 $period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 foreach($period as $occurrence) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 if ($start <= $occurrence && $end > $occurrence) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 return ($start <= $effectiveTrigger && $end > $effectiveTrigger);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 }