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/k/kasscaffolding/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/k/kasscaffolding/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/k/kasscaffolding/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/k/kasscaffolding/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/k/kasscaffolding/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/k/kasscaffolding/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/k/kasscaffolding/vendor/symfony/console/Input/Input.php on line 36

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

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

src/Controller/NewsDefaultController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Annotation\CmsComponent;
  4. use App\Entity\News;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class NewsDefaultController extends AbstractController
  12. {
  13.     /**
  14.      * @CmsComponent("All News Articles", active=true, routeName="embed_news_overview")
  15.      *
  16.      * @param mixed $request
  17.      */
  18.     #[Route(path'/test-news/overview'name'embed_news_overview')]
  19.     public function embedNewsOverview(EntityManagerInterface $emPaginatorInterface $paginatorRequest $request): Response
  20.     {
  21.         $perpage 9;
  22.         $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')->setParameter('now', new \DateTime());
  23.         $paginatedNews $paginator->paginate($query$request->query->getInt('page'1), $perpage);
  24.         return $this->render('@theme/news/embedNewsOverview.html.twig', [
  25.             'articles' => $paginatedNews,
  26.         ]);
  27.     }
  28.     /**
  29.      * @CmsComponent("Featured News Article", active=true, routeName="embed_news_featured")
  30.      *
  31.      * @param mixed $request
  32.      */
  33.     #[Route(path'/test-news/featured'name'embed_news_featured')]
  34.     public function embedFeaturedNewsArticle(EntityManagerInterface $emRequest $request): Response
  35.     {
  36.         $article $em->getRepository(News::class)->findLastestFeatured();
  37.         return $this->render('@theme/news/embedFeaturedNewsArticle.html.twig', [
  38.             'article' => $article,
  39.         ]);
  40.     }
  41.     /**
  42.      * @CmsComponent("Single News Article", slug="{news_slug}", slugEntity="News", active=true, routeName="embed_news_article")
  43.      *
  44.      * @param mixed $request
  45.      */
  46.     #[Route(path'/test-news/{news_slug}'name'embed_news_article')]
  47.     public function embedNewsArticle(EntityManagerInterface $emRequest $requestmixed $news_slug)
  48.     {
  49.         $prev $next null;
  50.         $news $em->getRepository(News::class)->findOneBy(['slug' => $news_slug'deleted' => false'active' => true]);
  51.         if (!$news && $this->getParameter('multilingual')) {
  52.             $news $em->getRepository(News::class)->findSlugWithLocale($news_slug$request->getLocale());
  53.             if (!$news) {
  54.                 return new Response('Not Found');
  55.             }
  56.         }
  57.         $now = new \DateTime();
  58.         if (!$news || $news->getPublishDate() > $now) {
  59.             return new Response('Not Found');
  60.         }
  61.         $next $em->getRepository(News::class)->findNextPublished($news->getPublishDate());
  62.         $prev $em->getRepository(News::class)->findLastPublished($news->getPublishDate());
  63.         return $this->render('@theme/news/embedNewsArticle.html.twig', [
  64.             'news' => $news,
  65.             'prev' => $prev,
  66.             'next' => $next,
  67.         ]);
  68.     }
  69. }