1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\SetlistFm\Model; |
13
|
|
|
|
14
|
|
|
use DateTime; |
15
|
|
|
|
16
|
|
|
final class Setlist |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Artist|null |
25
|
|
|
*/ |
26
|
|
|
private $artist; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Venue|null |
30
|
|
|
*/ |
31
|
|
|
private $venue; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Tour|null |
35
|
|
|
*/ |
36
|
|
|
private $tour; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Set[] |
40
|
|
|
*/ |
41
|
|
|
private $sets; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string|null |
45
|
|
|
*/ |
46
|
|
|
private $info; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string|null |
50
|
|
|
*/ |
51
|
|
|
private $url; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string|null |
55
|
|
|
*/ |
56
|
|
|
private $versionId; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var DateTime |
60
|
|
|
*/ |
61
|
|
|
private $eventDate; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var DateTime|null |
65
|
|
|
*/ |
66
|
|
|
private $updateDate; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Set[] $sets |
70
|
|
|
*/ |
71
|
|
|
public function __construct( |
72
|
|
|
string $id, |
73
|
|
|
?Artist $artist, |
74
|
|
|
?Venue $venue, |
75
|
|
|
?Tour $tour, |
76
|
|
|
array $sets, |
77
|
|
|
?string $info, |
78
|
|
|
?string $url, |
79
|
|
|
?string $versionId, |
80
|
|
|
DateTime $eventDate, |
81
|
|
|
?DateTime $updateDate |
82
|
|
|
) { |
83
|
|
|
$this->id = $id; |
84
|
|
|
$this->artist = $artist; |
85
|
|
|
$this->venue = $venue; |
86
|
|
|
$this->tour = $tour; |
87
|
|
|
$this->sets = $sets; |
88
|
|
|
$this->info = $info; |
89
|
|
|
$this->url = $url; |
90
|
|
|
$this->versionId = $versionId; |
91
|
|
|
$this->eventDate = $eventDate; |
92
|
|
|
$this->updateDate = $updateDate; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getId(): string |
96
|
|
|
{ |
97
|
|
|
return $this->id; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getArtist(): ?Artist |
101
|
|
|
{ |
102
|
|
|
return $this->artist; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getVenue(): ?Venue |
106
|
|
|
{ |
107
|
|
|
return $this->venue; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getTour(): ?Tour |
111
|
|
|
{ |
112
|
|
|
return $this->tour; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return Set[] |
117
|
|
|
*/ |
118
|
|
|
public function getSets(): array |
119
|
|
|
{ |
120
|
|
|
return $this->sets; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getInfo(): ?string |
124
|
|
|
{ |
125
|
|
|
return $this->info; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getUrl(): ?string |
129
|
|
|
{ |
130
|
|
|
return $this->url; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getVersionId(): ?string |
134
|
|
|
{ |
135
|
|
|
return $this->versionId; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getEventDate(): DateTime |
139
|
|
|
{ |
140
|
|
|
return $this->eventDate; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getUpdateDate(): ?DateTime |
144
|
|
|
{ |
145
|
|
|
return $this->updateDate; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return Setlist |
150
|
|
|
*/ |
151
|
|
|
public static function fromApi(array $data): self |
152
|
|
|
{ |
153
|
|
|
$artist = null; |
154
|
|
|
$venue = null; |
155
|
|
|
$tour = null; |
156
|
|
|
|
157
|
|
|
if (\array_key_exists('artist', $data)) { |
158
|
|
|
$artist = Artist::fromApi($data['artist']); |
159
|
|
|
} |
160
|
|
|
if (\array_key_exists('venue', $data)) { |
161
|
|
|
$venue = Venue::fromApi($data['venue']); |
162
|
|
|
} |
163
|
|
|
if (\array_key_exists('tour', $data)) { |
164
|
|
|
$tour = Tour::fromApi($data['tour']); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$sets = self::createSetsFromApi($data); |
168
|
|
|
|
169
|
|
|
return new self( |
170
|
|
|
$data['id'], |
171
|
|
|
$artist, |
172
|
|
|
$venue, |
173
|
|
|
$tour, |
174
|
|
|
$sets, |
175
|
|
|
$data['info'] ?? null, |
176
|
|
|
$data['url'] ?? null, |
177
|
|
|
$data['versionId'] ?? null, |
178
|
|
|
new DateTime($data['eventDate']), |
179
|
|
|
$data['lastUpdated'] ? new DateTime($data['lastUpdated']) : null |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
private static function createSetsFromApi(array $data): array |
184
|
|
|
{ |
185
|
|
|
$sets = []; |
186
|
|
|
|
187
|
|
|
$setData = []; |
188
|
|
|
|
189
|
|
|
if (\array_key_exists('sets', $data) && \array_key_exists('set', $data['sets'])) { |
190
|
|
|
$setData = $data['sets']['set']; |
191
|
|
|
} elseif (\array_key_exists('set', $data)) { |
192
|
|
|
$setData = $data['set']; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
foreach ($setData as $set) { |
196
|
|
|
$sets[] = Set::fromApi($set); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return $sets; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|