|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Orm\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Types\Types; |
|
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
9
|
|
|
use Uxmp\Core\Component\Playlist\PlaylistTypeEnum; |
|
10
|
|
|
use Uxmp\Core\Orm\Repository\PlaylistRepository; |
|
11
|
|
|
|
|
12
|
|
|
#[ORM\Entity(repositoryClass: PlaylistRepository::class)] |
|
13
|
|
|
#[ORM\Table(name: 'playlist')] |
|
14
|
|
|
class Playlist implements PlaylistInterface |
|
15
|
|
|
{ |
|
16
|
|
|
#[ORM\Column(type: Types::INTEGER)] |
|
17
|
|
|
#[ORM\Id, ORM\GeneratedValue(strategy: 'AUTO')] |
|
18
|
|
|
private int $id; |
|
19
|
|
|
|
|
20
|
|
|
#[ORM\Column(type: Types::STRING)] |
|
21
|
|
|
private string $name = ''; |
|
22
|
|
|
|
|
23
|
|
|
#[ORM\Column(type: Types::INTEGER, options: ['default' => 0])] |
|
24
|
|
|
private int $owner_user_id = 0; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
#[ORM\Column(type: Types::INTEGER, options: ['default' => 0])] |
|
27
|
|
|
private int $song_count = 0; |
|
28
|
|
|
|
|
29
|
|
|
#[ORM\Column(type: Types::INTEGER, enumType: PlaylistTypeEnum::class, options: ['default' => PlaylistTypeEnum::STATIC])] |
|
30
|
|
|
private PlaylistTypeEnum $type = PlaylistTypeEnum::STATIC; |
|
31
|
|
|
|
|
32
|
|
|
/** @var array<int> */ |
|
33
|
|
|
#[ORM\Column(type: Types::JSON, options: ['default' => '[]'])] |
|
34
|
|
|
private array $song_list = []; |
|
35
|
|
|
|
|
36
|
|
|
#[ORM\ManyToOne(targetEntity: UserInterface::class)] |
|
37
|
|
|
#[ORM\JoinColumn(name: 'owner_user_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
38
|
|
|
private UserInterface $owner; |
|
39
|
|
|
|
|
40
|
|
|
public function getId(): int |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->id; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function getName(): string |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->name; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function setName(string $name): PlaylistInterface |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->name = $name; |
|
53
|
1 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function getOwner(): UserInterface |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->owner; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function setOwner(UserInterface $owner): PlaylistInterface |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->owner = $owner; |
|
64
|
1 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return array<int> |
|
69
|
|
|
*/ |
|
70
|
2 |
|
public function getSongList(): array |
|
71
|
|
|
{ |
|
72
|
2 |
|
return $this->song_list; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param array<int> $songList |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function setSongList(array $songList): PlaylistInterface |
|
79
|
|
|
{ |
|
80
|
2 |
|
$this->song_list = $songList; |
|
81
|
2 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function getSongCount(): int |
|
85
|
|
|
{ |
|
86
|
2 |
|
return $this->song_count; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
public function setSongCount(int $songCount): PlaylistInterface |
|
90
|
|
|
{ |
|
91
|
2 |
|
$this->song_count = $songCount; |
|
92
|
2 |
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
2 |
|
public function getType(): PlaylistTypeEnum |
|
96
|
|
|
{ |
|
97
|
2 |
|
return $this->type; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
1 |
|
public function isStatic(): bool |
|
101
|
|
|
{ |
|
102
|
1 |
|
return $this->getType() === PlaylistTypeEnum::STATIC; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
2 |
|
public function setType(PlaylistTypeEnum $type): PlaylistInterface |
|
106
|
|
|
{ |
|
107
|
2 |
|
$this->type = $type; |
|
108
|
2 |
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Updates the song list and also sets the song count |
|
113
|
|
|
* |
|
114
|
|
|
* @param array<int> $songList |
|
115
|
|
|
*/ |
|
116
|
1 |
|
public function updateSongList( |
|
117
|
|
|
array $songList |
|
118
|
|
|
): PlaylistInterface { |
|
119
|
1 |
|
$this->setSongList($songList); |
|
120
|
1 |
|
$this->setSongCount(count($songList)); |
|
121
|
|
|
|
|
122
|
1 |
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|