1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Usox\HyperSonic\FeatureSet\V1161\Method; |
6
|
|
|
|
7
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Contract\ArtistListDataProviderInterface; |
8
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface; |
9
|
|
|
use Usox\HyperSonic\Response\ResponderInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Retrieves and transforms data for the list of artists |
13
|
|
|
* |
14
|
|
|
* This class covers the `getArtists.view` method |
15
|
|
|
* |
16
|
|
|
* @see http://www.subsonic.org/pages/api.jsp#getArtists |
17
|
|
|
*/ |
18
|
|
|
final class GetArtistsMethod implements V1161MethodInterface |
19
|
|
|
{ |
20
|
2 |
|
public function __construct( |
21
|
|
|
private readonly ResponderFactoryInterface $responderFactory, |
22
|
|
|
) { |
23
|
2 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array<string, scalar> $queryParams |
27
|
|
|
* @param array<string, scalar> $args |
28
|
|
|
*/ |
29
|
1 |
|
public function __invoke( |
30
|
|
|
ArtistListDataProviderInterface $artistListDataProvider, |
31
|
|
|
array $queryParams, |
32
|
|
|
array $args, |
33
|
|
|
): ResponderInterface { |
34
|
1 |
|
$data = []; |
35
|
1 |
|
$currentIndex = null; |
36
|
1 |
|
$indexItem = []; |
37
|
|
|
|
38
|
1 |
|
$musicFolderId = $queryParams['musicFolderId'] ?? null; |
39
|
1 |
|
if ($musicFolderId !== null) { |
40
|
1 |
|
$musicFolderId = (string) $musicFolderId; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
foreach ($artistListDataProvider->getArtists($musicFolderId) as $artist) { |
44
|
1 |
|
$artistIndex = mb_strtoupper(substr($artist['name'], 0, 1)); |
45
|
|
|
|
46
|
1 |
|
if ($artistIndex !== $currentIndex) { |
47
|
1 |
|
if ($indexItem !== []) { |
48
|
1 |
|
$data[] = $indexItem; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$currentIndex = $artistIndex; |
52
|
|
|
|
53
|
1 |
|
$indexItem = [ |
54
|
1 |
|
'name' => $currentIndex, |
55
|
1 |
|
'artist' => [], |
56
|
1 |
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$item = [ |
60
|
1 |
|
'id' => $artist['id'], |
61
|
1 |
|
'name' => $artist['name'], |
62
|
1 |
|
'coverArt' => $artist['coverArtId'], |
63
|
1 |
|
'artistImageUrl' => $artist['artistImageUrl'], |
64
|
1 |
|
'albumCount' => $artist['albumCount'], |
65
|
1 |
|
]; |
66
|
|
|
|
67
|
1 |
|
if ($artist['starred'] !== null) { |
68
|
1 |
|
$item['starred'] = $artist['starred']->format(DATE_ATOM); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
$indexItem['artist'][] = $item; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
if ($indexItem !== []) { |
75
|
1 |
|
$data[] = $indexItem; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
return $this->responderFactory->createArtistsResponder( |
79
|
1 |
|
[ |
80
|
1 |
|
'ignoredArticles' => implode(' ', $artistListDataProvider->getIgnoredArticles()), |
81
|
1 |
|
'index' => $data, |
82
|
1 |
|
] |
83
|
1 |
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|