koel/app/Repositories/AlbumRepository.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2018-08-29 06:30:39 +00:00
<?php
namespace App\Repositories;
2022-06-10 10:47:46 +00:00
use App\Models\Album;
use App\Models\User;
2020-12-23 11:03:22 +00:00
use App\Repositories\Traits\Searchable;
2022-06-10 10:47:46 +00:00
use Illuminate\Database\Eloquent\Collection;
2018-08-29 06:30:39 +00:00
class AlbumRepository extends AbstractRepository
{
2020-12-23 11:03:22 +00:00
use Searchable;
2022-06-10 10:47:46 +00:00
public function getOne(int $id, ?User $scopedUser = null): Album
{
2022-06-10 10:47:46 +00:00
return Album::withMeta($scopedUser ?? $this->auth->user())
->where('albums.id', $id)
->first();
}
/** @return Collection|array<array-key, Album> */
public function getRecentlyAdded(int $count = 6, ?User $scopedUser = null): Collection
{
return Album::withMeta($scopedUser ?? $this->auth->user())
->isStandard()
->latest('albums.created_at')
->limit($count)
->get();
}
/** @return Collection|array<array-key, Album> */
public function getMostPlayed(int $count = 6, ?User $scopedUser = null): Collection
{
$scopedUser ??= $this->auth->user();
return Album::withMeta($scopedUser ?? $this->auth->user())
->isStandard()
->orderByDesc('play_count')
->limit($count)
->get();
}
/** @return Collection|array<array-key, Album> */
public function getByIds(array $ids, ?User $scopedUser = null): Collection
{
return Album::withMeta($scopedUser ?? $this->auth->user())
->whereIn('albums.id', $ids)
->get();
}
2018-08-29 06:30:39 +00:00
}