src/Controller/BusinessController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\BlogTag;
  4. use App\Helper\LastModifyHelper;
  5. use App\Repository\BlogPostRepository;
  6. use App\Repository\ReviewRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\KernelInterface;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class BusinessController extends AbstractController
  12. {
  13.     private const RESTAURANTS_TAGS = ['кейсы''horeca'];
  14.     private const RESTAURANTS_RETAIL = ['кейсы''ритейл'];
  15.     private LastModifyHelper $tracker;
  16.     public function __construct(KernelInterface $appKernel)
  17.     {
  18.         $this->tracker = new LastModifyHelper($appKernel);
  19.     }
  20.     /**
  21.      * @Route("/business/restaurants", name="business.restaurants.ru", methods={"GET"}, requirements={"_locale":"ru"})
  22.      */
  23.     public function restaurants(
  24.         ReviewRepository $reviewRepository,
  25.         BlogPostRepository $blogPostRepository
  26.     ): Response
  27.     {
  28.         $reviews $reviewRepository->findAllOrdered();
  29.         $query $blogPostRepository->publishedAndTagSelective(self::RESTAURANTS_TAGS10000);
  30.         $posts $query->getQuery()->getResult();
  31.         $countResult 3;
  32.         foreach($posts as $id => $post) {
  33.             if (!$countResult) {
  34.                 unset($posts[$id]);
  35.                 continue;
  36.             }
  37.             $tg = [];
  38.             /** @var BlogTag $tag */
  39.             foreach($post->getTags() as $tag) {
  40.                 $tg[] = $tag->getName();
  41.             }
  42.             if (count($tg) !== ||
  43.                 !in_array(current($tg), self::RESTAURANTS_TAGS) ||
  44.                 !in_array(end($tg), self::RESTAURANTS_TAGS)
  45.             ) {
  46.               unset($posts[$id]);
  47.             } else {
  48.                 $countResult--;
  49.             }
  50.         }
  51.         $template 'business/restaurants/index.html.twig';
  52.         $modified $this->tracker->get($template);
  53.         $response $this->render($template, [
  54.             'reviews' => $reviews,
  55.             'posts' => $posts,
  56.             'modified' => $modified
  57.         ]);
  58.         $response->headers->set('Last-Modified'$modified);
  59.         return $response;
  60.     }
  61.     /**
  62.      * @Route("/business/retail", name="business.retail.ru", methods={"GET"}, requirements={"_locale":"ru"})
  63.      */
  64.     public function retail(
  65.         ReviewRepository $reviewRepository,
  66.         BlogPostRepository $blogPostRepository
  67.     ): Response
  68.     {
  69.         $reviews $reviewRepository->findAllOrdered();
  70.         $query $blogPostRepository->publishedAndTagSelectiveself::RESTAURANTS_RETAIL10000);
  71.         $posts $query->getQuery()->getResult();
  72.         $countResult 3;
  73.         foreach($posts as $id => $post) {
  74.             if (!$countResult) {
  75.                 unset($posts[$id]);
  76.                 continue;
  77.             }
  78.             $tg = [];
  79.             /** @var BlogTag $tag */
  80.             foreach($post->getTags() as $tag) {
  81.                 $tg[] = $tag->getName();
  82.             }
  83.             if (count($tg) !== ||
  84.                 !in_array(current($tg), self::RESTAURANTS_RETAIL) ||
  85.                 !in_array(end($tg), self::RESTAURANTS_RETAIL)
  86.             ) {
  87.                 unset($posts[$id]);
  88.             } else {
  89.                 $countResult--;
  90.             }
  91.         }
  92.         $template 'business/retail/index.html.twig';
  93.         $modified $this->tracker->get($template);
  94.         $response $this->render($template, [
  95.             'reviews' => $reviews,
  96.             'posts' => $posts,
  97.             'modified' => $modified
  98.         ]);
  99.         $response->headers->set('Last-Modified'$modified);
  100.         return $response;
  101.     }
  102. }