src/WebBundle/Controller/HomeController.php line 56

Open in your IDE?
  1. <?php
  2. namespace WebBundle\Controller;
  3. use Exception;
  4. use FlexApp\DTO\RequestCatalogDTO;
  5. use FlexApp\Helper\MetaHelper;
  6. use Import1CBundle\Helper\v4\TranslitNameHelper;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use WebBundle\Helper\App;
  11. use WebBundle\Helper\CookieHelper;
  12. use WebBundle\Helper\LocaleHelper;
  13. use WebBundle\Helper\PathHelper;
  14. use WebBundle\Helper\RequestHelper;
  15. use WebBundle\Helper\UserHelper;
  16. use WebBundle\Repository\CollectionRepository;
  17. use WebBundle\Repository\FilterRepository;
  18. use WebBundle\Repository\IdeaRepository;
  19. use WebBundle\Repository\InteriorHistoryRepository;
  20. use WebBundle\Repository\PublicationRepository;
  21. use WebBundle\Service\PublicationService;
  22. use WebBundle\Service\SearchService;
  23. use WebBundle\Service\WidjetReviewService;
  24. class HomeController extends ExtendedController
  25. {
  26.     /** @required */
  27.     public PublicationService $publicationService;
  28.     /** @required */
  29.     public WidjetReviewService $widgetReviewService;
  30.     /** @required */
  31.     public FilterRepository $filterRepository;
  32.     /** @required */
  33.     public CollectionRepository $collectionRepository;
  34.     /** @required */
  35.     public PublicationRepository $publicationRepository;
  36.     /** @required */
  37.     public IdeaRepository $ideaRepository;
  38.     /** @required */
  39.     public InteriorHistoryRepository $interiorHistoryRepository;
  40.     public function rusAction(): Response
  41.     {
  42.         return $this->render('@Web/Home/rus.html.twig');
  43.     }
  44.     /**
  45.      * Главная страница.
  46.      *
  47.      * @return Response
  48.      * @throws Exception
  49.      */
  50.     public function mainAction(): Response
  51.     {
  52.         $publications $this->publicationService->page(116);
  53.         $metaManager MetaHelper::getManager();
  54.         $topCarousel $this->filterRepository->getItemsForTopCollectionCarouselMenu();
  55.         $title $metaManager->getTitle();
  56.         $title TranslitNameHelper::converTitle($title);
  57.         $output = [
  58.             'publications' => $publications,
  59.             'topCarousel' => $topCarousel,
  60.             'meta' => [
  61.                 'title' => $title,
  62.                 'description' => $metaManager->getDescription(),
  63.                 'keywords' => $metaManager->getKeywords(),
  64.             ],
  65.         ];
  66.         // отслеживаем посещения главной страницы
  67.         $visitCount CookieHelper::get('visitCount'0);
  68.         if ($visitCount 5) {
  69.             $output['isFirstFourVisit'] = true;
  70.             $visitCount++;
  71.             CookieHelper::set('visitCount'$visitCount);
  72.         }
  73.         $ides $this->collectionRepository->getCollectionIdes(11);
  74.         $collections $this->collectionRepository->getCollections(['ides' => $ides]);
  75.         $collection $collections[0] ?? null;
  76.         if ($collection) {
  77.             $urlFirstCollection PathHelper::pathGenerate('m-main'$collection);
  78.         } else {
  79.             $urlFirstCollection '';
  80.         }
  81.         // получаем ключ блога по образцам
  82.         $output['samples'] = $this->publicationRepository->getKey(2232App::getCurLocale());
  83.         $output['imagePreload'] = $urlFirstCollection;
  84.         return $this->render('@Web/Home/main.html.twig'$output);
  85.     }
  86.     /**
  87.      * Render carousel template
  88.      * @param string $type
  89.      * @param int $page
  90.      * @return Response
  91.      * @throws Exception
  92.      */
  93.     public function carouselAction(string $type 'last-collection'int $page 1)
  94.     {
  95.         $favorites $this->ideaRepository->getInteriorsIdeasByToken(UserHelper::getInstance()->getToken());
  96.         $limit 20;
  97.         if ($type == 'last-collection') {
  98.             $ides $this->collectionRepository->getCollectionIdes($page$limit);
  99.             $colls $this->collectionRepository->getCollections(['ides' => $ides]);
  100.             foreach ($colls as $i => $coll) {
  101.                 // получение данных по наградам
  102.                 if (isset($colls[$i]['awards'])) {
  103.                     $colls[$i]['awards'] = [];
  104.                 }
  105.                 if (!empty($coll['awards'])) {
  106.                     $aAwards $this->filterRepository->getAwards($coll['awards']);
  107.                     if ($aAwards) {
  108.                         $colls[$i]['awards'] = $aAwards;
  109.                     }
  110.                 }
  111.                 // проверяем наличие выставок и получаем по ним данные, если есть
  112.                 $exhibitions = [];
  113.                 // скрыл бирки выставок с карусели новинок сайта
  114. //                if (!empty($coll['exhibition'])) {
  115. //                    $exhibitions = $filterRepo->getExhibitions($coll['exhibition']);
  116. //                }
  117.                 $colls[$i]['exhibition'] = $exhibitions;
  118.                 $colls[$i]['priceSort'] = LocaleHelper::getPrMin($colls[$i]);
  119.                 $colls[$i]['priceSortCur'] = LocaleHelper::getCurrency();
  120.                 $colls[$i]['priceSortMea'] = LocaleHelper::getUserMeasure();
  121.             }
  122.             if ($page == 1) {
  123.                 $response $this->render(
  124.                     '@Web/Home/carousel-element.html.twig',
  125.                     [
  126.                         'type' => $type,
  127.                         'withDate' => 1,
  128.                         'collections' => $colls,
  129.                         'favourites' => $favorites,
  130.                     ]
  131.                 );
  132.             } else {
  133.                 $response = new JsonResponse([
  134.                         'html' => $this->render(
  135.                             '@Web/Home/carousel-items.html.twig',
  136.                             [
  137.                                 'withDate' => 1,
  138.                                 'collections' => $colls,
  139.                                 'favourites' => $favorites,
  140.                             ]
  141.                         )->getContent(),
  142.                     ]
  143.                 );
  144.             }
  145.         } else {
  146.             $colls = [];
  147.             CookieHelper::set('homeTopCarousel'$type);
  148.             if ($type == 'top-week') {
  149.                 $withDate 2;
  150.                 $collTop $this->interiorHistoryRepository->getCollections(7$page);
  151.                 CookieHelper::set('carousel''top-week');
  152.             } elseif ($type == 'top-month' || $type == 'top-20') {
  153.                 $withDate 2;
  154.                 $collTop $this->interiorHistoryRepository->getCollections(30$page);
  155.             } else {
  156.                 $withDate 3;
  157.                 $ides $this->collectionRepository->getCollectionIdes($page$limit'c.rating DESC, c.id');
  158.                 $colls $this->collectionRepository->getCollections(['ides' => $ides'order' => 'c.rating DESC, c.id']);
  159.             }
  160.             if (!empty($collTop)) {
  161.                 $collections $this->collectionRepository->getCollections(['ides' => array_keys($collTop), 'showMain' => true]);
  162.                 foreach ($collections as $row) {
  163.                     $colls[$collTop[$row['id']]['key']] = array_merge($row$collTop[$row['id']]);
  164.                 }
  165.                 ksort($colls);
  166.             }
  167.             // получение данных по наградам
  168.             foreach ($colls as $i => $coll) {
  169.                 if (isset($colls[$i]['awards'])) {
  170.                     $colls[$i]['awards'] = [];
  171.                 }
  172.                 if (!empty($coll['awards'])) {
  173.                     $aAwards $this->filterRepository->getAwards($coll['awards']);
  174.                     if ($aAwards) {
  175.                         $colls[$i]['awards'] = $aAwards;
  176.                     }
  177.                 }
  178.                 // проверяем наличие выставок и получаем по ним даныне, если есть
  179.                 $exhibitions = [];
  180.                 if (!empty($coll['exhibition'])) {
  181.                     $exhibitions $this->filterRepository->getExhibitions($coll['exhibition']);
  182.                 }
  183.                 $colls[$i]['exhibition'] = $exhibitions;
  184.                 $colls[$i]['priceSort'] = LocaleHelper::getPrMin($colls[$i]);
  185.                 $colls[$i]['priceSortCur'] = LocaleHelper::getCurrency();
  186.                 $colls[$i]['priceSortMea'] = LocaleHelper::getUserMeasure();
  187.             }
  188.             if ($page == && !RequestHelper::isAjax()) {
  189.                 $response $this->render(
  190.                     '@Web/Home/carousel-element.html.twig',
  191.                     [
  192.                         'type' => $type,
  193.                         'withDate' => $withDate,
  194.                         'collections' => $colls,
  195.                         'favourites' => $favorites,
  196.                     ]
  197.                 );
  198.             } else {
  199.                 $response = new JsonResponse([
  200.                         'html' => $this->render(
  201.                             '@Web/Home/carousel-items.html.twig',
  202.                             [
  203.                                 'type' => $type,
  204.                                 'withDate' => $withDate,
  205.                                 'collections' => $colls,
  206.                                 'favourites' => $favorites,
  207.                             ]
  208.                         )->getContent(),
  209.                     ]
  210.                 );
  211.             }
  212.         }
  213.         return $response;
  214.     }
  215.     public function setVarSessionAlertPopupAction(): JsonResponse
  216.     {
  217.         $session $this->get('session');
  218.         if (!$session->get('alert_popup')) {
  219.             $session->set('alert_popup''1');
  220.         }
  221.         return new JsonResponse($session->get('alert_popup'));
  222.     }
  223.     /**
  224.      * @param Request $request
  225.      * @return Response
  226.      * @throws Exception
  227.      */
  228.     public function reviewsAction(Request $request): Response
  229.     {
  230.         $reviews $this->widgetReviewService->getReviews($request);
  231.         $response $this->render('@Web/Home/reviews.html.twig', [
  232.             'reviews' => $reviews,
  233.         ]);
  234.         if (App::isGeneral()) {
  235.             $response->setCache([
  236.                 'max_age' => 300,
  237.                 's_maxage' => 300,
  238.                 'public' => true,
  239.             ]);
  240.         }
  241.         return $response;
  242.     }
  243. }