|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Api\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use JsonSerializable; |
|
8
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
9
|
|
|
use Uxmp\Core\Orm\Model\PlaybackHistoryInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class PlaybackHistoryItem implements JsonSerializable |
|
12
|
|
|
{ |
|
13
|
2 |
|
public function __construct( |
|
14
|
|
|
private ConfigProviderInterface $config, |
|
15
|
|
|
private PlaybackHistoryInterface $playbackHistory, |
|
16
|
|
|
) { |
|
17
|
2 |
|
} |
|
18
|
|
|
|
|
19
|
1 |
|
public function jsonSerialize() |
|
20
|
|
|
{ |
|
21
|
1 |
|
$song = $this->playbackHistory->getSong(); |
|
22
|
1 |
|
$album = $song->getDisc()->getAlbum(); |
|
23
|
1 |
|
$user = $this->playbackHistory->getUser(); |
|
24
|
1 |
|
$artist = $song->getArtist(); |
|
25
|
|
|
|
|
26
|
1 |
|
$songId = $song->getId(); |
|
27
|
1 |
|
$albumId = $album->getId(); |
|
28
|
1 |
|
$baseUrl = $this->config->getBaseUrl(); |
|
29
|
|
|
|
|
30
|
|
|
return [ |
|
31
|
1 |
|
'id' => $songId, |
|
32
|
1 |
|
'name' => $song->getTitle(), |
|
33
|
1 |
|
'artistName' => $artist->getTitle(), |
|
34
|
1 |
|
'albumName' => $album->getTitle(), |
|
35
|
1 |
|
'trackNumber' => $song->getTrackNumber(), |
|
36
|
1 |
|
'playUrl' => sprintf('%s/play/%d', $baseUrl, $songId), |
|
37
|
1 |
|
'cover' => sprintf('%s/art/album/%d', $baseUrl, $albumId), |
|
38
|
1 |
|
'artistId' => $artist->getId(), |
|
39
|
1 |
|
'albumId' => $albumId, |
|
40
|
1 |
|
'length' => $song->getLength(), |
|
41
|
1 |
|
'userId' => $user->getId(), |
|
42
|
1 |
|
'userName' => $user->getName(), |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|