Deprecated: Symfony\Component\Translation\t(): Implicitly marking parameter $domain as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/translation/Resources/functions.php on line 18

Deprecated: Symfony\Component\Dotenv\Dotenv::loadEnv(): Implicitly marking parameter $envKey as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/dotenv/Dotenv.php on line 110

Deprecated: Symfony\Component\Runtime\GenericRuntime::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/GenericRuntime.php on line 89

Deprecated: Symfony\Component\Runtime\RuntimeInterface::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/RuntimeInterface.php on line 26

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $argv as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\Input::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/Input.php on line 36

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

src/Controller/NewsDefaultController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\News;
  4. use App\Annotation\CmsComponent;
  5. use App\Service\ServiceController;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. class NewsDefaultController extends AbstractController
  13. {
  14.     public function __construct(private readonly ServiceController $serviceController) {}
  15.     /**
  16.      * @CmsComponent("News Overview", active=true, routeName="embed_news_overview")
  17.      *
  18.      * @param mixed $request
  19.      */
  20.     #[Route(path'/test-news/overview'name'embed_news_overview')]
  21.     public function embedNewsOverview(EntityManagerInterface $emPaginatorInterface $paginatorRequest $request): Response
  22.     {
  23.         $perpage 10;
  24.         $now = new \DateTime();
  25.         if ($this->isGranted('ROLE_ADMIN')) {
  26.             $query $em->createQuery('SELECT e FROM App:News e WHERE e.deleted = 0 ORDER BY e.publishDate DESC');
  27.         } else {
  28.             $query $em->createQuery('SELECT e FROM App:News e WHERE e.deleted = 0 AND e.active = 1 AND e.publishDate <= :now ORDER BY e.publishDate DESC')
  29.                 ->setParameter('now'$now);
  30.         }
  31.         $featuredArticle $em->getRepository(News::class)->findOneBy(['deleted' => false'active' => true'featuredOnNewsPage' => true], ['publishDate' => 'DESC'], 10);
  32.         if ($featuredArticle) {
  33.             if ($this->isGranted('ROLE_ADMIN')) {
  34.                 $query $em->createQuery('SELECT e FROM App:News e WHERE e.deleted = 0 AND e.id != :id ORDER BY e.publishDate DESC')
  35.                     ->setParameter('id'$featuredArticle->getId());
  36.             } else {
  37.                 $query $em->createQuery('SELECT e FROM App:News e WHERE e.deleted = 0 AND e.active = 1 AND e.publishDate <= :now AND e.id != :id ORDER BY e.publishDate DESC')
  38.                     ->setParameter('now'$now)
  39.                     ->setParameter('id'$featuredArticle->getId());
  40.             }
  41.         }
  42.         $paginatedNews $paginator->paginate($query$request->query->getInt('page'1), $perpage);
  43.         return $this->render('@theme/news/embedNewsOverview.html.twig', [
  44.             'featuredArticle' => $featuredArticle,
  45.             'articles' => $paginatedNews,
  46.         ]);
  47.     }
  48.     /**
  49.      * @CmsComponent("News Article", slug="{news_slug}", slugEntity="News", active=true, routeName="embed_news_article")
  50.      *
  51.      * @param mixed $request
  52.      */
  53.     #[Route(path'/test-news/{news_slug}'name'embed_news_article')]
  54.     public function embedNewsArticle(EntityManagerInterface $emRequest $requestmixed $news_slug)
  55.     {
  56.         $prev $next null;
  57.         if ($this->isGranted('ROLE_ADMIN')) {
  58.             $news $em->getRepository(News::class)->findOneBy(['slug' => $news_slug'deleted' => false]);
  59.         } else {
  60.             $news $em->getRepository(News::class)->findOneBy(['slug' => $news_slug'deleted' => false'active' => true]);
  61.         }
  62.         if (!$news && $this->getParameter('multilingual')) {
  63.             $news $em->getRepository(News::class)->findSlugWithLocale($news_slug$request->getLocale());
  64.             if (!$news) {
  65.                 return $this->serviceController->componentRedirect('/news-not-found');
  66.             }
  67.         }
  68.         $now = new \DateTime();
  69.         if (!$news || $news->getPublishDate() > $now) {
  70.             if (!$this->isGranted('ROLE_ADMIN')) {
  71.                 return $this->serviceController->componentRedirect('/news-not-found');
  72.             }
  73.         }
  74.         $next $em->getRepository(News::class)->findNextPublished($news->getPublishDate());
  75.         $prev $em->getRepository(News::class)->findLastPublished($news->getPublishDate());
  76.         return $this->render('@theme/news/embedNewsArticle.html.twig', [
  77.             'news' => $news,
  78.             'prev' => $prev,
  79.             'next' => $next,
  80.         ]);
  81.     }
  82. }