<?php
/**
* Created by Elements.at New Media Solutions GmbH
*
*/
namespace App\Controller;
use App\Service\NewsService;
use Pimcore\Model\DataObject\News;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class NewsController extends AbstractController
{
public function overviewAction(Request $request, NewsService $newsService): Response
{
$bigTeaserEditable = $this->getDocumentEditable('renderlet', 'bigTeaserGrid')->getData();
$smallTeasersEditable1 = $this->getDocumentEditable('renderlet', 'smallTeaserGrid-1')->getData();
$smallTeasersEditable2 = $this->getDocumentEditable('renderlet', 'smallTeaserGrid-2')->getData();
$linkTeasersEditable1 = $this->getDocumentEditable('renderlet', 'smallLinkGrid-1')->getData();
$linkTeasersEditable2 = $this->getDocumentEditable('renderlet', 'smallLinkGrid-2')->getData();
$linkTeasersEditable3 = $this->getDocumentEditable('renderlet', 'smallLinkGrid-3')->getData();
$newsGridArray = $newsService->getSortedNewsListing()->load();
$newsGridArray = !$bigTeaserEditable['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $bigTeaserEditable) ;
$newsGridArray = !$smallTeasersEditable1['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $smallTeasersEditable1);
$newsGridArray = !$smallTeasersEditable2['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $smallTeasersEditable2);
$newsGridArray = !$linkTeasersEditable1['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $linkTeasersEditable1);
$newsGridArray = !$linkTeasersEditable2['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $linkTeasersEditable2);
$newsGridArray = !$linkTeasersEditable3['id'] ? $newsGridArray : $newsService->filterNewsArray($newsGridArray, $linkTeasersEditable3);
$returnArray = $newsService->getNewsOverviewVars($request, $this->document);
$returnArray['newsList'] = $newsGridArray;
if ($request->get('ajax')) {
$template = $this->renderTemplate('news/partials/news-teaser-grid-result.html.twig', $returnArray);
return $this->json(['success' => true, 'html' => $template->getContent()], 200);
}
return $this->render('news/overview.html.twig', $returnArray);
}
public function micrositeOverviewAction(Request $request, NewsService $newsService): Response
{
return $this->render('news/microsite-overview.html.twig', $newsService->getNewsOverviewVars($request, $this->document));
}
public function detailAction(Request $request): Response
{
$newsList = [];
$news = News::getById($request->get('id'));
if ((!($news instanceof News) || !$news->isPublished()) && !$request->get('pimcore_object_preview')) {
throw new NotFoundHttpException('Requested object not found or not published!');
}
$newsCategories = $news->getCategories();
if ($newsCategories) {
$categoryFilterCondition = [];
$newsList = new News\Listing();
foreach ($newsCategories as $newsCategory) {
$categoryFilterCondition[] = 'FIND_IN_SET(' . intval($newsCategory->getId()) . ', categories)';
}
$newsList->addConditionParam(implode(' OR ', $categoryFilterCondition));
}
return $this->render('news/detail.html.twig', [ 'news' => $news, 'newsList' => $newsList]);
}
}