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 Pauli Järvinen <[email protected]> |
10
|
|
|
* @copyright Pauli Järvinen 2020 - 2023 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Db; |
14
|
|
|
|
15
|
|
|
use OCP\IL10N; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @method string getName() |
19
|
|
|
* @method void setName(string $name) |
20
|
|
|
* @method string getLowerName() |
21
|
|
|
* @method void setLowerName(string $lowerName) |
22
|
|
|
* |
23
|
|
|
* @method int getTrackCount() |
24
|
|
|
* @method int getAlbumCount() |
25
|
|
|
* @method int getArtistCount() |
26
|
|
|
*/ |
27
|
|
|
class Genre extends Entity { |
28
|
|
|
public $name; |
29
|
|
|
public $lowerName; |
30
|
|
|
// not from the music_genres table but still part of the standard content of this entity |
31
|
|
|
public $trackCount; |
32
|
|
|
public $albumCount; |
33
|
|
|
public $artistCount; |
34
|
|
|
|
35
|
|
|
// not part of the standard content, injected separately when needed |
36
|
|
|
public $trackIds; |
37
|
|
|
|
38
|
|
|
public function __construct() { |
39
|
|
|
$this->addType('trackCount', 'int'); |
40
|
|
|
$this->addType('albumCount', 'int'); |
41
|
|
|
$this->addType('artistCount', 'int'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ?int[] |
46
|
|
|
*/ |
47
|
|
|
public function getTrackIds() : array { |
48
|
|
|
return $this->trackIds; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param int[] $trackIds |
53
|
|
|
*/ |
54
|
|
|
public function setTrackIds(array $trackIds) : void { |
55
|
|
|
$this->trackIds = $trackIds; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getNameString(IL10N $l10n) { |
59
|
|
|
return $this->getName() ?: self::unknownNameString($l10n); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function toApi() { |
63
|
|
|
return [ |
64
|
|
|
'id' => $this->getId(), |
65
|
|
|
'name' => $this->getName(), |
66
|
|
|
'trackIds' => $this->trackIds ? \array_map('\intval', $this->trackIds) : [] |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function toAmpacheApi(IL10N $l10n) { |
71
|
|
|
return [ |
72
|
|
|
'id' => (string)$this->getId(), |
73
|
|
|
'name' => $this->getNameString($l10n), |
74
|
|
|
'albums' => $this->getAlbumCount(), |
75
|
|
|
'artists' => $this->getArtistCount(), |
76
|
|
|
'songs' => $this->getTrackCount(), |
77
|
|
|
'videos' => 0, |
78
|
|
|
'playlists' => 0, |
79
|
|
|
'live_streams' => 0 |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function unknownNameString(IL10N $l10n) { |
84
|
|
|
return (string) $l10n->t('(Unknown genre)'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|