6 * This component contains some additional functionality specific for VALARMs.
10 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11 * @author Evert Pot (http://www.rooftopsolutions.nl/)
12 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14 class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
17 * Returns a DateTime object when this alarm is going to trigger.
19 * This ignores repeated alarm, only the first trigger is returned.
23 public function getEffectiveTriggerTime() {
25 $trigger = $this->TRIGGER;
26 if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
27 $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($this->TRIGGER);
28 $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
30 $parentComponent = $this->parent;
31 if ($related === 'START') {
32 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
33 $effectiveTrigger->add($triggerDuration);
35 if ($parentComponent->name === 'VTODO') {
37 } elseif ($parentComponent->name === 'VEVENT') {
40 throw new Sabre_DAV_Exception('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
43 if (isset($parentComponent->$endProp)) {
44 $effectiveTrigger = clone $parentComponent->$endProp->getDateTime();
45 $effectiveTrigger->add($triggerDuration);
46 } elseif (isset($parentComponent->DURATION)) {
47 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
48 $duration = Sabre_VObject_DateTimeParser::parseDuration($parentComponent->DURATION);
49 $effectiveTrigger->add($duration);
50 $effectiveTrigger->add($triggerDuration);
52 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
53 $effectiveTrigger->add($triggerDuration);
57 $effectiveTrigger = $trigger->getDateTime();
59 return $effectiveTrigger;
64 * Returns true or false depending on if the event falls in the specified
65 * time-range. This is used for filtering purposes.
67 * The rules used to determine if an event falls within the specified
68 * time-range is based on the CalDAV specification.
70 * @param DateTime $start
71 * @param DateTime $end
74 public function isInTimeRange(DateTime $start, DateTime $end) {
76 $effectiveTrigger = $this->getEffectiveTriggerTime();
78 if (isset($this->DURATION)) {
79 $duration = Sabre_VObject_DateTimeParser::parseDuration($this->DURATION);
80 $repeat = (string)$this->repeat;
85 $period = new DatePeriod($effectiveTrigger, $duration, (int)$repeat);
87 foreach($period as $occurrence) {
89 if ($start <= $occurrence && $end > $occurrence) {
95 return ($start <= $effectiveTrigger && $end > $effectiveTrigger);