2024-05-19 05:49:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2024-05-31 05:40:34 +00:00
|
|
|
use App\Models\Podcast;
|
2024-05-19 05:49:42 +00:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/** @extends Repository<Podcast> */
|
|
|
|
class PodcastRepository extends Repository
|
|
|
|
{
|
|
|
|
public function findOneByUrl(string $url): ?Podcast
|
|
|
|
{
|
|
|
|
return $this->findOneBy(['url' => $url]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return Collection<Podcast> */
|
|
|
|
public function getAllByUser(User $user): Collection
|
|
|
|
{
|
2024-06-13 14:46:13 +00:00
|
|
|
return $user->podcasts()->orderByPivot('updated_at', 'desc')->get();
|
2024-05-19 05:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return Collection<Podcast> */
|
2024-05-31 05:40:34 +00:00
|
|
|
public function getMany(array $ids, bool $preserveOrder = false, ?User $user = null): Collection
|
2024-05-19 05:49:42 +00:00
|
|
|
{
|
|
|
|
$podcasts = Podcast::query()
|
|
|
|
->subscribedBy($user ?? $this->auth->user())
|
|
|
|
->whereIn('podcasts.id', $ids)
|
|
|
|
->groupBy('podcasts.id')
|
|
|
|
->distinct()
|
|
|
|
->get('podcasts.*');
|
|
|
|
|
2024-05-31 05:40:34 +00:00
|
|
|
return $preserveOrder ? $podcasts->orderByArray($ids) : $podcasts;
|
2024-05-19 05:49:42 +00:00
|
|
|
}
|
|
|
|
}
|