koel/app/Services/PlaylistService.php

41 lines
982 B
PHP
Raw Normal View History

<?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;
}
2022-07-04 10:39:02 +00:00
public function addSongsToPlaylist(Playlist $playlist, array $songIds): void
{
$playlist->songs()->syncWithoutDetaching($songIds);
}
public function removeSongsFromPlaylist(Playlist $playlist, array $songIds): void
{
$playlist->songs()->detach($songIds);
}
2022-07-29 06:47:10 +00:00
/** @deprecated */
public function populatePlaylist(Playlist $playlist, array $songIds): void
{
$playlist->songs()->sync($songIds);
}
}