1 | <?php |
||
25 | class PlaylistBusinessLayer extends BusinessLayer { |
||
26 | |||
27 | private $logger; |
||
28 | |||
29 | public function __construct(PlaylistMapper $playlistMapper, Logger $logger) { |
||
33 | |||
34 | /** |
||
35 | * Return a playlist |
||
36 | * @param int $playlistId the id of the playlist |
||
37 | * @param string $userId the name of the user |
||
38 | * @return Playlist playlist |
||
39 | */ |
||
40 | public function find($playlistId, $userId) { |
||
43 | |||
44 | /** |
||
45 | * Returns all playlists |
||
46 | * @param string $userId the name of the user |
||
47 | * @return Playlist[] playlists |
||
48 | */ |
||
49 | public function findAll($userId) { |
||
52 | |||
53 | public function addTracks($trackIds, $playlistId, $userId) { |
||
54 | $playlist = $this->find($playlistId, $userId); |
||
55 | $prevTrackIds = $playlist->getTrackIdsAsArray(); |
||
56 | $playlist->setTrackIdsFromArray(array_merge($prevTrackIds, $trackIds)); |
||
57 | $this->mapper->update($playlist); |
||
58 | return $playlist; |
||
59 | } |
||
60 | |||
61 | public function removeTracks($trackIndices, $playlistId, $userId) { |
||
62 | $playlist = $this->find($playlistId, $userId); |
||
63 | $trackIds = $playlist->getTrackIdsAsArray(); |
||
64 | $trackIds = array_diff_key($trackIds, array_flip($trackIndices)); |
||
65 | $playlist->setTrackIdsFromArray($trackIds); |
||
66 | $this->mapper->update($playlist); |
||
67 | return $playlist; |
||
68 | } |
||
69 | |||
70 | public function moveTrack($fromIndex, $toIndex, $playlistId, $userId) { |
||
79 | |||
80 | public function create($name, $userId) { |
||
81 | $playlist = new Playlist(); |
||
82 | $playlist->setName($name); |
||
83 | $playlist->setUserId($userId); |
||
84 | |||
85 | return $this->mapper->insert($playlist); |
||
86 | } |
||
87 | |||
88 | public function rename($name, $playlistId, $userId) { |
||
89 | $playlist = $this->find($playlistId, $userId); |
||
90 | $playlist->setName($name); |
||
91 | $this->mapper->update($playlist); |
||
92 | return $playlist; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * removes tracks from all available playlists |
||
97 | * @param int[] $trackIds array of all track IDs to remove |
||
98 | */ |
||
99 | public function removeTracksFromAllLists($trackIds) { |
||
110 | } |
||
111 |