koel/app/Builders/ArtistBuilder.php

34 lines
971 B
PHP
Raw Normal View History

<?php
namespace App\Builders;
2024-01-03 17:02:18 +00:00
use App\Facades\License;
use App\Models\Artist;
2024-01-03 17:02:18 +00:00
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
2024-01-03 17:02:18 +00:00
use Illuminate\Database\Query\JoinClause;
class ArtistBuilder extends Builder
{
public function isStandard(): self
{
return $this->whereNotIn('artists.id', [Artist::UNKNOWN_ID, Artist::VARIOUS_ID]);
}
2024-01-03 17:02:18 +00:00
public function accessibleBy(User $user): self
2024-01-03 17:02:18 +00:00
{
if (License::isCommunity()) {
// With the Community license, all artists are accessible by all users.
return $this;
}
return $this->join('songs', static function (JoinClause $join) use ($user): void {
$join->on('artists.id', 'songs.artist_id')
->where(static function (JoinClause $query) use ($user): void {
$query->where('songs.owner_id', $user->id)
->orWhere('songs.is_public', true);
});
});
}
}