2020-06-10 15:00:12 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
class Episode extends BaseController
|
2020-06-10 15:00:12 +00:00
|
|
|
{
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Episode|null
|
|
|
|
*/
|
|
|
|
protected $episode;
|
2020-06-10 15:00:12 +00:00
|
|
|
|
2020-06-30 18:17:41 +02:00
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
2020-09-04 09:09:26 +00:00
|
|
|
$this->podcast = (new PodcastModel())->getPodcastByName($params[0]);
|
2020-08-04 11:25:22 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
count($params) > 1 &&
|
2020-09-04 09:09:26 +00:00
|
|
|
!($this->episode = (new EpisodeModel())->getEpisodeBySlug(
|
|
|
|
$this->podcast->id,
|
|
|
|
$params[1]
|
|
|
|
))
|
2020-08-04 11:25:22 +00:00
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function index()
|
2020-06-30 18:17:41 +02:00
|
|
|
{
|
2020-09-04 09:09:26 +00:00
|
|
|
self::triggerWebpageHit($this->episode->podcast_id);
|
2020-07-02 10:08:32 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
if (
|
|
|
|
!($cachedView = cache(
|
|
|
|
"page_podcast{$this->episode->podcast_id}_episode{$this->episode->id}"
|
|
|
|
))
|
|
|
|
) {
|
|
|
|
$previousNextEpisodes = (new EpisodeModel())->getPreviousNextEpisodes(
|
|
|
|
$this->episode,
|
|
|
|
$this->podcast->type
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'previousEpisode' => $previousNextEpisodes['previous'],
|
|
|
|
'nextEpisode' => $previousNextEpisodes['next'],
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
|
|
|
|
|
|
|
// The page cache is set to a decade so it is deleted manually upon podcast update
|
|
|
|
return view('episode', $data, [
|
|
|
|
'cache' => DECADE,
|
|
|
|
'cache_name' => "page_podcast{$this->episode->podcast_id}_episode{$this->episode->id}",
|
|
|
|
]);
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
return $cachedView;
|
2020-06-10 15:00:12 +00:00
|
|
|
}
|
|
|
|
}
|