2022-08-09 18:45:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Builders;
|
|
|
|
|
2024-01-03 17:02:18 +00:00
|
|
|
use App\Facades\License;
|
2022-08-09 18:45:11 +00:00
|
|
|
use App\Models\Album;
|
2024-01-03 17:02:18 +00:00
|
|
|
use App\Models\User;
|
2022-08-09 18:45:11 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2024-01-03 17:02:18 +00:00
|
|
|
use Illuminate\Database\Query\JoinClause;
|
2022-08-09 18:45:11 +00:00
|
|
|
|
|
|
|
class AlbumBuilder extends Builder
|
|
|
|
{
|
|
|
|
public function isStandard(): static
|
|
|
|
{
|
|
|
|
return $this->whereNot('albums.id', Album::UNKNOWN_ID);
|
|
|
|
}
|
2024-01-03 17:02:18 +00:00
|
|
|
|
|
|
|
public function accessibleBy(User $user): static
|
|
|
|
{
|
|
|
|
if (License::isCommunity()) {
|
|
|
|
// With the Community license, all albums are accessible by all users.
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->join('songs', static function (JoinClause $join) use ($user): void {
|
|
|
|
$join->on('albums.id', 'songs.album_id')
|
|
|
|
->where(static function (JoinClause $query) use ($user): void {
|
|
|
|
$query->where('songs.owner_id', $user->id)
|
|
|
|
->orWhere('songs.is_public', true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-08-09 18:45:11 +00:00
|
|
|
}
|