mirror of
https://github.com/koel/koel
synced 2024-12-23 19:13:06 +00:00
34 lines
823 B
PHP
34 lines
823 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Playlist;
|
|
use App\Models\User;
|
|
|
|
class PlaylistService
|
|
{
|
|
public function createPlaylist(string $name, User $user, array $songs, ?array $ruleGroups = null): Playlist
|
|
{
|
|
/** @var Playlist $playlist */
|
|
$playlist = $user->playlists()->create([
|
|
'name' => $name,
|
|
'rules' => $ruleGroups,
|
|
]);
|
|
|
|
if (!$playlist->is_smart && $songs) {
|
|
$playlist->songs()->sync($songs);
|
|
}
|
|
|
|
return $playlist;
|
|
}
|
|
|
|
public function addSongsToPlaylist(Playlist $playlist, array $songIds): void
|
|
{
|
|
$playlist->songs()->syncWithoutDetaching($songIds);
|
|
}
|
|
|
|
public function removeSongsFromPlaylist(Playlist $playlist, array $songIds): void
|
|
{
|
|
$playlist->songs()->detach($songIds);
|
|
}
|
|
}
|