2024-01-18 11:13:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Facades\License;
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
2024-04-24 21:58:19 +00:00
|
|
|
/** @extends Repository<Playlist> */
|
2024-01-18 11:13:05 +00:00
|
|
|
class PlaylistRepository extends Repository
|
|
|
|
{
|
2024-04-18 11:27:07 +00:00
|
|
|
/** @return Collection<array-key, Playlist> */
|
2024-01-18 11:13:05 +00:00
|
|
|
public function getAllAccessibleByUser(User $user): Collection
|
|
|
|
{
|
2024-03-27 09:53:05 +00:00
|
|
|
$ownPlaylists = Playlist::query()
|
|
|
|
->where('playlists.user_id', $user->id)
|
|
|
|
->leftJoin('playlist_playlist_folder', 'playlists.id', '=', 'playlist_playlist_folder.playlist_id')
|
|
|
|
->get(['playlists.*', 'playlist_playlist_folder.folder_id']);
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
if (License::isCommunity()) {
|
2024-03-27 09:53:05 +00:00
|
|
|
return $ownPlaylists;
|
2024-01-18 11:13:05 +00:00
|
|
|
}
|
|
|
|
|
2024-03-27 09:53:05 +00:00
|
|
|
$collaboratedPlaylists = Playlist::query()
|
|
|
|
->join('playlist_collaborators', 'playlists.id', '=', 'playlist_collaborators.playlist_id')
|
|
|
|
->where('playlist_collaborators.user_id', $user->id)
|
|
|
|
->join('playlist_playlist_folder', 'playlists.id', '=', 'playlist_playlist_folder.playlist_id')
|
|
|
|
->get(['playlists.*', 'playlist_playlist_folder.folder_id']);
|
|
|
|
|
|
|
|
return $ownPlaylists->merge($collaboratedPlaylists);
|
2024-01-18 11:13:05 +00:00
|
|
|
}
|
|
|
|
}
|