|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Orm\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use JetBrains\PhpStorm\Pure; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @Entity(repositoryClass="\Uxmp\Core\Orm\Repository\AlbumRepository") |
|
12
|
|
|
* @Table(name="album") |
|
13
|
|
|
*/ |
|
14
|
|
|
class Album implements AlbumInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Id |
|
18
|
|
|
* @Column(type="integer") |
|
19
|
|
|
* @GeneratedValue |
|
20
|
|
|
*/ |
|
21
|
|
|
private int $id; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @Column(type="string", nullable=true) |
|
25
|
|
|
*/ |
|
26
|
|
|
private ?string $title = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @Column(type="integer") |
|
30
|
|
|
*/ |
|
31
|
|
|
private int $artist_id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @Column(type="integer") |
|
35
|
|
|
*/ |
|
36
|
|
|
private int $catalog_id; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @Column(type="datetime") |
|
40
|
|
|
*/ |
|
41
|
|
|
private \DateTimeInterface $last_modified; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @Column(type="string", length="32", nullable="true", unique=true) |
|
45
|
|
|
*/ |
|
46
|
|
|
private ?string $mbid = null; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @ManyToOne(targetEntity="Artist", inversedBy="albums") |
|
50
|
|
|
* @JoinColumn(name="artist_id", referencedColumnName="id", onDelete="CASCADE") |
|
51
|
|
|
*/ |
|
52
|
|
|
private ArtistInterface $artist; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @ManyToOne(targetEntity="Catalog") |
|
56
|
|
|
* @JoinColumn(name="catalog_id", referencedColumnName="id", onDelete="CASCADE") |
|
57
|
|
|
*/ |
|
58
|
|
|
private CatalogInterface $catalog; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @OneToMany(targetEntity="Disc", mappedBy="album", cascade={"ALL"}, indexBy="id") |
|
62
|
|
|
* |
|
63
|
|
|
* @var ArrayCollection<int, DiscInterface> |
|
64
|
|
|
*/ |
|
65
|
|
|
private iterable $discs; |
|
66
|
|
|
|
|
67
|
1 |
|
#[Pure] |
|
68
|
|
|
public function __construct() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$this->discs = new ArrayCollection(); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getId(): int |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->id; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getTitle(): ?string |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->title; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function setTitle(?string $title): AlbumInterface |
|
84
|
|
|
{ |
|
85
|
|
|
$this->title = $title; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getArtist(): ArtistInterface |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->artist; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function setArtist(ArtistInterface $artist): AlbumInterface |
|
95
|
|
|
{ |
|
96
|
|
|
$this->artist = $artist; |
|
97
|
|
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getMbid(): ?string |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->mbid; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function setMbid(?string $mbid): AlbumInterface |
|
106
|
|
|
{ |
|
107
|
|
|
$this->mbid = $mbid; |
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getDiscs(): iterable |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->discs; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getDiscCount(): int |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->discs->count(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function getCatalog(): CatalogInterface |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->catalog; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function setCatalog(CatalogInterface $catalog): AlbumInterface |
|
127
|
|
|
{ |
|
128
|
|
|
$this->catalog = $catalog; |
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getLength(): int |
|
133
|
|
|
{ |
|
134
|
|
|
return array_sum( |
|
|
|
|
|
|
135
|
|
|
array_map( |
|
136
|
|
|
fn (DiscInterface $disc): int => $disc->getLength(), |
|
137
|
|
|
$this->discs->toArray() |
|
138
|
|
|
) |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function getLastModified(): \DateTimeInterface |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->last_modified; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function setLastModified(\DateTimeInterface $last_modified): AlbumInterface |
|
148
|
|
|
{ |
|
149
|
|
|
$this->last_modified = $last_modified; |
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|