src/Controller/NewsController.php line 72

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller;
  7. use App\Service\NewsService;
  8. use Pimcore\Model\DataObject\News;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. class NewsController extends AbstractController
  13. {
  14.     public function overviewAction(Request $requestNewsService $newsService): Response
  15.     {
  16.         $bigTeaserEditable $this->getDocumentEditable('renderlet''bigTeaserGrid')->getData();
  17.         $smallTeasersEditable1 $this->getDocumentEditable('renderlet''smallTeaserGrid-1')->getData();
  18.         $smallTeasersEditable2 $this->getDocumentEditable('renderlet''smallTeaserGrid-2')->getData();
  19.         $linkTeasersEditable1 $this->getDocumentEditable('renderlet''smallLinkGrid-1')->getData();
  20.         $linkTeasersEditable2 $this->getDocumentEditable('renderlet''smallLinkGrid-2')->getData();
  21.         $linkTeasersEditable3 $this->getDocumentEditable('renderlet''smallLinkGrid-3')->getData();
  22.         $newsGridArray $newsService->getSortedNewsListing()->load();
  23.         $newsGridArray = !$bigTeaserEditable['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$bigTeaserEditable) ;
  24.         $newsGridArray = !$smallTeasersEditable1['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$smallTeasersEditable1);
  25.         $newsGridArray = !$smallTeasersEditable2['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$smallTeasersEditable2);
  26.         $newsGridArray = !$linkTeasersEditable1['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$linkTeasersEditable1);
  27.         $newsGridArray = !$linkTeasersEditable2['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$linkTeasersEditable2);
  28.         $newsGridArray = !$linkTeasersEditable3['id'] ? $newsGridArray $newsService->filterNewsArray($newsGridArray$linkTeasersEditable3);
  29.         $returnArray $newsService->getNewsOverviewVars($request$this->document);
  30.         $returnArray['newsList'] = $newsGridArray;
  31.         if ($request->get('ajax')) {
  32.             $template $this->renderTemplate('news/partials/news-teaser-grid-result.html.twig'$returnArray);
  33.             return $this->json(['success' => true'html' => $template->getContent()], 200);
  34.         }
  35.         return $this->render('news/overview.html.twig'$returnArray);
  36.     }
  37.     public function micrositeOverviewAction(Request $requestNewsService $newsService): Response
  38.     {
  39.         return $this->render('news/microsite-overview.html.twig'$newsService->getNewsOverviewVars($request$this->document));
  40.     }
  41.     public function detailAction(Request $request): Response
  42.     {
  43.         $newsList = [];
  44.         $news News::getById($request->get('id'));
  45.         if ((!($news instanceof News) || !$news->isPublished()) && !$request->get('pimcore_object_preview')) {
  46.             throw new NotFoundHttpException('Requested object not found or not published!');
  47.         }
  48.         $newsCategories $news->getCategories();
  49.         if ($newsCategories) {
  50.             $categoryFilterCondition = [];
  51.             $newsList = new News\Listing();
  52.             foreach ($newsCategories as $newsCategory) {
  53.                 $categoryFilterCondition[] = 'FIND_IN_SET(' intval($newsCategory->getId()) . ', categories)';
  54.             }
  55.             $newsList->addConditionParam(implode(' OR '$categoryFilterCondition));
  56.         }
  57.         return $this->render('news/detail.html.twig', [ 'news' => $news'newsList' => $newsList]);
  58.     }
  59. }