ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VAlarm.php
Go to the documentation of this file.
1<?php
2
4
5use DateTimeImmutable;
6use DateTimeInterface;
9
20
29
30 $trigger = $this->TRIGGER;
31 if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
32 $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
33 $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
34
35 $parentComponent = $this->parent;
36 if ($related === 'START') {
37
38 if ($parentComponent->name === 'VTODO') {
39 $propName = 'DUE';
40 } else {
41 $propName = 'DTSTART';
42 }
43
44 $effectiveTrigger = $parentComponent->$propName->getDateTime();
45 $effectiveTrigger = $effectiveTrigger->add($triggerDuration);
46 } else {
47 if ($parentComponent->name === 'VTODO') {
48 $endProp = 'DUE';
49 } elseif ($parentComponent->name === 'VEVENT') {
50 $endProp = 'DTEND';
51 } else {
52 throw new InvalidDataException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
53 }
54
55 if (isset($parentComponent->$endProp)) {
56 $effectiveTrigger = $parentComponent->$endProp->getDateTime();
57 $effectiveTrigger = $effectiveTrigger->add($triggerDuration);
58 } elseif (isset($parentComponent->DURATION)) {
59 $effectiveTrigger = $parentComponent->DTSTART->getDateTime();
60 $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
61 $effectiveTrigger = $effectiveTrigger->add($duration);
62 $effectiveTrigger = $effectiveTrigger->add($triggerDuration);
63 } else {
64 $effectiveTrigger = $parentComponent->DTSTART->getDateTime();
65 $effectiveTrigger = $effectiveTrigger->add($triggerDuration);
66 }
67 }
68 } else {
69 $effectiveTrigger = $trigger->getDateTime();
70 }
71 return $effectiveTrigger;
72
73 }
74
87 function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) {
88
89 $effectiveTrigger = $this->getEffectiveTriggerTime();
90
91 if (isset($this->DURATION)) {
92 $duration = VObject\DateTimeParser::parseDuration($this->DURATION);
93 $repeat = (string)$this->REPEAT;
94 if (!$repeat) {
95 $repeat = 1;
96 }
97
98 $period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat);
99
100 foreach ($period as $occurrence) {
101
102 if ($start <= $occurrence && $end > $occurrence) {
103 return true;
104 }
105 }
106 return false;
107 } else {
108 return ($start <= $effectiveTrigger && $end > $effectiveTrigger);
109 }
110
111 }
112
129
130 return [
131 'ACTION' => 1,
132 'TRIGGER' => 1,
133
134 'DURATION' => '?',
135 'REPEAT' => '?',
136
137 'ATTACH' => '?',
138 ];
139
140 }
141
142}
An exception for terminatinating execution or to throw for unit testing.
VAlarm component.
Definition: VAlarm.php:19
getEffectiveTriggerTime()
Returns a DateTime object when this alarm is going to trigger.
Definition: VAlarm.php:28
isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
Returns true or false depending on if the event falls in the specified time-range.
Definition: VAlarm.php:87
static parseDuration($duration, $asString=false)
Parses an iCalendar (RFC5545) formatted duration value.
This exception is thrown whenever an invalid value is found anywhere in a iCalendar or vCard object.
$start
Definition: bench.php:8