src/AppBundle/Controller/SnippetsController.php line 26

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Model\Article;
  4. use AppBundle\Model\Broadcast;
  5. use AppBundle\Model\Menu;
  6. use AppBundle\Model\Podcast;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Request;
  9. class SnippetsController extends BaseController
  10. {
  11.     /** @var Article */
  12.     private $articleModel;
  13.     /** @var Menu */
  14.     private $menuModel;
  15.     /** @var Podcast */
  16.     private $podcastModel;
  17.     /** @var Broadcast */
  18.     private $broadcastModel;
  19.     public function getHeaderMenuAction(Request $request)
  20.     {
  21.         $this->menuModel $this->get('eemce.appbundle.menu');
  22.         $this->articleModel $this->get('eemce.appbundle.article');
  23.         $currentRelativePath $request->server->get('PHP_SELF');
  24.         $segments explode('/'trim($currentRelativePath'/'));
  25.         $lastSegment end($segments);
  26.         $viewData = [];
  27.         $viewData['lastSegmentUrl'] = $lastSegment;
  28.         $viewData['header_menu'] = $this->menuModel->getHeaderMenu();
  29.         $viewData['jmArticles'] = $this->articleModel->getBroadcastFull(25);
  30.         $viewData['dArticles'] = $this->articleModel->getBroadcastFull(35);
  31.         $viewData['sArticles'] = $this->articleModel->getBroadcastFull(45);
  32.         $response $this->render('includes/header_menu.html.twig'$viewData);
  33.         // rendered as ESI => no need to set cache headers locally
  34.         return $response;
  35.     }
  36.     public function getFooterAction()
  37.     {
  38.         $this->menuModel $this->get('eemce.appbundle.menu');
  39.         $this->podcastModel $this->get('eemce.appbundle.podcast');
  40.         // followings are hard inserts in DB
  41.         $viewData = [];
  42.         $viewData['footer_menu_airing'] = $this->menuModel->getMenu(3);
  43.         $viewData['footer_menu_categories'] = $this->menuModel->getMenu(4);
  44.         $viewData['footer_menu_bottom'] = $this->menuModel->getMenu(2);
  45.         $viewData['footer_menu_bottom'] = $this->menuModel->getMenu(2);
  46.         $viewData['footer_menu_podcasts'] = $this->podcastModel->getAllPodcasts();
  47.         $response $this->render('includes/footer.html.twig'$viewData);
  48.         // rendered as ESI => no need to set cache headers locally
  49.         return $response;
  50.     }
  51.     // TODO maybe not used
  52.     public function getModeratorsAction()
  53.     {
  54.         $this->broadcastModel $this->get('eemce.appbundle.broadcast');
  55.         $this->articleModel $this->get('eemce.appbundle.article');
  56.         $broadcasts $this->broadcastModel->getActiveBroadcasts();
  57.         foreach ($broadcasts as $broadcast) {
  58.             $broadcast->setCategories($this->broadcastModel->getBroadcastCategories($broadcast->getId()));
  59.             if ($broadcast->getId() == 6// load articles for sarkan
  60.             {
  61.                 $broadcast->setArticles($this->articleModel->getBroadcastFull($broadcast->getId(), 2));
  62.             }
  63.         }
  64.         $viewData = [];
  65.         $viewData['broadcasts'] = $broadcasts;
  66.         $response $this->render('includes/moderators.html.twig'$viewData);
  67.         // rendered as ESI => no need to set cache headers locally
  68.         return $response;
  69.     }
  70.     public function getPpcfgAction(): Response
  71.     {
  72.         $viewData = [];
  73.         $viewData['radio_config'] = $this->get('eemce.appbundle.sepia_stream')->getPlayerConfig();
  74.         $viewData['podcast_config'] = [];
  75.         $podcasts $this->get('eemce.appbundle.podcast')->getPodcastsWithLatestEpisodes(10);
  76.         foreach ($podcasts as $value) {
  77.             $this->get('eemce.appbundle.podcast_process_service')->processLatestEpisodes($value['episodes'], $value['podcast']);
  78.             $podcast = [
  79.                 'id' => $value['podcast']['id'],
  80.                 'name' => $value['podcast']['name'],
  81.                 'slug' => $value['podcast']['podcastSlug'],
  82.                 'seoKeywords' => $value['podcast']['metaSeoTitle'],
  83.                 'seoDescription' => $value['podcast']['metaSeoDescription'],
  84.             ];
  85.             $podcast['episodes'] = $value['episodes'];
  86.             $viewData['podcast_config'][] = $podcast;
  87.         }
  88.         $response $this->render('includes/ppcfg.html.twig'$viewData);
  89.         return $this->setResponseCacheHeadersFromConfig($responsefalse'cache_ttl_seconds_other');
  90.     }
  91.     /**
  92.      * Renders empty document with Gemius code for respective stream
  93.      *
  94.      * This is horrible, but needs to be done as an iframe because:
  95.      *
  96.      * - gemius code needs to be changed dynamically (client-side) each time user switches to another stream
  97.      * - gemius prism documentation did not reveal that they support a more sane method of doing this
  98.      * - we want to keep the ability to copy/paste gemius codes _as-is_ via admin UI (avoiding the need to fiddle with
  99.      *   them in any way)
  100.      *
  101.      * @param string $streamSlug
  102.      *
  103.      * @return Response
  104.      */
  105.     public function playerGemiusIframeAction($streamSlug)
  106.     {
  107.         $gemiusCode null;
  108.         $activeStreams $this->get('eemce.appbundle.sepia_stream')->getActiveStreams();
  109.         foreach ($activeStreams as $stream) {
  110.             if ($stream->getSlug() != $streamSlug) {
  111.                 continue;
  112.             }
  113.             // found
  114.             $gemiusCode $stream->getGemiusCode();
  115.         }
  116.         $response = !empty($gemiusCode) ? new Response($gemiusCode) : new Response(''204);
  117.         $response $this->setResponseCacheHeadersFromConfig($responsefalse'cache_ttl_seconds_other');
  118.         return $response;
  119.     }
  120. }