|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace HDNET\Calendarize\Ical; |
|
6
|
|
|
|
|
7
|
|
|
use HDNET\Calendarize\Domain\Model\ConfigurationInterface; |
|
8
|
|
|
use HDNET\Calendarize\Utility\DateTimeUtility; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class DissectEvent |
|
12
|
|
|
*/ |
|
13
|
|
|
class DissectEventAdapter implements ICalEvent |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var \JMBTechnologyLimited\ICalDissect\ICalEvent |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $event; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* DissectEvent constructor. |
|
23
|
|
|
* @param \JMBTechnologyLimited\ICalDissect\ICalEvent $event |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(\JMBTechnologyLimited\ICalDissect\ICalEvent $event) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->event = $event; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getRawData(): array |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->event->getRaw(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return \JMBTechnologyLimited\ICalDissect\ICalEvent |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getEvent(): \JMBTechnologyLimited\ICalDissect\ICalEvent |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->event; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @inheritDoc |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getUid(): string |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->event->getUid(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritDoc |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getTitle(): ?string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->event->getSummary(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritDoc |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getDescription(): ?string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->event->getDescription(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritDoc |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getLocation(): ?string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->event->getLocation(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritDoc |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getOrganizer(): ?string |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getEvent()->getRaw('ORGANIZER')[0] ?? null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritDoc |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getStartDate(): ?\DateTime |
|
90
|
|
|
{ |
|
91
|
|
|
if (empty($this->event->getStart())) { |
|
92
|
|
|
return null; |
|
93
|
|
|
} |
|
94
|
|
|
return DateTimeUtility::getDayStart($this->event->getStart()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritDoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getStartTime(): int |
|
101
|
|
|
{ |
|
102
|
|
|
if ($this->isAllDay() || empty($this->event->getStart())) { |
|
103
|
|
|
return self::ALLDAY_START_TIME; |
|
104
|
|
|
} |
|
105
|
|
|
return DateTimeUtility::getDaySecondsOfDateTime($this->event->getStart()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritDoc |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getEndDate(): ?\DateTime |
|
112
|
|
|
{ |
|
113
|
|
|
$endDate = $this->event->getEnd(); |
|
114
|
|
|
if (empty($endDate)) { |
|
115
|
|
|
return null; |
|
116
|
|
|
} |
|
117
|
|
|
if ($this->isAllDay()) { |
|
118
|
|
|
// Converts the exclusive enddate to inclusive |
|
119
|
|
|
$endDate = (clone $endDate)->sub(new \DateInterval('P1D')); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return DateTimeUtility::getDayStart($endDate); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @inheritDoc |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getEndTime(): int |
|
129
|
|
|
{ |
|
130
|
|
|
if ($this->isAllDay() || empty($this->event->getEnd())) { |
|
131
|
|
|
return self::ALLDAY_END_TIME; |
|
132
|
|
|
} |
|
133
|
|
|
return DateTimeUtility::getDaySecondsOfDateTime($this->event->getEnd()); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @inheritDoc |
|
138
|
|
|
*/ |
|
139
|
|
|
public function isAllDay(): bool |
|
140
|
|
|
{ |
|
141
|
|
|
// The ICalDissect\ICalEvent does not provide information, |
|
142
|
|
|
// if DTSTART is a DATE or DATE-TIME |
|
143
|
|
|
// If no time was given, the class sets following values |
|
144
|
|
|
// starTime to 00:00:00 = 0 |
|
145
|
|
|
// endTime to 23:59:59 = (24h*60m*60s - 1) = 86399 |
|
146
|
|
|
// So we check for these values. |
|
147
|
|
|
// Note: By spec (RFC) DTEND is irrelevant for allday events, |
|
148
|
|
|
// so this may produce invalid results. |
|
149
|
|
|
$start = true; |
|
150
|
|
|
$end = true; |
|
151
|
|
|
if (!empty($this->event->getStart())) { |
|
152
|
|
|
$start = DateTimeUtility::getDaySecondsOfDateTime($this->event->getStart()) === 0; |
|
153
|
|
|
} |
|
154
|
|
|
if (!empty($this->event->getEnd())) { |
|
155
|
|
|
$end = DateTimeUtility::getDaySecondsOfDateTime($this->event->getEnd()) === 86399; |
|
156
|
|
|
} |
|
157
|
|
|
return $start && $end; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @inheritDoc |
|
162
|
|
|
*/ |
|
163
|
|
|
public function isOpenEndTime(): bool |
|
164
|
|
|
{ |
|
165
|
|
|
return false; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @inheritDoc |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getState(): string |
|
172
|
|
|
{ |
|
173
|
|
|
if ($this->event->isDeleted()) { |
|
174
|
|
|
return ConfigurationInterface::STATE_CANCELED; |
|
175
|
|
|
} |
|
176
|
|
|
return ConfigurationInterface::STATE_DEFAULT; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|