src/AppBundle/Controller/PodcastController.php line 23

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Model\Podcast as PodcastModel;
  4. use AppBundle\Service\PodcastProcessService;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class PodcastController extends BaseController
  8. {
  9.     /** @var PodcastModel */
  10.     private $podcastModel;
  11.     /** @var PodcastProcessService */
  12.     private $podcastProcessService;
  13.     /**
  14.      * List all podcasts with their latest episodes.
  15.      *
  16.      * @return Response
  17.      */
  18.     public function indexAction(): Response
  19.     {
  20.         $this->podcastModel $this->get('eemce.appbundle.podcast');
  21.         $this->podcastProcessService $this->get('eemce.appbundle.podcast_process_service');
  22.         $viewData $this->getMainPageData();
  23.         $viewData['podcasts'] = $this->podcastModel->getAllPodcasts();
  24.         $viewData['episodes'] = $this->podcastModel->getLatestEpisodes(6);
  25.         if (empty($viewData['podcasts'])) {
  26.             throw new NotFoundHttpException();
  27.         }
  28.         if (!empty($viewData['episodes'])) {
  29.             $this->podcastProcessService->processLatestEpisodes($viewData['episodes']);
  30.         }
  31.         $response $this->render('podcast/index.html.twig'$viewData);
  32.         return $this->setResponseCacheHeadersFromConfig($responsefalse'cache_ttl_seconds_other');
  33.     }
  34.     /**
  35.      * Display a specific podcast.
  36.      *
  37.      * @param int $id The podcast ID.
  38.      *
  39.      * @return Response
  40.      */
  41.     public function showAction(int $id): Response
  42.     {
  43.         $this->podcastModel $this->get('eemce.appbundle.podcast');
  44.         $this->podcastProcessService $this->get('eemce.appbundle.podcast_process_service');
  45.         $viewData $this->getMainPageData();
  46.         // Retrieve a single podcast by its ID. Additional attributes can be added if needed.
  47.         $viewData['podcast'] = $this->podcastModel->getPodcastById($id);
  48.         $viewData['episodes'] = $this->podcastModel->getLatestPodcastEpisodes($id6);
  49.         if (empty($viewData['podcast'])) {
  50.             throw new NotFoundHttpException();
  51.         }
  52.         if (!empty($viewData['episodes'])) {
  53.             $this->podcastProcessService->processLatestEpisodes($viewData['episodes'], $viewData['podcast']);
  54.         }
  55.         $viewData['podcast'] = $viewData['podcast'][0];
  56.         $response $this->render('podcast/show.html.twig'$viewData);
  57.         return $this->setResponseCacheHeadersFromConfig($responsefalse'cache_ttl_seconds_other');
  58.     }
  59.     /**
  60.      * Display a specific episode of a podcast
  61.      *
  62.      * @param int $podcastId   The podcast ID.
  63.      * @param int $episodeId   The episode ID.
  64.      *
  65.      * @return Response
  66.      */
  67.     public function showEpisodeAction(int $podcastIdint $episodeId): Response {
  68.         $this->podcastModel $this->get('eemce.appbundle.podcast');
  69.         $this->podcastProcessService $this->get('eemce.appbundle.podcast_process_service');
  70.         $viewData $this->getMainPageData();
  71.         $viewData['episode'] = $this->podcastModel->getPodcastEpisode($episodeId);
  72.         $viewData['episodes'] = $this->podcastModel->getLatestPodcastEpisodes($podcastId60$episodeId);
  73.         if (empty($viewData['episode'])) {
  74.             throw new NotFoundHttpException();
  75.         }
  76.         if (!empty($viewData['episodes'])) {
  77.             $this->podcastProcessService->processLatestEpisodes($viewData['episodes'], $viewData['episode']);
  78.         }
  79.         $viewData['episode'] = $viewData['episode'][0];
  80.         $viewData['episode']['podcastSlug'] = dirname($viewData['episode']['link']); // only for show_episode needs
  81.         $response $this->render('podcast/show_episode.html.twig'$viewData);
  82.         return $this->setResponseCacheHeadersFromConfig($responsefalse'cache_ttl_seconds_other');
  83.     }
  84. }