1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Music app |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Morris Jobke <[email protected]> |
10
|
|
|
* @author Pauli Järvinen <[email protected]> |
11
|
|
|
* @copyright Morris Jobke 2013, 2014 |
12
|
|
|
* @copyright Pauli Järvinen 2017 - 2023 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace OCA\Music\Db; |
16
|
|
|
|
17
|
|
|
use OCP\IL10N; |
18
|
|
|
use OCP\IURLGenerator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @method ?string getName() |
22
|
|
|
* @method void setName(?string $name) |
23
|
|
|
* @method ?int getCoverFileId() |
24
|
|
|
* @method void setCoverFileId(?int $coverFileId) |
25
|
|
|
* @method ?string getMbid() |
26
|
|
|
* @method void setMbid(?string $mbid) |
27
|
|
|
* @method string getHash() |
28
|
|
|
* @method void setHash(string $hash) |
29
|
|
|
* @method ?string getStarred() |
30
|
|
|
* @method void setStarred(?string $timestamp) |
31
|
|
|
* @method ?int getRating() |
32
|
|
|
* @method setRating(?int $rating) |
33
|
|
|
*/ |
34
|
|
|
class Artist extends Entity { |
35
|
|
|
public $name; |
36
|
|
|
public $coverFileId; |
37
|
|
|
public $mbid; |
38
|
|
|
public $hash; |
39
|
|
|
public $starred; |
40
|
|
|
public $rating; |
41
|
|
|
|
42
|
|
|
// not part of the standard content, injected separately when needed |
43
|
|
|
private $lastfmUrl; |
44
|
|
|
private $albums; |
45
|
|
|
private $tracks; |
46
|
|
|
|
47
|
|
|
public function __construct() { |
48
|
|
|
$this->addType('coverFileId', 'int'); |
49
|
|
|
$this->addType('rating', 'int'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getLastfmUrl() : ?string { |
53
|
|
|
return $this->lastfmUrl; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setLastfmUrl(?string $lastfmUrl) : void { |
57
|
|
|
$this->lastfmUrl = $lastfmUrl; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return ?Album[] |
62
|
|
|
*/ |
63
|
|
|
public function getAlbums() : ?array { |
64
|
|
|
return $this->albums; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Album[] $albums |
69
|
|
|
*/ |
70
|
|
|
public function setAlbums(array $albums) : void { |
71
|
|
|
$this->albums = $albums; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return ?Track[] |
76
|
|
|
*/ |
77
|
|
|
public function getTracks() : ?array { |
78
|
|
|
return $this->tracks; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param Track[] $tracks |
83
|
|
|
*/ |
84
|
|
|
public function setTracks(array $tracks) : void { |
85
|
|
|
$this->tracks = $tracks; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getUri(IURLGenerator $urlGenerator) : string { |
89
|
|
|
return $urlGenerator->linkToRoute( |
90
|
|
|
'music.shivaApi.artist', |
91
|
|
|
['artistId' => $this->id] |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getNameString(IL10N $l10n) : string { |
96
|
|
|
return $this->getName() ?: self::unknownNameString($l10n); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Return the cover URL to be used in the Shiva API |
101
|
|
|
*/ |
102
|
|
|
public function coverToAPI(IURLGenerator $urlGenerator) : ?string { |
103
|
|
|
$coverUrl = null; |
104
|
|
|
if ($this->getCoverFileId() > 0) { |
105
|
|
|
$coverUrl = $urlGenerator->linkToRoute('music.api.artistCover', |
106
|
|
|
['artistId' => $this->getId()]); |
107
|
|
|
} |
108
|
|
|
return $coverUrl; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $albums in the "toCollection" format |
113
|
|
|
*/ |
114
|
|
|
public function toCollection(IL10N $l10n, array $albums) : array { |
115
|
|
|
return [ |
116
|
|
|
'id' => $this->getId(), |
117
|
|
|
'name' => $this->getNameString($l10n), |
118
|
|
|
'albums' => $albums |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function toAPI(IURLGenerator $urlGenerator, IL10N $l10n) : array { |
123
|
|
|
return [ |
124
|
|
|
'id' => $this->getId(), |
125
|
|
|
'name' => $this->getNameString($l10n), |
126
|
|
|
'image' => $this->coverToAPI($urlGenerator), |
127
|
|
|
'slug' => $this->slugify('name'), |
128
|
|
|
'uri' => $this->getUri($urlGenerator) |
129
|
|
|
]; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public static function unknownNameString(IL10N $l10n) : string { |
133
|
|
|
return (string) $l10n->t('Unknown artist'); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|