<?php
namespace AppBundle\Controller;
use AppBundle\Model\Article;
use AppBundle\Model\Broadcast;
use AppBundle\Model\Menu;
use AppBundle\Model\Podcast;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class SnippetsController extends BaseController
{
/** @var Article */
private $articleModel;
/** @var Menu */
private $menuModel;
/** @var Podcast */
private $podcastModel;
/** @var Broadcast */
private $broadcastModel;
public function getHeaderMenuAction(Request $request)
{
$this->menuModel = $this->get('eemce.appbundle.menu');
$this->articleModel = $this->get('eemce.appbundle.article');
$currentRelativePath = $request->server->get('PHP_SELF');
$segments = explode('/', trim($currentRelativePath, '/'));
$lastSegment = end($segments);
$viewData = [];
$viewData['lastSegmentUrl'] = $lastSegment;
$viewData['header_menu'] = $this->menuModel->getHeaderMenu();
$viewData['jmArticles'] = $this->articleModel->getBroadcastFull(2, 5);
$viewData['dArticles'] = $this->articleModel->getBroadcastFull(3, 5);
$viewData['sArticles'] = $this->articleModel->getBroadcastFull(4, 5);
$response = $this->render('includes/header_menu.html.twig', $viewData);
// rendered as ESI => no need to set cache headers locally
return $response;
}
public function getFooterAction()
{
$this->menuModel = $this->get('eemce.appbundle.menu');
$this->podcastModel = $this->get('eemce.appbundle.podcast');
// followings are hard inserts in DB
$viewData = [];
$viewData['footer_menu_airing'] = $this->menuModel->getMenu(3);
$viewData['footer_menu_categories'] = $this->menuModel->getMenu(4);
$viewData['footer_menu_bottom'] = $this->menuModel->getMenu(2);
$viewData['footer_menu_bottom'] = $this->menuModel->getMenu(2);
$viewData['footer_menu_podcasts'] = $this->podcastModel->getAllPodcasts();
$response = $this->render('includes/footer.html.twig', $viewData);
// rendered as ESI => no need to set cache headers locally
return $response;
}
// TODO maybe not used
public function getModeratorsAction()
{
$this->broadcastModel = $this->get('eemce.appbundle.broadcast');
$this->articleModel = $this->get('eemce.appbundle.article');
$broadcasts = $this->broadcastModel->getActiveBroadcasts();
foreach ($broadcasts as $broadcast) {
$broadcast->setCategories($this->broadcastModel->getBroadcastCategories($broadcast->getId()));
if ($broadcast->getId() == 6) // load articles for sarkan
{
$broadcast->setArticles($this->articleModel->getBroadcastFull($broadcast->getId(), 2));
}
}
$viewData = [];
$viewData['broadcasts'] = $broadcasts;
$response = $this->render('includes/moderators.html.twig', $viewData);
// rendered as ESI => no need to set cache headers locally
return $response;
}
public function getPpcfgAction(): Response
{
$viewData = [];
$viewData['radio_config'] = $this->get('eemce.appbundle.sepia_stream')->getPlayerConfig();
$viewData['podcast_config'] = [];
$podcasts = $this->get('eemce.appbundle.podcast')->getPodcastsWithLatestEpisodes(10);
foreach ($podcasts as $value) {
$this->get('eemce.appbundle.podcast_process_service')->processLatestEpisodes($value['episodes'], $value['podcast']);
$podcast = [
'id' => $value['podcast']['id'],
'name' => $value['podcast']['name'],
'slug' => $value['podcast']['podcastSlug'],
'seoKeywords' => $value['podcast']['metaSeoTitle'],
'seoDescription' => $value['podcast']['metaSeoDescription'],
];
$podcast['episodes'] = $value['episodes'];
$viewData['podcast_config'][] = $podcast;
}
$response = $this->render('includes/ppcfg.html.twig', $viewData);
return $this->setResponseCacheHeadersFromConfig($response, false, 'cache_ttl_seconds_other');
}
/**
* Renders empty document with Gemius code for respective stream
*
* This is horrible, but needs to be done as an iframe because:
*
* - gemius code needs to be changed dynamically (client-side) each time user switches to another stream
* - gemius prism documentation did not reveal that they support a more sane method of doing this
* - we want to keep the ability to copy/paste gemius codes _as-is_ via admin UI (avoiding the need to fiddle with
* them in any way)
*
* @param string $streamSlug
*
* @return Response
*/
public function playerGemiusIframeAction($streamSlug)
{
$gemiusCode = null;
$activeStreams = $this->get('eemce.appbundle.sepia_stream')->getActiveStreams();
foreach ($activeStreams as $stream) {
if ($stream->getSlug() != $streamSlug) {
continue;
}
// found
$gemiusCode = $stream->getGemiusCode();
}
$response = !empty($gemiusCode) ? new Response($gemiusCode) : new Response('', 204);
$response = $this->setResponseCacheHeadersFromConfig($response, false, 'cache_ttl_seconds_other');
return $response;
}
}