3 namespace Sabre\VObject\Component;
9 * This component contains some additional functionality specific for VALARMs.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class VAlarm extends VObject\Component {
18 * Returns a DateTime object when this alarm is going to trigger.
20 * This ignores repeated alarm, only the first trigger is returned.
24 public function getEffectiveTriggerTime() {
26 $trigger = $this->TRIGGER;
27 if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
28 $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
29 $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
31 $parentComponent = $this->parent;
32 if ($related === 'START') {
33 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
34 $effectiveTrigger->add($triggerDuration);
36 if ($parentComponent->name === 'VTODO') {
38 } elseif ($parentComponent->name === 'VEVENT') {
41 throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
44 if (isset($parentComponent->$endProp)) {
45 $effectiveTrigger = clone $parentComponent->$endProp->getDateTime();
46 $effectiveTrigger->add($triggerDuration);
47 } elseif (isset($parentComponent->DURATION)) {
48 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
49 $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
50 $effectiveTrigger->add($duration);
51 $effectiveTrigger->add($triggerDuration);
53 $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
54 $effectiveTrigger->add($triggerDuration);
58 $effectiveTrigger = $trigger->getDateTime();
60 return $effectiveTrigger;
65 * Returns true or false depending on if the event falls in the specified
66 * time-range. This is used for filtering purposes.
68 * The rules used to determine if an event falls within the specified
69 * time-range is based on the CalDAV specification.
71 * @param \DateTime $start
72 * @param \DateTime $end
75 public function isInTimeRange(\DateTime $start, \DateTime $end) {
77 $effectiveTrigger = $this->getEffectiveTriggerTime();
79 if (isset($this->DURATION)) {
80 $duration = VObject\DateTimeParser::parseDuration($this->DURATION);
81 $repeat = (string)$this->repeat;
86 $period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat);
88 foreach($period as $occurrence) {
90 if ($start <= $occurrence && $end > $occurrence) {
96 return ($start <= $effectiveTrigger && $end > $effectiveTrigger);