public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $episodeId) { if (!($episode = Episode::find($episodeId))) { continue; } $episode->delete(); } Flash::success(e(trans('cosmicradiotv.podcast::lang.episode.delete_success_multiple'))); } return $this->listRefresh(); }
/** * Set components state based on parameters * * @throws ModelNotFoundException */ public function setState() { $showSlugFilter = $this->property('showSlugFilter'); if (!empty($showSlugFilter)) { $this->show = Show::query()->where('slug', $showSlugFilter)->firstOrFail(); $this->episode = $this->show->episodes()->getQuery()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail(); } else { $this->episode = Episode::query()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail(); } $this->releases = Collection::make($this->episode->releases); // Creates a copy $this->releases->sort(function (Release $a, Release $b) { // Order by the sort_order column $aRating = $a->release_type->sort_order; $bRating = $b->release_type->sort_order; return $aRating - $bRating; }); }
/** * Loads episodes for the current show (or all shows if not set * * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|Collection|Episode[] */ protected function loadEpisodes() { if ($this->show) { // Show's episodes $query = $this->show->episodes(); $setShows = true; // Skips loading from database } else { // All shows' episodes $query = Episode::query(); $query->with('show'); $setShows = false; } $query->with('image')->where('published', true)->orderBy('release', 'desc'); if ($this->tag) { $query->whereHas('tags', function (Builder $q) { $q->where('cosmicradiotv_podcast_tags.id', $this->tag->id); }); } if ($this->allowPagination) { /** @var LengthAwarePaginator|Episode[] $returns */ $returns = $query->paginate(intval($this->property('perPage'))); $collection = $returns->getCollection(); } else { $returns = $collection = $query->take($this->property('perPage'))->get(); } $collection->each(function (Episode $episode) use($setShows) { if ($setShows) { $episode->setRelation('show', $this->show); } // Cache URL value to the model $episode->url = $this->getEpisodeURL($episode); }); return $returns; }
/** * Load the episode as requested * * @throws ModelNotFoundException * @return Episode */ protected function loadEpisode() { // Show filter / Query base if ($this->show) { // Show's episodes $query = $this->show->episodes(); $setShow = true; // Skips loading from database $latest = false; // In case of Show & Episode no need to find latest } else { // All shows' episodes $query = Episode::query(); $query->with('show'); $setShow = false; $latest = true; } // Episode slug filter if ($this->property('episodeSlug')) { // Load specific episode, unless show isn't set $latest = $latest || false; $query->where('slug', $this->property('episodeSlug')); } else { // Load latest episode $latest = true; } // Tag filter if ($this->tag) { $query->whereHas('tags', function (Builder $q) { $q->where('cosmicradiotv_podcast_tags.id', $this->tag->id); }); } // Generic rules $query->with(['releases', 'releases.release_type', 'image', 'tags'])->where('published', true); // If latest also order by if ($latest) { $query->orderBy('release', 'desc'); } $episode = $query->firstOrFail(); if ($setShow) { // Set show on episode $episode->setRelation('show', $this->show); } else { // Set component's show to episode's show $this->show = $episode->show; } return $episode; }