1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Shapin\Calendar\Model; |
6
|
|
|
|
7
|
|
|
class Event |
8
|
|
|
{ |
9
|
|
|
private $startAt; |
10
|
|
|
private $endAt; |
11
|
|
|
private $summary; |
12
|
|
|
private $description; |
13
|
|
|
private $recurrenceRule; |
14
|
|
|
private $recurrenceId; |
15
|
|
|
|
16
|
3 |
|
public function __construct(\DateTimeImmutable $startAt, \DateTimeImmutable $endAt) |
17
|
|
|
{ |
18
|
3 |
|
$this->startAt = $startAt; |
19
|
3 |
|
$this->endAt = $endAt; |
20
|
3 |
|
} |
21
|
|
|
|
22
|
3 |
|
public function isRecurring(): bool |
23
|
|
|
{ |
24
|
3 |
|
return null !== $this->recurrenceRule; |
25
|
|
|
} |
26
|
|
|
|
27
|
3 |
|
public function isARecurrence(): bool |
28
|
|
|
{ |
29
|
3 |
|
return null !== $this->recurrenceId; |
30
|
|
|
} |
31
|
|
|
|
32
|
3 |
|
public function getLastEventStartAt(): \DateTimeImmutable |
33
|
|
|
{ |
34
|
3 |
|
if (!$this->isRecurring()) { |
35
|
|
|
throw new \BadMethodCallException('Not a recurring event'); |
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
return $this->getRecurrenceRule()->getLastEvent($this->getStartAt()); |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
public function getStartAt(): ?\DateTimeImmutable |
42
|
|
|
{ |
43
|
3 |
|
return $this->startAt; |
44
|
|
|
} |
45
|
|
|
|
46
|
3 |
|
public function getEndAt(): ?\DateTimeImmutable |
47
|
|
|
{ |
48
|
3 |
|
return $this->endAt; |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
public function getSummary(): ?string |
52
|
|
|
{ |
53
|
3 |
|
return $this->summary; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function setSummary(string $summary): self |
57
|
|
|
{ |
58
|
3 |
|
$this->summary = $summary; |
59
|
|
|
|
60
|
3 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
public function getDescription(): ?string |
64
|
|
|
{ |
65
|
3 |
|
return $this->description; |
66
|
|
|
} |
67
|
|
|
|
68
|
3 |
|
public function setDescription(string $description): self |
69
|
|
|
{ |
70
|
3 |
|
$this->description = $description; |
71
|
|
|
|
72
|
3 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
3 |
|
public function getRecurrenceRule(): ?RecurrenceRule |
76
|
|
|
{ |
77
|
3 |
|
return $this->recurrenceRule; |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
public function setRecurrenceRule(RecurrenceRule $recurrenceRule): self |
81
|
|
|
{ |
82
|
3 |
|
$this->recurrenceRule = $recurrenceRule; |
83
|
|
|
|
84
|
3 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
public function getRecurrenceId(): ?\DateTimeImmutable |
88
|
|
|
{ |
89
|
2 |
|
return $this->recurrenceId; |
90
|
|
|
} |
91
|
|
|
|
92
|
2 |
|
public function setRecurrenceId(\DateTimeImmutable $recurrenceId): self |
93
|
|
|
{ |
94
|
2 |
|
$this->recurrenceId = $recurrenceId; |
95
|
|
|
|
96
|
2 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|