2018-08-29 06:30:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\User;
|
2020-12-24 12:41:18 +00:00
|
|
|
use App\Repositories\Traits\Searchable;
|
2022-08-09 18:45:11 +00:00
|
|
|
use Illuminate\Contracts\Pagination\Paginator;
|
2022-06-10 10:47:46 +00:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-08-29 06:30:39 +00:00
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
class ArtistRepository extends Repository
|
2018-08-29 06:30:39 +00:00
|
|
|
{
|
2020-12-24 12:41:18 +00:00
|
|
|
use Searchable;
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
/** @return Collection|array<array-key, Artist> */
|
|
|
|
public function getMostPlayed(int $count = 6, ?User $scopedUser = null): Collection
|
2018-08-29 09:41:24 +00:00
|
|
|
{
|
2022-08-09 18:45:11 +00:00
|
|
|
return Artist::query()
|
|
|
|
->withMeta($scopedUser ?? $this->auth->user())
|
2022-06-10 10:47:46 +00:00
|
|
|
->isStandard()
|
|
|
|
->orderByDesc('play_count')
|
|
|
|
->limit($count)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOne(int $id, ?User $scopedUser = null): Artist
|
|
|
|
{
|
2022-08-09 18:45:11 +00:00
|
|
|
return Artist::query()
|
|
|
|
->withMeta($scopedUser ?? $this->auth->user())
|
2022-06-10 10:47:46 +00:00
|
|
|
->where('artists.id', $id)
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return Collection|array<array-key, Artist> */
|
|
|
|
public function getByIds(array $ids, ?User $scopedUser = null): Collection
|
|
|
|
{
|
2022-08-09 18:45:11 +00:00
|
|
|
return Artist::query()
|
|
|
|
->withMeta($scopedUser ?? $this->auth->user())
|
2022-06-10 10:47:46 +00:00
|
|
|
->isStandard()
|
|
|
|
->whereIn('artists.id', $ids)
|
|
|
|
->get();
|
2018-08-29 09:41:24 +00:00
|
|
|
}
|
2022-08-09 18:45:11 +00:00
|
|
|
|
|
|
|
public function paginate(?User $scopedUser = null): Paginator
|
|
|
|
{
|
|
|
|
return Artist::query()
|
|
|
|
->withMeta($scopedUser ?? $this->auth->user())
|
|
|
|
->isStandard()
|
|
|
|
->orderBy('artists.name')
|
|
|
|
->simplePaginate(21);
|
|
|
|
}
|
2018-08-29 06:30:39 +00:00
|
|
|
}
|