src/Controller/Mvc/NewsController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Mvc;
  3. use App\Entity\Interfaces\Cms\LinkInterface;
  4. use App\Repository\News\CategoryRepository;
  5. use App\Service\Entity\News\EntryService;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. #[Route(path"/news")]
  11. class NewsController extends AbstractController
  12. {
  13.     #[Route(path"/"name"news_index"methods: ["GET"])]
  14.     public function index(
  15.         Request $request,
  16.         EntryService $service,
  17.         CategoryRepository $categoryRepository
  18.     ): Response
  19.     {
  20.         $service->setContainer($this->container);
  21.         $paginate $service->getPagination($request);
  22.         return $this->render('pages/news/index.html.twig', [
  23.             "paginate" => $paginate,
  24.             "categories" => $categoryRepository->getCategoriesHaveEntry()
  25.         ]);
  26.     }
  27.     #[Route(path"/{id}"name"news_detail"requirements: ["id" => "\d+"], methods: ["GET"])]
  28.     public function detail(
  29.         EntryService $entryService,
  30.         int          $id
  31.     ): Response
  32.     {
  33.         $entry $entryService->getEntryById($id);
  34.         if (!$entry) {
  35.             throw $this->createNotFoundException();
  36.         }
  37.         if (
  38.             in_array(LinkInterface::class, class_implements($entry), true) &&
  39.             $entry->getLinkUrl()
  40.         ) {
  41.             return $this->redirect($entry->getLinkUrl());
  42.         }
  43.         $beforeAfter $entryService->getBeforeAfter($entry);
  44.         return $this->render('pages/news/detail.html.twig', [
  45.             "entry" => $entry,
  46.             "before" => $beforeAfter['before'],
  47.             "after" => $beforeAfter['after']
  48.         ]);
  49.     }
  50.     #[Route(path'/headline'name"news_headline"methods: ["GET"])]
  51.     public function headline(
  52.         Request $request,
  53.         EntryService $service
  54.     ): Response
  55.     {
  56.         $service->setContainer($this->container);
  57.         $paginate $service->getPagination($request4);
  58.         return $this->render('pages/news/headline.html.twig', [
  59.             "paginate" => $paginate
  60.         ]);
  61.     }
  62. }