src/Controller/DefaultController.php line 1424

Open in your IDE?
  1. <?php
  2. namespace Slivki\Controller;
  3. use Doctrine\ORM\Query;
  4. use Slivki\Dao\GiftCertificate\GiftCertificateDaoInterface;
  5. use Slivki\Dao\OfferCode\PurchaseCountWithCorrectionDaoInterface;
  6. use Slivki\Dao\TireFilter\TireFilterDaoInterface;
  7. use Slivki\Entity\AlternativeOffer;
  8. use Slivki\Entity\BankCurrency;
  9. use Slivki\Entity\Banner\MobileLandingBanner;
  10. use Slivki\Entity\Director;
  11. use Slivki\Entity\FoodOrder;
  12. use Slivki\Entity\GiftCertificate;
  13. use Slivki\Entity\MailingCampaign;
  14. use Slivki\Entity\SearchQuery;
  15. use Slivki\Entity\Seo;
  16. use Slivki\Enum\SwitcherFeatures;
  17. use Slivki\Repository\Comment\CommentRepositoryInterface;
  18. use Slivki\Services\CategoryBoxCacheService;
  19. use Slivki\Services\City\CityProvider;
  20. use Slivki\Services\Comment\CommentCacheService;
  21. use Slivki\Services\DeviceTypeService;
  22. use Slivki\Services\Offer\GalleryVideo\VideoPackageDtoGetter;
  23. use Slivki\Services\Sidebar\SidebarCacheService;
  24. use Slivki\Services\Subscription\SubscriptionService;
  25. use Slivki\Services\Switcher\ServerFeatureStateChecker;
  26. use Slivki\Util\Iiko\Dodo;
  27. use Slivki\Util\Iiko\Dominos;
  28. use Symfony\Component\HttpFoundation\Cookie;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use Slivki\Entity\Booking;
  31. use Slivki\Entity\Category;
  32. use Slivki\Entity\ChatSession;
  33. use Slivki\Entity\City;
  34. use Slivki\Entity\Comment;
  35. use Slivki\Entity\CommentLike;
  36. use Slivki\Entity\EntityOption;
  37. use Slivki\Entity\GeoLocation;
  38. use Slivki\Entity\HotFeed;
  39. use Slivki\Entity\InfoPage;
  40. use Slivki\Entity\MainMenu;
  41. use Slivki\Entity\Media;
  42. use Slivki\Entity\MediaType;
  43. use Slivki\Entity\Offer;
  44. use Slivki\Entity\OfferOrder;
  45. use Slivki\Entity\OfferProposal;
  46. use Slivki\Entity\ReadabilityStat;
  47. use Slivki\Entity\Sale;
  48. use Slivki\Entity\SearchStatistic;
  49. use Slivki\Entity\Subscriber;
  50. use Slivki\Entity\User;
  51. use Slivki\Entity\UserGroup;
  52. use Slivki\Repository\CityRepository;
  53. use Slivki\Repository\CommentRepository;
  54. use Slivki\Repository\OfferRepository;
  55. use Slivki\Repository\SaleRepository;
  56. use Slivki\Repository\SeoRepository;
  57. use Slivki\Services\BannerService;
  58. use Slivki\Services\CacheService;
  59. use Slivki\Services\Category\CategoryCacheService;
  60. use Slivki\Services\Mailer;
  61. use Slivki\Services\Offer\OfferCacheService;
  62. use Slivki\Services\Sale\SaleCacheService;
  63. use Slivki\Services\TextCacheService;
  64. use Slivki\Twig\SlivkiTwigExtension;
  65. use Slivki\Util\Amplitude;
  66. use Slivki\Util\CommonUtil;
  67. use Slivki\Util\Iiko\AbstractDelivery;
  68. use Slivki\Util\Iiko\SushiHouse;
  69. use Slivki\Services\ImageService;
  70. use Slivki\Util\Logger;
  71. use Slivki\Util\SoftCache;
  72. use Slivki\Util\CensureLibrary\Censure;
  73. use Symfony\Component\HttpFoundation\JsonResponse;
  74. use Symfony\Component\HttpFoundation\Request;
  75. use Symfony\Component\HttpFoundation\Response;
  76. use Symfony\Component\Filesystem\Filesystem;
  77. use Slivki\Entity\Visit;
  78. use Symfony\Component\HttpKernel\KernelInterface;
  79. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  80. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  81. use Symfony\Component\Validator\Constraints\Email;
  82. class DefaultController extends SiteController {
  83.     const OFFERS_PER_PAGE 24;
  84.     const LONG_CATEGORIES_PER_PAGE 36;
  85.     const SIDEBAR_CACHE_PATH '/slivki-cache/sidebar';
  86.     const CATEGORY_BOX_PATH '/slivki-cache/categorybox/';
  87.     const LONG_CATEGORIES = [
  88.         Category::TIRE_FITTING_CATEGORY_ID,
  89.         Category::LASER_EPILATION_CATEGORY_ID,
  90.     ];
  91.     private TireFilterDaoInterface $tireFilterDao;
  92.     public function __construct(
  93.         KernelInterface $kernel,
  94.         TireFilterDaoInterface $tireFilterDao
  95.     ) {
  96.         parent::__construct($kernel);
  97.         $this->tireFilterDao $tireFilterDao;
  98.     }
  99.     /**
  100.      * @Route("/", name="homepage")
  101.      */
  102.     public function indexAction(
  103.         Request $request,
  104.         BannerService $bannerService,
  105.         OfferCacheService $offerCacheService,
  106.         SaleCacheService $saleCacheService,
  107.         CategoryBoxCacheService $categoryBoxCacheService,
  108.         CategoryCacheService $categoryCacheService,
  109.         CommentRepositoryInterface $commentRepository
  110.     ) {
  111.         $isMobileDevice self::getMobileDevice($request);
  112.         if ($request->getHost() == 'm.slivki.by') {
  113.             return $this->render($isMobileDevice'Slivki/m/mobile/index.html.twig' 'Slivki/m/index.html.twig');
  114.         }
  115.         $cityID $request->getSession()->get(City::CITY_ID_SESSION_KEYCity::DEFAULT_CITY_ID);
  116.         $referrer $request->headers->get('referer''');
  117.         $response = new Response();
  118.         if (self::getMobileDevice($request)) {
  119.             $urlParsed parse_url($referrer);
  120.             $referrerHost = isset($urlParsed['host']) ? $urlParsed['host']: '';
  121.             if ($referrer != $request->getSchemeAndHttpHost() . '/landing' && $referrerHost != $request->getHost() && $cityID == City::DEFAULT_CITY_ID) {
  122.                 return $this->redirect('/landing');
  123.             }
  124.         }
  125.         $mainMenuItems $this->getDoctrine()->getManager()->getRepository(MainMenu::class)->getItemListCached(MainMenu::MENU_ID_MAIN$cityID);
  126.         $categoryBoxList = [];
  127.         $expanded count($mainMenuItems) == 1;
  128.         $i 0;
  129.         foreach ($mainMenuItems as $menuItem) {
  130.             $category $categoryCacheService->getCategory($menuItem->getEntityID());
  131.             $categoryBoxTarantool $categoryBoxCacheService->getCategoryBox(
  132.                 $menuItem->getEntityID(),
  133.                 CategoryBoxCacheService::SORT_BY_DEFAULT_COLUMN,
  134.                 $isMobileDevice,
  135.                 0,
  136.                 $category[8]
  137.             );
  138.             $categoryBox = \str_replace(
  139.                 '<!-- categoryTeasersPlaceholder -->',
  140.                 $categoryBoxTarantool['categoryBoxHtml'],
  141.                 $categoryBoxCacheService->getCategoryPage($menuItem->getEntityID(), false$isMobileDevice)
  142.             );
  143.             if ($categoryBox) {
  144.                 $categoryBoxList[$menuItem->getEntityID()] = $categoryBox;
  145.             }
  146.             if ($i == 0) {
  147.                 break;
  148.             }
  149.             $i++;
  150.         }
  151.         // getSidebarBanner
  152.         if (!$isMobileDevice) {
  153.             if ($this->getUser() && $this->getUser()->hasRole(UserGroup::ROLE_ADS_FREE)) {
  154.                 $data['sidebarBanner'] = '';
  155.             } else {
  156.                 $sidebarBannerCached $bannerService->getSidebarBannerCached($cityID);
  157.                 $data['sidebarBanner'] = $sidebarBannerCached['html'];
  158.             }
  159.             $data['lastComments'] = $commentRepository->getLastOfferComments(3);
  160.         }
  161.         $data['categoryBoxList'] = $categoryBoxList;
  162.         $data['salesList'] = $this->getSaleRepository()->getMainSales($cityIDself::getMobileDevice($request));
  163.         $data['mainPage'] = true;
  164.         $data['smallCity'] = $expanded;
  165.         $deviceType $isMobileDevice self::DEVICE_TYPE_MOBILE self::DEVICE_TYPE_DESKTOP;
  166.         $this->addVisit(0Visit::TYPE_MAIN_PAGE$deviceType$this->getUser(), $request->getClientIp(), $referrer);
  167.         $data['cityID'] = $cityID;
  168.         $request->attributes->set('mainPage'true);
  169.         $data['offerRateSchedule'] = $this->getOfferRateSchedule($request->getSession());
  170.         $mainHotFeed '';
  171.         $mainHotFeedEntities $this->getMainHotFeed($offerCacheService$saleCacheService200HotFeed::TYPE_MAIN_PAGE$cityID);
  172.         if (count($mainHotFeedEntities) > 4) {
  173.             foreach ($mainHotFeedEntities as $entity) {
  174.                 $mainHotFeed .= $this->renderView($isMobileDevice 'Slivki/mobile/hot_feed_teaser.html.twig'
  175.                     'Slivki/top_main_feed_teaser_mobile.html.twig',  $entity);
  176.             }
  177.         }
  178.         $data['mainHotFeed'] = $mainHotFeed;
  179.         $topLevelCategoryIDList = [];
  180.         foreach ($mainMenuItems as $menuItem) {
  181.             $topLevelCategoryIDList[] = $menuItem->getEntityID();
  182.         }
  183.         $data['topLevelCategoryIDList'] = $topLevelCategoryIDList;
  184.         $response->setContent($this->renderView($isMobileDevice 'Slivki/mobile/index.html.twig' 'Slivki/index.html.twig'$data));
  185.         return $response;
  186.     }
  187.     /** @Route("/auth") */
  188.     public function auth(Request $request) {
  189.         $path $request->query->get('path''/');
  190.         $response = new Response();
  191.         if ($this->getUser()) {
  192.             return $this->redirect($path);
  193.         }
  194.         return $this->render(CommonUtil::isMobileDevice($request) ? 'Slivki/mobile/auth.html.twig' 'Slivki/auth.html.twig');
  195.     }
  196.     /** @Route("/main_top_sales/{offset}") */
  197.     public function getMainOffsetSales(Request $request$offset) {
  198.         $cityID $request->getSession()->get(City::CITY_ID_SESSION_KEYCity::DEFAULT_CITY_ID);
  199.         $result = [];
  200.         $data['sale'] = $this->getSaleRepository()->getMainSales($cityIDself::getMobileDevice($request), $offset);
  201.         foreach ($data['sale'] as $sale) {
  202.             $result['result'][] = $this->renderView('Slivki/news/mobile_top_news.html.twig'$sale);
  203.         }
  204.         return new JsonResponse($result);
  205.     }
  206.     /** @Route("/main_hot_feed/{limit}/{offset}/{type}/{isNewMobileVersion}/{cityID}") */
  207.     public function getMainHotFeedAction(Request $requestSaleCacheService $saleCacheServiceOfferCacheService $offerCacheService$limit$offset$type$isNewMobileVersion$cityID) {
  208.         $result '';
  209.         foreach ($this->getMainHotFeed($offerCacheService$saleCacheService$limit$offset$type$cityID) as $entity) {
  210.             $result .= $this->renderView($isNewMobileVersion == 'true' ?  'Slivki/mobile/hot_feed_teaser.html.twig':
  211.                 'Slivki/top_main_feed_teaser_mobile.html.twig',  $entity);
  212.         }
  213.         return new Response($result);
  214.     }
  215.     public function categoryAction(
  216.         Request $request,
  217.         CategoryCacheService $categoryCacheService,
  218.         CategoryBoxCacheService $categoryBoxCacheService,
  219.         $entityID
  220.     ) {
  221.         return $this->tarantoolCategory($request$categoryCacheService$categoryBoxCacheService$entityID);
  222.     }
  223.     private function tarantoolCategory(
  224.         Request $request,
  225.         CategoryCacheService $categoryCacheService,
  226.         CategoryBoxCacheService $categoryBoxCacheService,
  227.         $entityID
  228.     ) {
  229.         $currentPage $request->query->get('page'1);
  230.         $isMobileDevice CommonUtil::isMobileDevice($request);
  231.         $deviceType $isMobileDevice self::DEVICE_TYPE_MOBILE self::DEVICE_TYPE_DESKTOP;
  232.         $this->addVisit(
  233.             $entityID,
  234.             Visit::TYPE_OFFER_CATEGORY,
  235.             $deviceType,
  236.             $this->getUser(),
  237.             $request->getClientIp(),
  238.             $request->headers->get('referer''')
  239.         );
  240.         $category $categoryCacheService->getCategory($entityID);
  241.         $response = new Response();
  242.         $perPage in_array($entityIDself::LONG_CATEGORIES) ? self::LONG_CATEGORIES_PER_PAGE self::OFFERS_PER_PAGE;
  243.         $categoryBox $categoryBoxCacheService->getCategoryBox(
  244.             $entityID,
  245.             CategoryBoxCacheService::SORT_BY_DEFAULT_COLUMN,
  246.             $isMobileDevice,
  247.             ($currentPage 1) * $perPage,
  248.             $perPage,
  249.         );
  250.         $categoryPageContent str_replace(
  251.             '<!-- categoryTeasersPlaceholder -->',
  252.             $categoryBox['categoryBoxHtml'],
  253.             $categoryBoxCacheService->getCategoryPage($entityIDtrue$isMobileDevice)
  254.         );
  255.         $paginationHtml $this->renderView('Slivki/pagination.html.twig', [
  256.             'paginationID' => 'categoryPagination',
  257.             'total' => ceil($categoryBox['totalTeaserCount'] / self::OFFERS_PER_PAGE),
  258.             'current' => $currentPage,
  259.             'url' => $request->getRequestUri() . '?page='
  260.         ]);
  261.         $categoryPageContent str_replace(
  262.             '<!-- categoryPaginationPlaceholder -->',
  263.             $paginationHtml,
  264.             $categoryPageContent
  265.         );
  266.         $tireFilterCategories $this->tireFilterDao->getCategoriesByParentCategory($entityID);
  267.         if (!== \count($tireFilterCategories)) {
  268.             $categoryPageContent = \str_replace(
  269.                 '<!-- tireFilerPlaceholder -->',
  270.                 $this->renderView('Slivki/tire/tire_filter.html.twig', [
  271.                     'categories' => $tireFilterCategories,
  272.                 ]),
  273.                 $categoryPageContent,
  274.             );
  275.         }
  276.         $data = [
  277.             'categoryID' => $entityID,
  278.             'category' => $categoryPageContent,
  279.             'brandingBannerCategoryIDs' => [$entityID]
  280.         ];
  281.         $response->setContent($this->renderView($isMobileDevice 'Slivki/mobile/offer/category.html.twig'
  282.             'Slivki/offers/category_page.html.twig'$data));
  283.         return $response;
  284.     }
  285.     public function categoryRatingAction(Request $requestTextCacheService $textCacheService$entityID) {
  286.         $isMobile CommonUtil::isMobileDevice($request);
  287.         $content $textCacheService->getText($entityID$isMobile TextCacheService::CATEGORY_COMPANIES_RATING_PAGE_MOBILE_TYPE TextCacheService::CATEGORY_COMPANIES_RATING_PAGE_TYPE);
  288.         if (!$content) {
  289.             throw $this->createNotFoundException();
  290.         }
  291.         return $this->render($isMobile 'Slivki/mobile/offer/category_rating_page.html.twig' 'Slivki/offers/category_rating_page.html.twig', [
  292.             'content' => $content,
  293.             'robotsMeta' => 'noindex, follow'
  294.         ]);
  295.     }
  296.     public function worstCategoryAction(
  297.         Request $request,
  298.         CategoryCacheService $categoryCacheService,
  299.         CategoryBoxCacheService $categoryBoxCacheService,
  300.         $entityID
  301.     ) {
  302.         return $this->tarantoolCategory($request$categoryCacheService$categoryBoxCacheService$entityID);
  303.     }
  304.     /** @Route("/category/load-more/{categoryID}/{pageNumber}/{sortBy}") */
  305.     public function categoryLoadMoreAction(
  306.         Request $request,
  307.         CategoryBoxCacheService $categoryBoxCacheService,
  308.         $categoryID,
  309.         $pageNumber,
  310.         $sortBy
  311.     ) {
  312.         return $this->categoryLoadMoreTarantool($request$categoryBoxCacheService$categoryID$pageNumber$sortBy);
  313.     }
  314.     private function categoryLoadMoreTarantool(
  315.         Request $request,
  316.         CategoryBoxCacheService $categoryBoxCacheService,
  317.         $categoryID,
  318.         $pageNumber,
  319.         $sortBy
  320.     ) {
  321.         $referer $request->headers->get('referer');
  322.         if (!$referer) {
  323.             return new Response('Referer is invalid or empty.');
  324.         }
  325.         $refererPathInfo Request::create($referer)->getPathInfo();
  326.         $isMobileDevice CommonUtil::isMobileDevice($request);
  327.         switch ($sortBy) {
  328.             case 'popularity':
  329.                 $sortByColumn CategoryBoxCacheService::SORT_BY_PURCHASE_COLUMN;
  330.                 break;
  331.             case 'visit':
  332.                 $sortByColumn CategoryBoxCacheService::SORT_BY_VISIT_COLUMN;
  333.                 break;
  334.             case 'distance':
  335.             case 'timetable':
  336.                 break;
  337.             case 'update-date':
  338.                 $sortByColumn CategoryBoxCacheService::SORT_BY_CREATED_ON_COLUMN;
  339.                 break;
  340.             case 'price-asc':
  341.                 $sortByColumn CategoryBoxCacheService::SORT_BY_PRICE_ASC_COLUMN;
  342.                 break;
  343.             case 'price-desc':
  344.                 $sortByColumn CategoryBoxCacheService::SORT_BY_PRICE_DESC_COLUMN;
  345.                 break;
  346.             default:
  347.                 $sortByColumn CategoryBoxCacheService::SORT_BY_DEFAULT_COLUMN;
  348.         }
  349.         $perPage in_array($categoryIDself::LONG_CATEGORIES) ? self::LONG_CATEGORIES_PER_PAGE self::OFFERS_PER_PAGE;
  350.         if ($sortBy == 'distance') {
  351.             $categoryBox $categoryBoxCacheService->getCategoryBoxSortedByLocation(
  352.                 $categoryID,
  353.                 $request->cookies->get(User::CURRENT_LOCATION_COOKIEGeoLocation::DEFAULT_LOCATION),
  354.                 $isMobileDevice,
  355.                 ($pageNumber 1) * $perPage,
  356.                 $perPage,
  357.             );
  358.         } elseif ($sortBy == 'timetable') {
  359.             $categoryBox $categoryBoxCacheService->getCategoryBoxSortedByTimetable(
  360.                 $categoryID,
  361.                 $isMobileDevice,
  362.                 ($pageNumber 1) * $perPage,
  363.                 $perPage,
  364.             );
  365.         } else {
  366.             $categoryBox $categoryBoxCacheService->getCategoryBox(
  367.                 $categoryID,
  368.                 $sortByColumn,
  369.                 $isMobileDevice,
  370.                 ($pageNumber 1) * $perPage,
  371.                 $perPage,
  372.             );
  373.         }
  374.         return new JsonResponse([
  375.             'teasers' => $categoryBox['categoryBoxHtml'],
  376.             'pagination' => $this->renderView('Slivki/pagination.html.twig', [
  377.                 'paginationID' => 'categoryPagination',
  378.                 'total' => ceil($categoryBox['totalTeaserCount'] / self::OFFERS_PER_PAGE),
  379.                 'current' => $pageNumber,
  380.                 'url' => $refererPathInfo '?page='
  381.             ])
  382.         ]);
  383.     }
  384.     /**
  385.      * @Route("/categoryBoxNotExpanded/{categoryID}")
  386.      */
  387.     public function categoryBoxNotExpandedAction(
  388.         Request $request,
  389.         CategoryBoxCacheService $categoryBoxCacheService,
  390.         CategoryCacheService $categoryCacheService,
  391.         $categoryID
  392.     ) {
  393.         $isMobileDevice CommonUtil::isMobileDevice($request);
  394.         $category $categoryCacheService->getCategory($categoryID);
  395.         $categoryBoxTarantool $categoryBoxCacheService->getCategoryBox(
  396.             $categoryID,
  397.             CategoryBoxCacheService::SORT_BY_DEFAULT_COLUMN,
  398.             $isMobileDevice,
  399.             0,
  400.             $category[8]
  401.         );
  402.         $categoryBox = \str_replace(
  403.             '<!-- categoryTeasersPlaceholder -->',
  404.             $categoryBoxTarantool['categoryBoxHtml'],
  405.             $categoryBoxCacheService->getCategoryPage($categoryIDfalse$isMobileDevice)
  406.         );
  407.         return new Response($categoryBox);
  408.     }
  409.     /**
  410.      * @Route("/moreOffers")
  411.      */
  412.     public function moreOffers(Request $request) {
  413.         $categoryID = (int)$request->query->get("categoryID"0);
  414.         $data['categoryBoxID'] = $request->query->get("categoryBoxId"0);
  415.         $moreCount = (int)$request->query->get("moreCount"150);
  416.         $position = (int)$request->query->get("position"0);
  417.         $category $this->getCategoryRepository()->findCached($categoryID)['category'];
  418.         if (!$category) {
  419.             return new Response();
  420.         }
  421.         $offerIDList = [];
  422.         $sql "select entity_id from offer_category_position where category_id = $categoryID order by position offset $position limit $moreCount + 1";
  423.         $offersByPosition $this->getDoctrine()->getManager()->getConnection()->executeQuery($sql)->fetchAll(Query::HYDRATE_ARRAY);
  424.         $i 0;
  425.         foreach ($offersByPosition as $offerPosition) {
  426.             if ($i>=$moreCount) {
  427.                 break;
  428.             }
  429.             $offerIDList[] = $offerPosition['entity_id'];
  430.             $i++;
  431.         }
  432.         $softCache = new SoftCache(OfferRepository::CACHE_NAME);
  433.         $offerListCached $softCache->getMulti($offerIDList);
  434.         if(!$offerListCached) {
  435.             return new Response('');
  436.         }
  437.         $moreOfferList = [];
  438.         foreach ($offerListCached as $offer) {
  439.             $moreOfferList[] = $offer;
  440.         }
  441.         $data['position'] = $position $moreCount;
  442.         $data['expanded'] = !count($offersByPosition) > count($offerIDList);
  443.         $data['showCollapse'] = true;
  444.         $data['isMailing'] = false;
  445.         $teaserBanners $this->getOfferRepository()->getTeaserBanners($category);
  446.         $data['teaserBanners'] = $teaserBanners['teaserBanners'];
  447.         $data['absolutePosition'] = $position 1;
  448.         $data['withVerticalBannersRowList'] = $teaserBanners['withVerticalBannersRowList'];
  449.         $data['category'] = $category;
  450.         $data['offerList'] = $moreOfferList;
  451.         $response $this->render("Slivki/offers/teasers.html.twig"$data);
  452.         return $response;
  453.     }
  454.     public function detailsAction(
  455.         Request $request,
  456.         BannerService $bannerService,
  457.         OfferCacheService $offerCacheService,
  458.         CacheService $cacheService,
  459.         $entityID,
  460.         ImageService $imageService,
  461.         SubscriptionService $subscriptionService,
  462.         GiftCertificateDaoInterface $giftCertificateDao,
  463.         ServerFeatureStateChecker $serverFeatureStateChecker,
  464.         VideoPackageDtoGetter $videoPackageDtoGetter,
  465.         CityProvider $cityProvider,
  466.         PurchaseCountWithCorrectionDaoInterface $purchaseCountWithCorrectionDao
  467.     ) {
  468.         ini_set('memory_limit''10g');
  469.         $data['currentPage'] = $request->query->getInt('page'1);
  470.         $this->get('session')->set('userCommentImages', []);
  471.         $entityManager $this->getDoctrine()->getManager();
  472.         $offerRepository $this->getOfferRepository();
  473.         $offer $offerCacheService->getOffer($entityIDfalsetrue);
  474.         if ($offer instanceof Offer && $offer->getDefaultCityId() === City::TASHKENT_CITY_ID && $cityProvider->getDefaultCityId() !== City::TASHKENT_CITY_ID) {
  475.             return $this->redirect('https://www.slivki.uz' $request->getRequestUri(), Response::HTTP_MOVED_PERMANENTLY);
  476.         }
  477.         $dreamLangPartner $request->getSession()->get(EntityOption::OPTION_DREAMLAND_PARTNER);
  478.         if ($this->getUser() && $dreamLangPartner && !$entityManager->getRepository(User::class)->getDreamlandOption($this->getUser()->getID())) {
  479.             $option = new EntityOption();
  480.             $option->setEntityTypeID(EntityOption::USER_TYPE);
  481.             $option->setEntityID($this->getUser()->getID());
  482.             $option->setName(EntityOption::OPTION_DREAMLAND_PARTNER);
  483.             $option->setValue($dreamLangPartner);
  484.             $entityManager->persist($option);
  485.             $entityManager->flush();
  486.             $request->getSession()->remove(EntityOption::OPTION_DREAMLAND_PARTNER);
  487.         }
  488.         $pastOffer false;
  489.         $timeNow = new \DateTime();
  490.         $preview $request->query->get("preview"false);
  491.         if (!$offer || $preview) {
  492.             $offer $offerRepository->find($entityID);
  493.             if (!$offer || ((!$offer->isInVisiblePeriod() || !$offer->isActive()) && !$preview)) {
  494.                 throw $this->createNotFoundException();
  495.             }
  496.             if ((!$offer->isActive() || $offer->getActiveTill() < $timeNow || $offer->getActiveSince() > $timeNow) && !$preview) {
  497.                 $pastOffer true;
  498.             }
  499.             if ($preview || $pastOffer) {
  500.                 $mediaRepository $this->getMediaRepository();
  501.                 $offer->setDetailMeidas($mediaRepository->getOfferDetailMedias($offer->getID()));
  502.                 $offer->setShopMedias($mediaRepository->getOfferShopMedias($offer->getID()));
  503.             } else {
  504.                 Logger::instance('CACHE DEBUG')->info('Offer ' $entityID ' is not found in cache');
  505.                 $offer $offerCacheService->reloadOfferCache($entityID);
  506.             }
  507.         }
  508.         if ((!$offer->isActive() || $offer->getActiveTill() < $timeNow || $offer->getActiveSince() > $timeNow) && !$preview) {
  509.             $pastOffer true;
  510.         }
  511.         if ($entityID == 131841 && ($pastOffer || $offer->isHidden())) { // issue #2688
  512.             return $this->redirect($this->getSeoRepository()->getByEntity(SeoRepository::RESOURCE_URL_OFFER_CATEGORY509)->getMainAlias());
  513.         }
  514.         if ($offer->isHidden()) {
  515.             throw $this->createNotFoundException();
  516.         }
  517.         $response = new Response();
  518.         $offerRateSchedule $this->getOfferRateSchedule($request->getSession());
  519.         if ($offerRateSchedule) {
  520.             if ($offerRateSchedule->getOffer()->getID() == $entityID) {
  521.                 $request->getSession()->set(SiteController::LAST_OFFER_RATE_ACTIVITY_PARAMETER_NAMEtime());
  522.                 $sql 'delete from offer_rate_schedule where user_id = ' . (int)$this->getUser()->getID() . ' and offer_id = ' . (int)$entityID;
  523.                 $entityManager->getConnection()->executeQuery($sql);
  524.             } else {
  525.                 $data['offerRateSchedule'] = $offerRateSchedule;
  526.             }
  527.         }
  528.         $data['pastOffer'] = $pastOffer;
  529.         $data['todayPurchaseCount'] = $purchaseCountWithCorrectionDao->findLastDayByOfferId($offer->getID());
  530.         if (!$pastOffer && $offer->getFreeCodesCount() > 0) {
  531.             $lastPurchaseTime $offerRepository->getLastPurchaseTime($offer->getID());
  532.             if ($lastPurchaseTime) {
  533.                 $now = new \DateTime();
  534.                 $lastPurchaseInterval $now->diff($lastPurchaseTime);
  535.                 $lastPurchaseText '';
  536.                 if ($lastPurchaseInterval->0) {
  537.                     $lastPurchaseText $lastPurchaseInterval->' час' CommonUtil::plural(['''а''ов'], $lastPurchaseInterval->h) . ' ';
  538.                 }
  539.                 $lastPurchaseMinutes $lastPurchaseInterval->== && $lastPurchaseInterval->$lastPurchaseInterval->i;
  540.                 $lastPurchaseText .= $lastPurchaseMinutes ' минут' CommonUtil::plural(['у''ы'''], $lastPurchaseMinutes) . ' назад';
  541.                 $data['lastPurchaseText'] = $lastPurchaseText;
  542.             }
  543.         } elseif (!self::getMobileDevice($request)) {
  544.             $data['relatedOfferListHtml'] = implode(''$this->getRelatedOffersTeasers($cacheService$offer));
  545.         }
  546.         $data['offer'] = $offer;
  547.         $data['galleryVideos'] = $videoPackageDtoGetter->getByOfferId($offer->getID());
  548.         $userGeoLocation $request->cookies->get(User::CURRENT_LOCATION_COOKIEnull);
  549.         if ($userGeoLocation) {
  550.             $userGeoLocation explode(','$userGeoLocation);
  551.         }
  552.         $data['offerGeoLocationData'] = $offerRepository->getOfferGeoLocationData($offer$userGeoLocation$imageService);
  553.         $data['freeCodesCount'] = 0;
  554.         $buyCodePopup "";
  555.         /** @var User $user */
  556.         $user $this->getUser();
  557.         $data['offerIsFreeForUser'] = $offerRepository->isOfferFreeForUser($offer$user);
  558.         $codeCost $offerRepository->getCodeCost($offer);
  559.         if (!$pastOffer) {
  560.             if ($user && !$subscriptionService->isSubscriber($user) && !$data['offerIsFreeForUser']) {
  561.                 $data['testSubscriptionGroupID'] = true;
  562.             }
  563.             $data['canBuyFromBalance'] = false;
  564.             $data['freeCodesCount'] = $offer->getFreeCodesCount();
  565.             if ($offer->getID() != Offer::DREAMLAND_OFFER_ID) {
  566.                 if (!$user) {
  567.                     $buyCodePopup ".modal-auth";
  568.                 } else {
  569.                     if ($user->getFullBalance() >= $codeCost || $data['offerIsFreeForUser']) {
  570.                         $buyCodePopup "#confirmBox";
  571.                         $data['canBuyFromBalance'] = true;
  572.                     }
  573.                     if (isset($data['testSubscriptionGroupID'])) {
  574.                         $buyCodePopup "#confirmBox";
  575.                     }
  576.                 }
  577.             }
  578.         }
  579.         if (!$serverFeatureStateChecker->isServerFeatureEnabled(SwitcherFeatures::REPLENISHMENT_BALANCE())) {
  580.             $buyCodePopup "#confirmBox";
  581.             $data['canBuyFromBalance'] = false;
  582.         }
  583.         if ($user) {
  584.             $subscription $subscriptionService->getSubscription($user);
  585.             $data['allowedCodesCountBySubscription'] = $subscriptionService->isSubscriber($user)
  586.                 ? $subscription->getNumberOfCodes()
  587.                 : 0;
  588.         }
  589.         $buyButtonLabel 'Получить скидку ';
  590.         if ($data['offer']->isOneOfOnlineOrderAllowedOnSite()) {
  591.             $buyButtonLabel 'Получить промокод ';
  592.         }
  593.         if ($data['offerIsFreeForUser']) {
  594.             $buyButtonLabel 'Бесплатный промокод';
  595.         } else {
  596.             if ($offer->isActiveCurrencyCalculator() && is_numeric($offer->getDiscount())) {
  597.                 $bankCurrency $entityManager->getRepository(BankCurrency::class)->findOneBy(['currency' => $offer->getBankCurrency()->getCurrency()]);
  598.                 if ($bankCurrency) {
  599.                     $buyButtonLabel .= round($bankCurrency->getRate() * $offer->getDiscount(), 2);
  600.                 }
  601.             } else {
  602.                 $buyButtonLabel .= $offer->getDiscount();
  603.             }
  604.             $buyButtonLabel mb_strtoupper($buyButtonLabel);
  605.         }
  606.         if ($entityID == Offer::DREAMLAND_OFFER_ID) {
  607.             $buyButtonLabel 'Купить билет от ' $offer->getOfferPrice($offer)  . ' руб.';
  608.         }
  609.         $isMobile CommonUtil::isMobileDevice($request);
  610.         $commentsCacheName $isMobile CommentCacheService::MOBILE_CACHE_NAME CommentCacheService::CACHE_NAME;
  611.         if ($data['currentPage'] == 1) {
  612.             $comments $this->getComments($request$bannerService$entityIDComment::TYPE_OFFER_COMMENT000$commentsCacheName);
  613.         } else {
  614.             $comments $this->getCommentsByOffer($entityID$data['currentPage'], CommentRepository::COMMENTS_PER_PAGE$isMobile);
  615.         }
  616.         $commentsAmount $this->getCommentRepository()->getCommentsCountByEntityID($entityIDComment::TYPE_OFFER_COMMENT);
  617.         $data['comments'] = $this->renderView($isMobile 'Slivki/mobile/comment/block.html.twig' 'Slivki/comments/comments_list.html.twig', [
  618.             'entityID' => $entityID,
  619.             'type' => Comment::TYPE_OFFER_COMMENT,
  620.             'comments' => $comments,
  621.             'commentsAmount' => $commentsAmount,
  622.             'showCommentsAmount' => true,
  623.             'rating' => $offer->getRating(),
  624.         ]);
  625.         $data['items'] = []; //$offer->getItems();
  626.         $dataItemsCount count($data['items']);
  627.         if ($dataItemsCount 0) {
  628.             $minOfferPrice INF;
  629.             foreach ($data['items'] as $item) {
  630.                 if ($item->getOfferPrice() < $minOfferPrice) {
  631.                     $minOfferPrice $item->getOfferPrice();
  632.                 }
  633.             }
  634.             $buyButtonLabel 'Купить билет от ' number_format($minOfferPrice,2',''') . ' руб.';
  635.         }
  636.         $buyCodeBtnText $offer->getBuyCodeButtonText();
  637.         $buyCodeBtnText $buyCodeBtnText $buyCodeBtnText '';
  638.         $data['buyButtonLabel'] = $buyCodeBtnText == '' mb_strtoupper(mb_substr($buyButtonLabel01)) . mb_strtolower(mb_substr($buyButtonLabel1)) : $buyCodeBtnText;
  639.         if ($offer->isOneOfOnlineOrderAllowedOnSite()) {
  640.             $data['buyButtonLabelOnline'] = $offer->isBuyCodeDisable() ? 'Оформить сертификат онлайн' 'Заказать онлайн';
  641.         }
  642.         $data['isAllowedByOnlyCode'] =  $dataItemsCount == || ($dataItemsCount && $offer->isAllowedBuyOnlyCode());
  643.         $data['showGlobalcard'] = false;
  644.         $data['showGlobalcardFitness'] = false;
  645.         $data['tour3dName'] = '';
  646.         $softCache = new SoftCache(OfferRepository::CACHE_NAME);
  647.         $cacheKey 'alt-offers-box-' $entityID;
  648.         $altOffersBox $softCache->get($cacheKey);
  649.         if ($altOffersBox == SoftCache::LOCKED_KEY) {
  650.             $altOffersBox $softCache->getDataForLockedKey($cacheKey30);
  651.         } else if (!$altOffersBox) {
  652.             $softCache->add($cacheKeySoftCache::LOCKED_KEY30);
  653.             $cacheExpire strtotime(date('Y-m-d 05:00:00'strtotime('+1 day'))) - time();
  654.             $altOffersBox "";
  655.             $altOfferList $this->getDoctrine()->getRepository(AlternativeOffer::class)->getByOfferID($entityID);
  656.             if ($altOfferList) {
  657.                 if (count($altOfferList) < 3) {
  658.                     $altOffersBox SoftCache::EMPTY_VALUE;
  659.                 } else {
  660.                     if (count($altOfferList) < 6) {
  661.                         $altOfferList array_slice($altOfferList03);
  662.                     }
  663.                     foreach ($altOfferList as $altOffer) {
  664.                         $alternativeOffer $offerCacheService->getOffer($altOffer->getAlternativeOfferID(), true);
  665.                         if ($alternativeOffer) {
  666.                             $altOffersBox .= $this->get('twig')->render('Slivki/offers/teaser.html.twig', ['offer' => $alternativeOffer'noLazyLoad' => true]);
  667.                         } else {
  668.                             $this->getLogger()->error('Alternative offer ' $altOffer->getOfferID() . " not found in cache");
  669.                             $altOffersBox "";
  670.                             break;
  671.                         }
  672.                     }
  673.                 }
  674.             }
  675.             $softCache->set($cacheKey$altOffersBox$cacheExpire);
  676.             if ($altOffersBox == SoftCache::EMPTY_VALUE) {
  677.                 $altOffersBox "";
  678.             }
  679.         }
  680.         if ($user && $subscriptionService->isSubscriber($user)) {
  681.             $buyCodePopup '#confirmBox';
  682.         }
  683.         $data['altOffersBox'] = $altOffersBox;
  684.         $data['geoLocations'] = $offer->getGeoLocations();
  685.         $data['codeCost'] = $codeCost;
  686.         $data['buyCodePopup'] = $buyCodePopup;
  687.         $data['siteSettings'] = $this->getSiteSettings();
  688.         $data['parentCategoryList'] = $this->getParentCategoryList($request$offer->getDefaultCategoryID());
  689.         $data['categoryURL'] = '/';
  690.         $data['preview'] = $preview;
  691.         $data['commentsAmount'] = $this->getCommentRepository()->getCommentsCountByEntityID($offer->getID(), Comment::TYPE_OFFER_COMMENT);
  692.         $data['isOfferFavourite'] = $user $user->isOfferFavourite($offer) : false;
  693.         $data['detailMediaList'] = $offer->getDetailMedias();
  694.         $data['foodExtensions'] = $offer->getFoodExtensions();
  695.         $categoryRepository =  $this->getDoctrine()->getManager()->getRepository(Category::class);
  696.         $categoryID $offer->getDefaultCategoryID();
  697.         if ($categoryID) {
  698.             $category $categoryRepository->findCached($categoryID);
  699.             if (!$category) {
  700.                 $category['category'] = $categoryRepository->find($categoryID);
  701.             }
  702.             if ($category['category'] && $category['category']->isActive() && !$category['category']->isPast()) {
  703.                 $data['categoryURL'] = $this->getSeoRepository()->getCategoryURL($category['category']);
  704.             }
  705.         }
  706.         $deviceType self::getMobileDevice($request) ? self::DEVICE_TYPE_MOBILE self::DEVICE_TYPE_DESKTOP;
  707.         $this->addVisit($entityIDVisit::TYPE_OFFER$deviceType$user$request->getClientIp());
  708.         if ($entityID == Offer::FITNESS_WORLD_OFFER_ID) {
  709.             $data['fitnessOffer'] = true;
  710.         }
  711.         $data['confirmedUserPhoneNumber'] = null;
  712.         $dateDiff date_diff($offer->getActiveTill(), new \DateTime());
  713.         $data['daysLeft'] = $dateDiff->days;
  714.         $data['hoursLeft'] = $dateDiff->format('%h');
  715.         $data['minutesLeft'] = $dateDiff->format('%i');
  716.         $data['usedCodesCount'] = $pastOffer
  717.             $offer->getUsedCodesCountForPastOffer()
  718.             : $purchaseCountWithCorrectionDao->findTotalByOfferId($offer->getID());
  719.         $data['allCodesCount'] = $data['usedCodesCount'] + $offer->getFreeCodesCount();
  720.         $data['ratingWithCount'] = $entityManager->getRepository(Comment::class)->getEntityRatingWithCount(Category::OFFER_CATEGORY_ID$entityID);
  721.         $data['ratingPercentage'] = $data['ratingWithCount']['rating'] * 100 5;
  722.         $data['todayVisitCount'] = $offerRepository->getVisitCount($offertrue);
  723.         $data['visitCount'] = $entityManager->getRepository(Visit::class)->getVisitCount($entityIDVisit::TYPE_OFFER30true);
  724.         $data['phoneNumbersCount'] = count($offer->getPhoneNumbers());
  725.         if ($entityID == Offer::BOOKING_OFFER_ID) {
  726.             $entityOption $entityManager->getRepository(EntityOption::class)->findOneBy([
  727.                 "entityID" => $entityID,
  728.                 "entityTypeID" => EntityOption::BOOKING_RESERVED_DATES,
  729.                 "name" => EntityOption::OPTION_BOOKING_DATES
  730.             ]);
  731.             if ($entityOption) {
  732.                 $dateToFormat = [];
  733.                 foreach (explode(','$entityOption->getValue()) as $date) {
  734.                     $dateToFormat[] = date('Y-m-d'strtotime($date));
  735.                 }
  736.                 $data['bookedDates'] = implode(','$dateToFormat);
  737.             }
  738.             $data['bookingTypeList'] = Booking::BOOKING_TYPE_LIST;
  739.             $userCurrentPhone =  $user $user->getCurrentPhone() : null;
  740.             if ($userCurrentPhone and $userCurrentPhone->isConfirmed()) {
  741.                 $data['confirmedUserPhoneNumber'] = $userCurrentPhone->getPhoneNumber();
  742.             }
  743.         }
  744.         if ($user && $user->hasRole(UserGroup::STATISTICS_VIEWER)) {
  745.             $data['yesterdayShareClicks'] = $this->getShareClicks($entityID);
  746.         }
  747.         $utmMedium trim(mb_strtolower($request->query->get('utm_medium''')));
  748.         if ($request->query->get('utm_source') == 'search_result' && $utmMedium != '') {
  749.             $searchQuery $entityManager->getRepository(SearchQuery::class)
  750.                 ->findOneByQuery(($utmMedium));
  751.             if ($searchQuery) {
  752.                 $searchStatistic = new SearchStatistic();
  753.                 $searchStatistic->setSearchQuery($searchQuery);
  754.                 $searchStatistic->setEntityID($offer->getID());
  755.                 $searchStatistic->setEntityType(SearchStatistic::ENTITY_TYPE_OFFER);
  756.                 if ($user) {
  757.                     $searchStatistic->setUserID($user->getID());
  758.                 }
  759.                 $searchStatistic->setIpAddress($request->getClientIp());
  760.                 $searchStatistic->setRefferer($request->headers->get('referer'));
  761.                 $entityManager->persist($searchStatistic);
  762.                 $entityManager->flush();
  763.             }
  764.         }
  765.         $codesCount 1;
  766.         if ($entityID == Offer::DREAMLAND_OFFER_ID) {
  767.             $codesCount 5;
  768.             if ($user) {
  769.                 if ($entityManager->getRepository(User::class)->getDreamlandOption($user->getID())) {
  770.                     $codesCount 1;
  771.                 }
  772.             }
  773.         }
  774.         $data['codesCount'] = $codesCount;
  775.         $data['brandingBannerCategoryIDs'] = $categoryRepository->getParentCategoryIDsByOfferID($entityID);
  776.         $data['deliveryLink'] = '/delivery/select/' $offer->getID();
  777.         $onlineSettings $offer->getOnlineOrderSettings();
  778.         if (!$pastOffer && $offer->isOneOfOnlineOrderAllowedOnSite()) {
  779.             $data['hasDelivery'] = true;
  780.             $data['foodExtensions'] = [];
  781.             $data['items'] = [];
  782.             if (count($offer->getFoodExtensions())) {
  783.                 $orderUtil AbstractDelivery::instance($offer);
  784.                 if ($orderUtil::SPLIT_PAYMENT) {
  785.                     $data['domain'] = $orderUtil::DOMAIN;
  786.                 }
  787.                 if ($onlineSettings && $onlineSettings->isSplitPayment()) {
  788.                     if ($onlineSettings->getDomain()) {
  789.                         $data['domain'] = trim($onlineSettings->getDomain());
  790.                     }
  791.                 }
  792.             } elseif ($giftCertificateDao->getCountActiveByOfferId($entityID)) {
  793.                 $dql 'select giftCertificate from Slivki:GiftCertificate giftCertificate where giftCertificate.offer = :offer';
  794.                 $giftCertificates $entityManager->createQuery($dql)
  795.                     ->setParameter('offer'$offer)->getResult();
  796.                 if ($giftCertificates[0]->getLastActiveCodePool()) {
  797.                     $multiplePoolOfferFreeCodesCount 0;
  798.                     $multiplePoolOfferUsedCodesCount 0;
  799.                     /** @var GiftCertificate $giftCertificate */
  800.                     foreach ($giftCertificates as $giftCertificate) {
  801.                         $giftCertificateCodePool $giftCertificate->getLastActiveCodePool();
  802.                         $multiplePoolOfferFreeCodesCount += $giftCertificateCodePool->getFreeCodesCount();
  803.                         $multiplePoolOfferUsedCodesCount += $giftCertificateCodePool->getUsedCodesCount();
  804.                     }
  805.                     $data['multiplePoolOfferFreeCodesCount'] = $multiplePoolOfferFreeCodesCount;
  806.                     $data['multiplePoolOfferUsedCodesCount'] = $multiplePoolOfferUsedCodesCount;
  807.                 }
  808.                 $data['deliveryLink'] = '/gift-certificate/select/' $offer->getID();
  809.                 if ($onlineSettings && $onlineSettings->isSplitPayment()) {
  810.                     if ($onlineSettings->getDomain()) {
  811.                         $data['domain'] = trim($onlineSettings->getDomain());
  812.                     }
  813.                 }
  814.             } else {
  815.                 $offer $entityManager->merge($offer);
  816.                 if (count($offer->getTireExtensions())) {
  817.                     $data['deliveryLink'] = '/online-zapis/' $offer->getID();
  818.                     if ($onlineSettings && $onlineSettings->isSplitPayment()) {
  819.                         if ($onlineSettings->getDomain()) {
  820.                             $data['domain'] = trim($onlineSettings->getDomain());
  821.                         }
  822.                     }
  823.                 }
  824.             }
  825.             $directorID $offer->getDirectorID();
  826.             if ($offer->getID() == Offer::DREAMLAND_OFFER_ID) {
  827.                 $data['domain'] = 'mp';
  828.             } else if ($entityID == 139498) {
  829.                 $data['domain'] = 'deka';
  830.             } else if ($entityID == 141075) {
  831.                 $data['domain'] = 'whitelotus';
  832.             } else if ($directorID == Director::MARSEL_DIRECTOR_ID) {
  833.                 $data['domain'] = 'marsel';
  834.             } else if ($directorID == Director::SHAH_DIRECTOR_ID) {
  835.                 $data['domain'] = 'shah';
  836.             } else if ($entityID == Offer::HEROPARK_OFFER_ID) {
  837.                 $data['domain'] = 'heropark';
  838.             }
  839.         }
  840.         if (isset($data['domain']) && $data['domain'] != '') {
  841.             $data['deliveryLink'] = 'https://' $data['domain'] . str_replace('https://www.''.'$this->getParameter('base_url')) . $data['deliveryLink'];
  842.         }
  843.         if ($offer->getExternalOfferLink() && $offer->getIsShowExternalOfferLink()) {
  844.             $data['deliveryLink'] = $offer->getExternalOfferLink();
  845.         }
  846.         if ($user) {
  847.             $siteSettings $this->getSiteSettings();
  848.             $data['subscriptionPrice'] = $subscriptionService->isSubscriptionFinished($user) ? $siteSettings->getSubscriptionPrice() : $siteSettings->getSubscriptionFirstPayment();
  849.             $data['subscriptionFullPrice'] = $siteSettings->getSubscriptionPrice();
  850.             $data['subscriptionTerm'] = $subscriptionService->isSubscriptionFinished($user) ? 30 7;
  851.         }
  852.         if ($preview) {
  853.             $data['robotsMeta'] = 'noindex, follow';
  854.         }
  855.         if (!$offer->hasFreeCodes()) {
  856.             $data['deliveryLink'] = 'javascript:void(0);';
  857.         }
  858.         $data['hadSubscription'] = null !== $user $subscriptionService->isExistBySubscriber($user) : false;
  859.         $data['codeCostInCurrency'] = $offer->getSumInCurrency((float) $codeCost);
  860.         $view $isMobile 'Slivki/mobile/offer/details.html.twig' 'Slivki/offers/details.html.twig';
  861.         $response->setContent($this->renderView($view$data));
  862.         if ($user) {
  863.             $eventData = ['offerID' => $entityID'promotion_owner' => $offerRepository->isOfferOwner($offer$user)];
  864.             $amplitude = new Amplitude($user);
  865.             $amplitude->sendEvent('PromotionVisited'$eventData$this->getUtmSourceArray($request));
  866.         }
  867.         return $response;
  868.     }
  869.     /**
  870.      * @Route("/offer/comment/get/{offerID}/{page}")
  871.      */
  872.     public function getOfferComments(Request $requestOfferCacheService $offerCacheService$offerID$page) {
  873.         $offer $offerCacheService->getOffer($offerIDfalsetrue);
  874.         if (!$offer) {
  875.             return new Response();
  876.         }
  877.         $isMobile CommonUtil::isMobileDevice($request);
  878.         return new Response($this->getCommentsByOffer($offer->getID(), $pageCommentRepository::COMMENTS_PER_PAGE$isMobile));
  879.     }
  880.     private function getCommentsByOffer($offerID$page$perPage$isMobile) {
  881.         $entityManager $this->getDoctrine()->getManager();
  882.         $offset = ($page 1) * $perPage;
  883.         $commentList $entityManager->getRepository(Comment::class)->getCommentsByOfferIDReversed($offerID$offset$perPage);
  884.         $commentsAmount $this->getCommentRepository()->getCommentsCountByEntityID($offerIDComment::TYPE_OFFER_COMMENT);
  885.         return  $this->renderView($isMobile 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig', [
  886.             'comments' => $commentList,
  887.             'pagination' => $this->renderView('Slivki/pagination.html.twig', [
  888.                 'paginationID' => 'offerCommentPagination',
  889.                 'current' => $page,
  890.                 'total' => ceil($commentsAmount/$perPage),
  891.                 'url' => $entityManager->getRepository(Seo::class)->getOfferURL($offerID)->getMainAlias() . '?page='
  892.             ]),
  893.             'showBanners' => true,
  894.             'hasMore' => false
  895.         ]);
  896.     }
  897.     /**
  898.      * @Route("/additional_offer_details/{entityID}/{offerPreview}")
  899.      */
  900.     public function additionalOfferDetailsAction(Request $requestOfferCacheService $offerCacheService$entityID$offerPreview false) {
  901.         $entityManager $this->getDoctrine()->getManager();
  902.         $offerRepository $this->getOfferRepository();
  903.         $offer $offerCacheService->getOffer($entityIDfalsetrue);
  904.         $pastOffer false;
  905.         $timeNow = new \DateTime();
  906.         if (!$offer || $offerPreview) {
  907.             $offer $offerRepository->find($entityID);
  908.             if (!$offer || ((!$offer->isInVisiblePeriod() || !$offer->isActive()) && !$offerPreview)) {
  909.                 throw $this->createNotFoundException();
  910.             }
  911.             $mediaRepository $this->getMediaRepository();
  912.             $offer->setDetailMeidas($mediaRepository->getOfferDetailMedias($offer->getID()));
  913.             $offer->setShopMedias($mediaRepository->getOfferShopMedias($offer->getID()));
  914.         }
  915.         $data['parentCategoryList'] = null;
  916.         $data['offer'] = $offer;
  917.         $data['tour3dName'] = '';
  918.         $softCache = new SoftCache(OfferRepository::CACHE_NAME);
  919.         $cacheKey 'alt-offers-box-1-' $entityID;
  920.         $altOffersBox $softCache->get($cacheKey);
  921.         if ($altOffersBox == SoftCache::LOCKED_KEY) {
  922.             $altOffersBox $softCache->getDataForLockedKey($cacheKey30);
  923.         } else if (!$altOffersBox) {
  924.             $softCache->add($cacheKeySoftCache::LOCKED_KEY30);
  925.             $cacheExpire strtotime(date('Y-m-d 05:00:00'strtotime('+1 day'))) - time();
  926.             $altOffersBox "";
  927.             $altOfferList $this->getDoctrine()->getRepository(AlternativeOffer::class)->getByOfferID($entityID);
  928.             if ($altOfferList) {
  929.                 if (count($altOfferList) < 3) {
  930.                     $altOffersBox SoftCache::EMPTY_VALUE;
  931.                 } else {
  932.                     if (count($altOfferList) < 6) {
  933.                         $altOfferList array_slice($altOfferList03);
  934.                     }
  935.                     foreach ($altOfferList as $altOffer) {
  936.                         $alternativeOffer $offerCacheService->getOffer($altOffer->getAlternativeOfferID(), true);
  937.                         if ($alternativeOffer) {
  938.                             $altOffersBox .= $this->get('twig')->render('Slivki/offers/teaser.html.twig', ['offer' => $alternativeOffer'noLazyLoad' => true]);
  939.                         } else {
  940.                             $this->getLogger()->error('Alternative offer ' $altOffer->getOfferID() . " not found in cache");
  941.                             $altOffersBox "";
  942.                             break;
  943.                         }
  944.                     }
  945.                 }
  946.             }
  947.             $softCache->set($cacheKey$altOffersBox$cacheExpire);
  948.             if ($altOffersBox == SoftCache::EMPTY_VALUE) {
  949.                 $altOffersBox "";
  950.             }
  951.         }
  952.         $data['altOffersBox'] = $altOffersBox;
  953.         $view $request->query->get('offerCondition') ? 'Slivki/offers/condition.html.twig' 'Slivki/offers/additional_offer_details.html.twig';
  954.         if (self::getMobileDevice($request)) {
  955.             $view 'Slivki/mobile/offer/description.html.twig';
  956.         }
  957.         return $this->render($view$data);
  958.     }
  959.     /**
  960.      * @Route("/offer_location/{entityID}")
  961.      */
  962.     public function offerLocationAction(Request $requestOfferCacheService $offerCacheService$entityID) {
  963.         $offerRepository $this->getOfferRepository();
  964.         $offer $offerCacheService->getOffer($entityIDfalsetrue);
  965.         if (!$offer) {
  966.             $offer $offerRepository->find($entityID);
  967.             if (!$offer) {
  968.                 throw $this->createNotFoundException();
  969.             }
  970.             $mediaRepository $this->getMediaRepository();
  971.             $offer->setDetailMeidas($mediaRepository->getOfferDetailMedias($offer->getID()));
  972.             $offer->setShopMedias($mediaRepository->getOfferShopMedias($offer->getID()));
  973.         }
  974.         $data['offer'] = $offer;
  975.         $data['geoLocations'] = $offer->getGeoLocations();
  976.         return $this->render('Slivki/offers/location.html.twig'$data);
  977.     }
  978.     /**
  979.      * @Route("/get_comment_box/{type}/{entityID}/{mobileCache}")
  980.      */
  981.     public function getCommentBoxAction(Request $requestBannerService $bannerService$type$entityID$mobileCache null) {
  982.         if ($entityID == 140503) {
  983.             Logger::instance('COMMENT-DEBUG')->info('start');
  984.         }
  985.         ini_set('memory_limit''512M');
  986.         $directorID 0;
  987.         if ($type == Comment::TYPE_OFFER_COMMENT) {
  988.             $offer $this->getDoctrine()->getManager()->find(Offer::class, $entityID);
  989.             if ($offer->getDirectors()->count() > 0) {
  990.                 $directorID $offer->getDirectors()->first()->getID();
  991.             }
  992.         }
  993.         if ($entityID == 140503) {
  994.             Logger::instance('COMMENT-DEBUG')->info('05');
  995.         }
  996.         $cacheName $mobileCache CommentCacheService::MOBILE_CACHE_NAME CommentCacheService::CACHE_NAME;
  997.         $data = [
  998.             'entityID' => $entityID,
  999.             'type' => $type,
  1000.             'comments' => $this->getComments($request$bannerService$entityID$type00$directorID$cacheName),
  1001.             'commentsAmount' => $this->getCommentRepository()->getCommentsCountByEntityID($entityID$type),
  1002.             'showCommentsAmount' => $type == Comment::TYPE_SALE_COMMENT false true
  1003.         ];
  1004.         if ($entityID == 140503) {
  1005.             Logger::instance('COMMENT-DEBUG')->info('1');
  1006.         }
  1007.         $view 'Slivki/comments/comments_list.html.twig';
  1008.         if ($entityID == 140503) {
  1009.             Logger::instance('COMMENT-DEBUG')->info('2');
  1010.         }
  1011.         if ($cacheName == CommentRepository::MOBILE_CACHE_NAME) {
  1012.             $view 'Slivki/mobile/comment/block.html.twig';
  1013.         }
  1014.         if ($entityID == 140503) {
  1015.             Logger::instance('COMMENT-DEBUG')->info('3');
  1016.         }
  1017.         $response = new Response();
  1018.         $response->setContent($this->get('twig')->render($view$data));
  1019.         if ($entityID == 140503) {
  1020.             Logger::instance('COMMENT-DEBUG')->info('status code ' $response->getStatusCode());
  1021.         }
  1022.         return $response;
  1023.     }
  1024.     /**
  1025.      * @Route("/landing")
  1026.      */
  1027.     public function mobileLandingAction(
  1028.         Request $request,
  1029.         OfferCacheService $offerCacheService,
  1030.         SubscriptionService $subscriptionService,
  1031.         DeviceTypeService $deviceTypeService,
  1032.         ServerFeatureStateChecker $serverFeatureStateChecker
  1033.     ): Response {
  1034.         if (!$deviceTypeService->isMobileDevice($request) || !$serverFeatureStateChecker->isServerFeatureEnabled(SwitcherFeatures::ALLOW_MOBILE_LANDING_PAGE())) {
  1035.             return $this->redirectToRoute('homepage');
  1036.         }
  1037.         $response = new Response();
  1038.         $entityManager $this->getDoctrine()->getManager();
  1039.         $user $this->getUser();
  1040.         $carouselOffersIDs = [Dominos::OFFER_IDSushiHouse::OFFER_IDOffer::KFC_OFFER_IDOffer::FREESTYLE_OFFER_IDDodo::OFFER_ID];
  1041.         $data['recomended'] = true;
  1042.         if ($user) {
  1043.             $sql 'select entity_id from visit where user_id = ' $user->getID()
  1044.                 . ' and entity_type_id = ' Category::OFFER_CATEGORY_ID
  1045.                 ' group by 1 order by max(created_on) desc limit 10';
  1046.             $visitedOfferIDs $this->getDoctrine()->getManager()->getConnection()->executeQuery($sql)->fetchAll(\PDO::FETCH_COLUMN);
  1047.             if (!empty($visitedOfferIDs)) {
  1048.                 $carouselOffersIDs $visitedOfferIDs;
  1049.                 $data['recomended'] = false;
  1050.             }
  1051.         }
  1052.         $carouselOffers $offerCacheService->getOffers($carouselOffersIDs);
  1053.         if ($data['recomended']) {
  1054.             shuffle($carouselOffers);
  1055.         }
  1056.         $data['carouselOffers'] = $carouselOffers;
  1057.         $data['categoryList'] = $this->getCategoryRepository()->getUserFavouriteCategories($user);
  1058.         $data['showWatchList'] = $user && $this->getUser() && $this->getVisitedByUserCount($user->getID()) > 0;
  1059.         $abTestViews = [
  1060.             'Slivki/mobile/landing_new.html.twig'
  1061.         ];
  1062.         $landingABCookieName 'landingab';
  1063.         $landingABCookieValue $request->cookies->get($landingABCookieName);
  1064.         if (!$landingABCookieValue) {
  1065.             $landingABCookieValue array_rand($abTestViews);
  1066.         } else {
  1067.             $landingABCookieValue = (int)$landingABCookieValue;
  1068.             $landingABCookieValue++;
  1069.             if ($landingABCookieValue >= count($abTestViews)) {
  1070.                 $landingABCookieValue 0;
  1071.             }
  1072.         }
  1073.         $landingABCookie Cookie::create($landingABCookieName$landingABCookieValuetime() + 315360000'/'$this->getParameter('base_domain'));
  1074.         $response->headers->setCookie($landingABCookie);
  1075.         $data['subscription'] = null !== $user $subscriptionService->getSubscription($user) : null;
  1076.         $data['hadSubscription'] = null !== $user $subscriptionService->isExistBySubscriber($user) : null;
  1077.         $landingBannerRepository $entityManager->getRepository(MobileLandingBanner::class);
  1078.         $bannerList $landingBannerRepository->findBy(['active' => true], ['position' => 'ASC']);
  1079.         $data['landingBannerHtmlTop'] = $this->get('twig')->render('Slivki/banners/landing_banner_top.html.twig', ['bannerList' => $bannerList]);
  1080.         $data['landingBannerHtmlBottom'] = $this->get('twig')->render('Slivki/banners/landing_banner_bottom.html.twig', ['bannerList' => $bannerList]);
  1081.         $response->setContent($this->renderView($abTestViews[$landingABCookieValue], $data));
  1082.         return $response;
  1083.     }
  1084.     private function getVisitedByUserCount($userID) {
  1085.         $sql 'select count(distinct entity_id) from visit where user_id = ' $userID ' and entity_type_id = ' Category::OFFER_CATEGORY_ID;
  1086.         return $this->getDoctrine()->getManager()->getConnection()->executeQuery($sql)->fetchColumn();
  1087.     }
  1088.     public function getRelatedOffersTeasers(CacheService $cacheService$offerID) {
  1089.         $entityManager $this->getDoctrine()->getManager();
  1090.         $offer $entityManager->find(Offer::class, $offerID);
  1091.         $defaultCategoryID $offer->getDefaultCategoryID();
  1092.         $categoryCached $entityManager->getRepository(Category::class)->findCached($defaultCategoryID);
  1093.         if (!$categoryCached) {
  1094.             return [];
  1095.         }
  1096.         $entityIDList $categoryCached['entityList'];
  1097.         if (=== count($entityIDList)) {
  1098.             return [];
  1099.         }
  1100.         $sql 'select entity_id, purchase_count_recent from purchase_count where entity_id in (' implode(','$entityIDList) . ') order by 2 desc limit 12;';
  1101.         $purschaseCountList $entityManager->getConnection()->executeQuery($sql)->fetchAll(\PDO::FETCH_KEY_PAIR);
  1102.         return $cacheService->getTeaserList(array_keys($purschaseCountList), false);
  1103.     }
  1104.     /**
  1105.      * @Route("/comments/add_like/{commentID}")
  1106.      */
  1107.     public function addLike($commentIDRequest $request) {
  1108.         if ($this->isGranted(UserGroup::COMMENTS_BANNED_ROLE_NAME)) {
  1109.             return new Response();
  1110.         }
  1111.         $user $this->getUser();
  1112.         if(!$user) {
  1113.             return new Response(json_encode(['error' => 1]));
  1114.         }
  1115.         /** @var Comment $comment */
  1116.         $comment $this->getCommentRepository()->find($commentID);
  1117.         $like = new CommentLike();
  1118.         $like->setUserID($user->getID());
  1119.         $like->setVote((bool)$request->request->get('vote'));
  1120.         $comment->addLike($like);
  1121.         $entityManager $this->getDoctrine()->getManager();
  1122.         $entityManager->flush();
  1123.         $result $comment->getLikesAmount();
  1124.         $this->resetCommentsCache($comment->getEntityID(), $comment->getTypeID());
  1125.         return new Response(json_encode($result));
  1126.     }
  1127.     private function validateComment(Request $request) {
  1128.         $commentText trim($request->request->get('comment'''));
  1129.         if($commentText == '') {
  1130.             $result 'Отзыв не может быть пустым';
  1131.             return $result;
  1132.         }
  1133.         return true;
  1134.     }
  1135.     /**
  1136.      * @Route("/ostavit-otziv/{typeID}/{entityID}/{parentID}", defaults = {"parentID" = 0})
  1137.      */
  1138.     public function addComment($typeID$entityID$parentIDRequest $request) {
  1139.         if (!self::getMobileDevice($request)) {
  1140.             return $this->redirectToRoute('homepage');
  1141.         }
  1142.         $typeID = (int)$typeID;
  1143.         $entityID = (int)$entityID;
  1144.         $parentID = (int)$parentID;
  1145.         if (!in_array($typeID, [Comment::TYPE_OFFER_COMMENTComment::TYPE_SALE_COMMENTComment::TYPE_MALL_BRAND_COMMENTComment::TYPE_DIRECTOR_COMMENT])) {
  1146.             return $this->redirectToRoute('homepage');
  1147.         }
  1148.         if ($parentID 0) {
  1149.             $parentComment $this->getCommentRepository()->find($parentID);
  1150.             if (!$parentComment || $parentComment->getEntityID() != $entityID) {
  1151.                 return $this->redirectToRoute('homepage');
  1152.             }
  1153.         }
  1154.         return $this->render('Slivki/mobile/comment/add.html.twig', [
  1155.             'typeID' => $typeID,
  1156.             'entityID' => $entityID,
  1157.             'parentID' => $parentID,
  1158.             'referer' => $request->headers->get('referer''/')
  1159.         ]);
  1160.     }
  1161.     /**
  1162.      * @Route("/redaktirovat-otziv/{commentID}")
  1163.      */
  1164.     public function editComment($commentIDRequest $request) {
  1165.         if (!self::getMobileDevice($request)) {
  1166.             return $this->redirectToRoute('homepage');
  1167.         }
  1168.         $commentRepository $this->getCommentRepository();
  1169.         /** @var Comment $comment */
  1170.         $comment $commentRepository->find($commentID);
  1171.         if (!$comment) {
  1172.             return $this->redirectToRoute('homepage');
  1173.         }
  1174.         $user $this->getUser();
  1175.         if (!$user || !($user->getID() == $comment->getUser()->getID())) {
  1176.             return $this->redirectToRoute('homepage');
  1177.         }
  1178.         $commentRating $comment->getRating();
  1179.         return $this->render('Slivki/mobile/comment/edit.html.twig', [
  1180.             'comment' => $comment,
  1181.             'commentRating' => $commentRating,
  1182.             'isUserAllowedToRate' => $commentRating 0,
  1183.             'referer' => $request->headers->get('referer''/')
  1184.         ]);
  1185.     }
  1186.     /**
  1187.      * @Route("/udalit-otziv/{commentID}")
  1188.      */
  1189.     public function deleteComment($commentIDRequest $request) {
  1190.         if (!self::getMobileDevice($request)) {
  1191.             return $this->redirectToRoute('homepage');
  1192.         }
  1193.         $comment $this->getCommentRepository()->find($commentID);
  1194.         if (!$comment) {
  1195.             return $this->redirectToRoute('homepage');
  1196.         }
  1197.         $user $this->getUser();
  1198.         if (!$user || !($user->getID() == $comment->getUser()->getID())) {
  1199.             return $this->redirectToRoute('homepage');
  1200.         }
  1201.         return $this->render('Slivki/mobile/comment/delete.html.twig', [
  1202.             'comment' => $comment,
  1203.             'referer' => $request->headers->get('referer''/')
  1204.         ]);
  1205.     }
  1206.     /**
  1207.      * @Route("/comments/add/{type}/{entityID}")
  1208.      */
  1209.     public function commentAdd(
  1210.         int $type,
  1211.         int $entityID,
  1212.         Request $request,
  1213.         Mailer $mailer,
  1214.         ServerFeatureStateChecker $serverFeatureStateChecker
  1215.     ): Response {
  1216.         $user $this->getUser();
  1217.         if (!$user) {
  1218.             return new Response('Войдите, чтобы мы могли учесть Ваше мнение!');
  1219.         }
  1220.         if ($this->isGranted(UserGroup::COMMENTS_BANNED_ROLE_NAME)) {
  1221.             return new Response('Добавление комментариев заблокировано администратором');
  1222.         }
  1223.         $validateCommentResult $this->validateComment($request);
  1224.         if ($validateCommentResult !== true) {
  1225.             return new Response($validateCommentResult);
  1226.         }
  1227.         $parentCommentID = (int)$request->request->get('parentVoteId');
  1228.         $commentText trim($request->request->get('comment'''));
  1229.         if (Censure::parse($commentText)) {
  1230.             $response = new Response();
  1231.             $response->setStatusCode(406);
  1232.             return $response;
  1233.         }
  1234.         $entityManager $this->getDoctrine()->getManager();
  1235.         $userPhone $user->getCurrentPhone();
  1236.         $confirmedPhone true;
  1237.         if ($serverFeatureStateChecker->isServerFeatureEnabled(SwitcherFeatures::NEED_CONFIRM_PHONE_TO_COMMENT())
  1238.             && (!$userPhone || !$userPhone->isConfirmed() || !$userPhone->isBelorussian())) {
  1239.             $confirmedPhone false;
  1240.         }
  1241.         if ($type == Comment::TYPE_OFFER_COMMENT) {
  1242.             $sql 'delete from offer_rate_schedule where user_id = ' . (int)$user->getID() . ' and offer_id = ' . (int)$entityID;
  1243.             $entityManager->getConnection()->executeQuery($sql);
  1244.         }
  1245.         $parentComment $this->getCommentRepository()->find($parentCommentID);
  1246.         $comment = new Comment();
  1247.         $comment->setComment($this->prepareCommentText($commentText));
  1248.         $rating $request->request->get('actionRating');
  1249.         $comment->setRating($rating);
  1250.         if ($parentComment) {
  1251.             $comment->setParentComment($parentComment);
  1252.         }
  1253.         $comment->setEntityID($entityID);
  1254.         $comment->setHidden(false);
  1255.         $comment->setTypeID($type);
  1256.         $comment->setMobileVersion(CommonUtil::isMobileDevice($request));
  1257.         $comment->setChecked(false);
  1258.         $comment->setUser($user);
  1259.         $comment->setConfirmedPhone($confirmedPhone);
  1260.         $comment->setAllowToContact($request->request->getBoolean('allowToContact'));
  1261.         $entityManager->persist($comment);
  1262.         $session $request->getSession();
  1263.         $userCommentImages $session->get('userCommentImages', []);
  1264.         foreach ($userCommentImages as $key=>$value) {
  1265.             $media = new Media\CommentMedia();
  1266.             $media->setMediaType($entityManager->getRepository(MediaType::class)->find(MediaType::TYPE_USER_VOTE_IMAGE_ID));
  1267.             $media->setPath(MediaType::TYPE_USER_VOTE_IMAGE_PATH);
  1268.             $media->setName($value);
  1269.             $media->setSortOrder($key);
  1270.             $comment->addMedia($media);
  1271.         }
  1272.         $session->set('userCommentImages', []);
  1273.         $entityManager->flush($comment);
  1274.         if (in_array($type, [Comment::TYPE_OFFER_COMMENTComment::TYPE_SALE_COMMENT])) {
  1275.             $eventData['review_id'] = $comment->getID();
  1276.             if ($type == Comment::TYPE_OFFER_COMMENT) {
  1277.                 $eventData['promotion_id'] = $entityID;
  1278.             } else {
  1279.                 $eventData['sale_news_id'] = $entityID;
  1280.             }
  1281.             $eventData['rating'] = $comment->getRating();
  1282.             $amplitude = new Amplitude($this->getUser());
  1283.             $amplitude->sendEvent('ReviewPublished'$eventData);
  1284.         }
  1285.         if ($type == Comment::TYPE_OFFER_COMMENT && $confirmedPhone) {
  1286.             $offer $this->getOfferRepository()->find($entityID);
  1287.             $this->sendOfferCommentNotice($mailer$offer$comment$parentComment);
  1288.         }
  1289.         $this->resetCommentsCache($entityID$type);
  1290.         return new Response($confirmedPhone '<p class="mb-3" style="font-size: 30px;">😊 </p><strong style="font-family:SF Pro Rounded Bold">Благодарим за оставленный отзыв!</strong> <br><br> <p class="mb-4" style="font-family:SF Pro Rounded;font-weight: 100;">Такие отзывы, как ваш, помогают другим людям находить самые лучшие акции и интересные места</p>' 'confirm');
  1291.     }
  1292.     /**
  1293.      * @Route("/comments-live")
  1294.      * @Route("/comments-live/{alias}")
  1295.      */
  1296.     public function commentsLiveRedirect($alias null) {
  1297.         $routeName 'commentsLive';
  1298.         $routeParameters = [];
  1299.         if ($alias != '') {
  1300.             $routeName 'commentsByCategory';
  1301.             $routeParameters['alias'] = $alias;
  1302.         }
  1303.         return $this->redirectToRoute($routeName$routeParameters301);
  1304.     }
  1305.     /**
  1306.      * @Route("/otzyvy", name="commentsLive")
  1307.      */
  1308.     public function commentsLiveAction(Request $request) { //TODO: total refactoring commentsLiveAction and commentsByCategory
  1309.         $isMobileDevice self::getMobileDevice($request);
  1310.         $commentRepository $this->getCommentRepository();
  1311.         $topMenu $commentRepository->getTopMenu();
  1312.         $data['offerRateSchedule'] = $this->getOfferRateSchedule($request->getSession());
  1313.         $data['comments'] = $commentRepository->getLiveComments(20);
  1314.         $data['isLiveComments'] = 1;
  1315.         $data['hasMore'] = true;
  1316.         $data['commentsAmount'] = 20;
  1317.         $comments $this->get('twig')->render($isMobileDevice 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig'$data);
  1318.         $deviceType self::getMobileDevice($request) ? self::DEVICE_TYPE_MOBILE self::DEVICE_TYPE_DESKTOP;
  1319.         $this->addVisit(0Visit::TYPE_COMMENTS_MAIN_PAGE$deviceType$this->getUser(), $request->getClientIp(), $request->headers->get('referer'''));
  1320.         return $this->render($isMobileDevice 'Slivki/mobile/comment/index.html.twig' 'Slivki/comments/comments_live.html.twig', [
  1321.             'comments' => $comments,
  1322.             'topMenu' => $topMenu
  1323.         ]);
  1324.     }
  1325.     /**
  1326.      * @Route("/otzyvy/{alias}", name="commentsByCategory")
  1327.      */
  1328.     public function commentsByCategoryAction(Request $request$alias null) {
  1329.         $page $request->query->get('page'1);
  1330.         $isMobileDevice self::getMobileDevice($request);
  1331.         $seo $request->attributes->get(SiteController::PARAMETER_META_INFO);
  1332.         if (!$seo && $alias) {
  1333.             $seo $this->getSeoRepository()->findOneBy(['mainAlias' => '/' $alias]);
  1334.         }
  1335.         if (!$seo) {
  1336.             return $this->redirectToRoute('commentsLive');
  1337.         }
  1338.         $seoType $seo->getResourceURL();
  1339.         $entityID $seo->getEntityID();
  1340.         $commentRepository $this->getCommentRepository();
  1341.         switch($seoType) {
  1342.             case SeoRepository::RESOURCE_URL_CATEGORY_COMMENTS:
  1343.             case SeoRepository::RESOURCE_URL_OFFER_CATEGORY:
  1344.                 $categoryRepository $this->getCategoryRepository();
  1345.                 $categoryCached $categoryRepository->findCached($entityID);
  1346.                 if(!$categoryCached) {
  1347.                     return $this->redirectToRoute('commentsLive');
  1348.                 }
  1349.                 $category $categoryCached['category'];
  1350.                 $subCategories $categoryRepository->getSubCategories($category);
  1351.                 $data['isLiveComments'] = 1;
  1352.                 $data['hasMore'] = true;
  1353.                 $data['categoryID'] = $entityID;
  1354.                 $data['commentsAmount'] = 10;
  1355.                 if ($category->getTypeID() == Category::SUPPLIER_CATEGORY_TYPE) {
  1356.                     $data['comments'] = $commentRepository->getOfferCategoryComments($entityID$page);
  1357.                     $data['hasMore'] = false;
  1358.                 } else {
  1359.                     $data['comments'] = $commentRepository->getCommentsByCategoryID($category->getID(), $data['commentsAmount']);
  1360.                 }
  1361.                 $comments $this->renderView($isMobileDevice 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig'$data);
  1362.                 $title mb_strtoupper('<h1>ОТЗЫВЫ ' $category->getName() . '</h1>');
  1363.                 return $this->render($isMobileDevice 'Slivki/mobile/comment/index.html.twig' 'Slivki/comments/comments_live.html.twig', [
  1364.                     'commentsCount' => $commentRepository->getOfferCategoryCommentsCount($category->getID()),
  1365.                     'page' => $page,
  1366.                     'comments' => $comments,
  1367.                     'subCategories' => $subCategories,
  1368.                     'title' => $title,
  1369.                     'categoryID' => $entityID,
  1370.                     'category' => $category,
  1371.                     'parentCategories' => $categoryRepository->getCategoryParentList($category)
  1372.                 ]);
  1373.                 break;
  1374.             case SeoRepository::RESOURCE_URL_OFFER_DETAILS:
  1375.             case SeoRepository::RESOURCE_URL_SALE_DETAILS:
  1376.                 return $this->redirect('/' $alias301);
  1377.                 break;
  1378.         }
  1379.         return $this->redirect(CityRepository::$mainPageURL);
  1380.     }
  1381.     /**
  1382.      * @Route("/comments/load")
  1383.      */
  1384.     public function commentLoad(Request $requestBannerService $bannerService) {
  1385.         $offerID $request->request->get('marketActionOID');
  1386.         $typeID $request->request->get('typeID');
  1387.         $lastCommentID $request->request->get('lastCommentOID');
  1388.         $categoryID $request->request->getInt('categoryID');
  1389.         $directorID $request->request->getInt('directorID');
  1390.         $cacheName $request->request->getInt('isMobileCache') == CommentCacheService::CACHE_NAME CommentCacheService::MOBILE_CACHE_NAME;
  1391.         return new Response($this->getComments($request$bannerService$offerID$typeID$lastCommentID$categoryID$directorID$cacheName));
  1392.     }
  1393.     /**
  1394.      * @Route("/comments/get_by_user/{userID}")
  1395.      */
  1396.     public function commentsGetByUser($userIDRequest $request) {
  1397.         $offerID $request->query->get('offerID');
  1398.         if (!$offerID) {
  1399.             return new Response();
  1400.         }
  1401.         $dql "select comment from Slivki:Comment comment 
  1402.             where comment.userID = :userID and comment.entityID = :offerID 
  1403.             and (comment.hidden = false or comment.hidden is null)
  1404.             and (comment.deleted = false or comment.deleted is null)
  1405.             and comment.confirmedPhone = true
  1406.             order by comment.createdOn desc";
  1407.         $data['comments'] = $this->getDoctrine()->getManager()->createQuery($dql)
  1408.             ->setParameter('userID'$userID)
  1409.             ->setParameter('offerID'$offerID)
  1410.             ->getResult();
  1411.         return $this->render('Slivki/comments/comments_by_user.html.twig'$data);
  1412.     }
  1413.     /**
  1414.      * @Route("/comment/image_upload")
  1415.      */
  1416.     public function commentImageUpload(Request $requestKernelInterface $kernel) {
  1417.         $imageFolder $kernel->getProjectDir() . '/public' ImageService::MEDIA_ROOT ImageService::INITIAL_PATH MediaType::TYPE_USER_VOTE_IMAGE_PATH;
  1418.         $uploadedFile $request->files->get('imageUploadForm');
  1419.         if ($uploadedFile) {
  1420.             if (!in_array(mb_strtolower($uploadedFile->getClientOriginalExtension()), ['jpg''png''gif''jpeg'])) {
  1421.                 return new Response("error=true;result=Разрешены только .jpg, .jpeg, .png или .gif изображения");
  1422.             };
  1423.             $fs = new Filesystem();
  1424.             $newFileName time() . '_' $uploadedFile->getClientOriginalName();
  1425.             while($fs->exists($imageFolder $newFileName)) {
  1426.                 $newFileName time() . '_' $newFileName;
  1427.             }
  1428.             $uploadedFile->move($imageFolder$newFileName);
  1429.             $session $request->getSession();
  1430.             $userCommentImages $session->get('userCommentImages', []);
  1431.             $userCommentImages[] = $newFileName;
  1432.             $session->set('userCommentImages'$userCommentImages);
  1433.             return new Response("error=false;result=" ImageService::MEDIA_ROOT ImageService::INITIAL_PATH MediaType::TYPE_USER_VOTE_IMAGE_PATH $newFileName);
  1434.         } else {
  1435.             return new Response("error=true;result=Error");
  1436.         }
  1437.     }
  1438.     /**
  1439.      * @Route("/comment/image_remove")
  1440.      */
  1441.     public function commentImageRemove(Request $request) {
  1442.         $imageIndex $request->request->get('imageIndex');
  1443.         $mediaID $request->request->getInt('id');
  1444.         if ($mediaID != 0) {
  1445.             $entityManager $this->getDoctrine()->getManager();
  1446.             $media $entityManager->getRepository(Media\CommentMedia::class)->find($mediaID);
  1447.             if ($media && $this->getUser() && $media->getComment()->getUserID() == $this->getUser()->getID()) {
  1448.                 $entityManager->remove($media);
  1449.                 $entityManager->flush();
  1450.             }
  1451.         }
  1452.         $session $request->getSession();
  1453.         $userCommentImages $session->get('userCommentImages', []);
  1454.         if (isset($userCommentImages[$imageIndex])) {
  1455.             unset($userCommentImages[$imageIndex]);
  1456.         }
  1457.         $session->set('userCommentImages'array_values($userCommentImages));
  1458.         return new Response("error=false;result=");
  1459.     }
  1460.     /**
  1461.      * @Route("/comment/get/{commentID}")
  1462.      */
  1463.     public function commentGet($commentID) {
  1464.         $comment $this->getCommentRepository()->find($commentID);
  1465.         return new Response(json_encode([
  1466.             'comment' => $comment,
  1467.             'commentMediasHtml' => $this->renderView('Slivki/comments/medias_preview.html.twig', ['medias' => $comment->getMedias()])
  1468.         ]));
  1469.     }
  1470.     /**
  1471.      * @Route("/comment/is_user_allowed_to_rate/{typeID}/{entityID}")
  1472.      */
  1473.     public function isUserAllowedToRate($typeID$entityID) {
  1474.         $user $this->getUser();
  1475.         if (!$user) {
  1476.             return new JsonResponse(json_encode(false));
  1477.         }
  1478.         return new Response(json_encode($this->getCommentRepository()->isUserAllowedToRate($user->getID(), $entityID$typeID)));
  1479.     }
  1480.     /**
  1481.      * @Route("/comment/edit/{commentID}")
  1482.      */
  1483.     public function commentEdit($commentIDRequest $request) {
  1484.         $entityManager $this->getDoctrine()->getManager();
  1485.         /** @var \Slivki\Entity\Comment $comment */
  1486.         $comment $this->getCommentRepository()->find($commentID);
  1487.         if (!$comment) {
  1488.             return new Response('');
  1489.         }
  1490.         if ($comment->getCreatedOn()->format('U') < strtotime('-7 days') || $comment->getUserID() != $this->getUser()->getID()) {
  1491.             return new Response('');
  1492.         }
  1493.         $commentText trim($request->request->get('comment'''));
  1494.         if (Censure::parse($commentText)) {
  1495.             $response = new Response();
  1496.             $response->setStatusCode(406);
  1497.             return $response;
  1498.         }
  1499.         if ($comment->getRating() > 0) {
  1500.             $rating $request->request->getInt('rating');
  1501.             if ($rating $comment->getRating()) {
  1502.                 $comment->setRating($rating);
  1503.             }
  1504.         }
  1505.         $commentChildren $comment->getChildren()->toArray();
  1506.         if (empty($commentChildren)) {
  1507.             $comment->setComment($this->prepareCommentText($commentText));
  1508.             $comment->setChecked(false);
  1509.         }
  1510.         $comment->setAllowToContact($request->request->getBoolean('allowToContact'));
  1511.         $session $request->getSession();
  1512.         $userCommentImages $session->get('userCommentImages', []);
  1513.         $mediaTypeRepository $entityManager->getRepository(MediaType::class);
  1514.         foreach ($userCommentImages as $key=>$value) {
  1515.             $media = new Media\CommentMedia();
  1516.             $media->setMediaType($mediaTypeRepository->find(MediaType::TYPE_USER_VOTE_IMAGE_ID));
  1517.             $media->setPath(MediaType::TYPE_USER_VOTE_IMAGE_PATH);
  1518.             $media->setName($value);
  1519.             $media->setSortOrder($key);
  1520.             $comment->addMedia($media);
  1521.         }
  1522.         $session->set('userCommentImages', []);
  1523.         $entityManager->flush();
  1524.         $this->resetCommentsCache($comment->getEntityID(), $comment->getTypeID());
  1525.         $comment->setComment(nl2br($comment->getComment()));
  1526.         return new Response(json_encode([
  1527.             'comment' => $comment,
  1528.             'mediasHtml' => $this->renderView('Slivki/comments/medias.html.twig', ['medias' => $comment->getMedias()->toArray()])
  1529.         ]));
  1530.     }
  1531.     /**
  1532.      * @Route("/comment/delete/{commentID}")
  1533.      */
  1534.     public function commentDelete($commentIDRequest $request) {
  1535.         /** @var \Slivki\Entity\Comment $comment */
  1536.         $entityManager $this->getDoctrine()->getManager();
  1537.         $comment $entityManager->getRepository(Comment::class)->find($commentID);
  1538.         if (!$comment) {
  1539.             return new Response('');
  1540.         }
  1541.         if ($comment->getCreatedOn()->format('U') < strtotime('-24 hours') || $comment->getUserID() != $this->getUser()->getID()) {
  1542.             return new Response('');
  1543.         }
  1544.         $commentTypeID $comment->getTypeID();
  1545.         $commentEntityID $comment->getEntityID();
  1546.         $comment->setDeleted(true);
  1547.         $comment->setChecked(false);
  1548.         $comment->setRating(0);
  1549.         $entityManager->flush();
  1550.         $this->resetCommentsCache($commentEntityID$commentTypeID);
  1551.         return new Response('');
  1552.     }
  1553.     /**
  1554.      * @Route("/mailing_seen_it_cheaper")
  1555.      */
  1556.     public function seenCheaperAction(Request $requestMailer $mailer){
  1557.         $email $request->request->get("sender_email");
  1558.         $body $request->request->get("body");
  1559.         $link $request->request->get("link_to_sale");
  1560.         if($this->checkSeenCheaperForm($request)) {
  1561.             $message $mailer->createMessage();
  1562.             $message->setSubject("ОКО: Лучшее предложение")
  1563.                 ->setFrom("info@slivki.by"'Slivki.by')
  1564.                 ->setTo('info@slivki.by')
  1565.                 ->setBody($this->renderView('Slivki/emails/seen_it_cheaper.html.twig',
  1566.                     array('email' => $email'message' => $body'link' => $link)),
  1567.                     'text/html');
  1568.             $mailer->send($message);
  1569.             $result['status'] = "success";
  1570.         } else {
  1571.             $result['status'] = "error";
  1572.         }
  1573.         return new Response(json_encode($result));
  1574.     }
  1575.     public function checkSeenCheaperForm(Request $request){
  1576.         $email $request->request->get("sender_email");
  1577.         if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  1578.             return false;
  1579.         }
  1580.         return true;
  1581.     }
  1582.     /**
  1583.      * @Route("/ajax_get_map_placemarks_by_category")
  1584.      */
  1585.     public function ajaxGetMapPlacemarksByCategory(Request $request) {
  1586.         if (!$request->isXmlHttpRequest()) {
  1587.             return $this->redirect("/");
  1588.         }
  1589.         ini_set('memory_limit''1024m');
  1590.         $categoryID $request->request->get('categoryOID');
  1591.         $result = array();
  1592.         $offerRepository $this->getOfferRepository();
  1593.         $offers $offerRepository->getActiveOffersByCategoryID($categoryID);
  1594.         foreach($offers as $offer) {
  1595.             if (!$offer) {
  1596.                 continue;
  1597.             }
  1598.             $result array_merge($result$offerRepository->getOfferGeoLocations($offer));
  1599.         }
  1600.         return new Response(json_encode($result));
  1601.     }
  1602.     /**
  1603.      * @Route("/mailing_campaign/{mailingCampaignID}")
  1604.      */
  1605.     public function mailingCampaignAction($mailingCampaignID) {
  1606.         $entityManager $this->getDoctrine()->getManager();
  1607.         $mailingCampaignRepository $entityManager->getRepository(MailingCampaign::class);
  1608.         $mailingCampaign $mailingCampaignRepository->find($mailingCampaignID);
  1609.         if(!$mailingCampaign) {
  1610.             return $this->redirect("/");
  1611.         }
  1612.         $mailBody $mailingCampaign->getMailBody();
  1613.         $template $this->get('twig')->createTemplate($mailBody);
  1614.         return new Response($template->render([]));
  1615.     }
  1616.     public function sendOfferMessageFormAction(Request $request) {
  1617.         return $this->render(self::getMobileDevice($request) ?
  1618.             'Slivki/mobile/offer/create_own_offer.html.twig' 'Slivki/offers/send_offer_messsage.html.twig');
  1619.     }
  1620.     /**
  1621.      * @Route("/send_offer_message")
  1622.      */
  1623.     public function sendOfferMessage(Request $requestMailer $mailer) {
  1624.         $offerProposal = new OfferProposal();
  1625.         $offerProposal->setType(OfferProposal::PROPOSAL_TYPE);
  1626.         $offerProposal->setPhone($request->request->get('offerPhone'));
  1627.         $offerProposal->setEmail($request->request->get('offerEmail'));
  1628.         $offerProposal->setOfferConditions($request->request->get('termsOfPromotion'));
  1629.         $subject 'NEW: Разместить акцию';
  1630.         $messageText '<b>Телефон:</b> ' $request->request->get('offerPhone') . '<br>'
  1631.             '<b>E-mail:</b> ' $request->request->get('offerEmail') . '<br>'
  1632.             '<b>Условия акции:</b> ' $request->request->get('termsOfPromotion') . '<br>';
  1633.         $message $mailer->createMessage();
  1634.         $message->setSubject($subject)
  1635.             ->setFrom("info@slivki.by"'Slivki.by')
  1636.             ->setTo('info@slivki.by')
  1637.             ->setBody(
  1638.                 $messageText,
  1639.                 'text/html'
  1640.             );
  1641.         $mailer->send($message);
  1642.         try {
  1643.             $em $this->getDoctrine()->getManager();
  1644.             $em->persist($offerProposal);
  1645.             $em->flush();
  1646.         } catch (\Exception $e) {
  1647.             return new Response('Ваше сообщение успешно отправлено');
  1648.         }
  1649.         return new Response('Ваше сообщение успешно отправлено');
  1650.     }
  1651.     /**
  1652.      * @Route("/humorfm")
  1653.      */
  1654.     public function humorFM(Request $request) {
  1655.         if($this->getMobileDevice($request)){
  1656.             return $this->render('Slivki/mobile_humorfm.html.twig');
  1657.         } else{
  1658.             return $this->render('Slivki/humorfm.html.twig');
  1659.         }
  1660.     }
  1661.     /**
  1662.      * @Route("/subscribe/mobile")
  1663.      */
  1664.     public function subscribeForm(Request $request) {
  1665.         if ($this->getMobileDevice($request) and (!$this->getUser() or !$this->getUser()->getAcceptNewsletter())) {
  1666.             return $this->render('Slivki/subscribe_mobile.html.twig');
  1667.         } else {
  1668.             return $this->redirect("/");
  1669.         }
  1670.     }
  1671.     /**
  1672.      * @Route("/send-contact-form")
  1673.      */
  1674.     public function sendContactForm(Request $requestMailer $mailer) {
  1675.         $data = [
  1676.             'email' => $request->request->get('email'''),
  1677.             'name' => $request->request->get('name'''),
  1678.             'body' => $request->request->get('body''')
  1679.         ];
  1680.         $error '';
  1681.         if (!filter_var(trim($data['email'], FILTER_VALIDATE_EMAIL))) {
  1682.             $error .= 'Пожалуйста, введите Ваш E-Mail.<br>';
  1683.         }
  1684.         if (trim($data['body']) == '') {
  1685.             $error .= 'Пожалуйста, введите текст сообщения.<br>';
  1686.         }
  1687.         if ($error != '') {
  1688.             return new Response($error);
  1689.         }
  1690.         $message $mailer->createMessage();
  1691.         $message->setSubject("Сообщение")
  1692.             ->setFrom("info@slivki.by"'Slivki.by')
  1693.             ->setTo("info@slivki.by")
  1694.             ->setBody(
  1695.                 $this->renderView(
  1696.                     'Slivki/emails/contact_email.html.twig',
  1697.                     $data
  1698.                 ),
  1699.                 'text/html'
  1700.             );
  1701.         $mailer->send($message);
  1702.         return new Response();
  1703.     }
  1704.     /**
  1705.      * @Route("/contact-mail-result")
  1706.      */
  1707.     public function contactMailResult(Request $request) {
  1708.         $data['lastComments'] = $this->getDoctrine()->getRepository(Comment::class)->findBy(["hidden" => false], ["createdOn" => "desc"], 3);
  1709.         return $this->render(CommonUtil::isMobileDevice($request) ?
  1710.             'Slivki/mobile/info_pages/contacts_form_result.html.twig' 'Slivki/contact_mail_result.html.twig'$data);
  1711.     }
  1712.     /**
  1713.      * @Route("/readability_sale_stat")
  1714.      */
  1715.     public function readabilitySaleStat(Request $request) {
  1716.         $id $request->request->get('saleID');
  1717.         $timeOnPage $request->request->get('timeOnPage');
  1718.         $percentOfScrolling $request->request->get('percentOfScrolling');
  1719.         $userID $this->getUser();
  1720.         if ($userID) {
  1721.             $userID $this->getUser()->getID();
  1722.         }
  1723.         $pageHeight $request->request->get('pageHeight');
  1724.         $readPx $request->request->get('readPx');
  1725.         $date = new \DateTime();
  1726.         $readabilityStat = new ReadabilityStat();
  1727.         $readabilityStat->setEntityID($id);
  1728.         $readabilityStat->setPercentOfScrolling($percentOfScrolling);
  1729.         $readabilityStat->setTimeOnPage($timeOnPage);
  1730.         $readabilityStat->setCreatedOn($date);
  1731.         $readabilityStat->setUserID($userID);
  1732.         $readabilityStat->setPageHeight($pageHeight);
  1733.         $readabilityStat->setReadPx($readPx);
  1734.         $em $this->getDoctrine()->getManager();
  1735.         $em->persist($readabilityStat);
  1736.         $em->flush($readabilityStat);
  1737.         return new Response('');
  1738.     }
  1739.     /**
  1740.      * @Route("/jivo/hooks")
  1741.      */
  1742.     public function jivoHookAction(Request $request) {
  1743.         $data json_decode($request->getContent(), true);
  1744.         $logger Logger::instance('JIVO HOOK');
  1745.         $entityManager $this->getDoctrine()->getManager();
  1746.         $chatSession null;
  1747.         switch ($data['event_name']) {
  1748.             case 'chat_accepted':
  1749.                 $chatSession = new ChatSession();
  1750.                 $chatSession->setChatID($data['chat_id']);
  1751.                 $entityManager->persist($chatSession);
  1752.                 $chatSession->setOperatorEmail($data['agent']['email']);
  1753.                 $chatSession->setOperatorName($data['agent']['name']);
  1754.                 break;
  1755.             case 'chat_finished':
  1756.                 $chatSession $entityManager->getRepository(ChatSession::class)->findOneByChatID($data['chat_id']);
  1757.                 if (!$chatSession) {
  1758.                     $logger->info('Chat ' $data['chat_id'] . ' not found');
  1759.                     return new Response();
  1760.                 }
  1761.                 $chatSession->setFinishedOn(new \DateTime());
  1762.                 $chatHistory '';
  1763.                 foreach ($data['chat']['messages'] as $message) {
  1764.                     $chatHistory .= date('d.m.Y'$message['timestamp']) . '<br>';
  1765.                     $chatHistory .= ($message['type'] == 'agent' 'Консультант' 'Клиент') . '<br>';
  1766.                     $chatHistory .= $message['message'] . '<br><br>';
  1767.                 }
  1768.                 $chatSession->setChatHistory($chatHistory);
  1769.                 break;
  1770.             default:
  1771.                 return new Response();
  1772.         }
  1773.         if (!$chatSession->getUser() && isset($data['user_token'])) {
  1774.             $user $entityManager->getRepository(User::class)->find($data['user_token']);
  1775.             if ($user) {
  1776.                 $chatSession->setUser($user);
  1777.             } else {
  1778.                 $logger->info('User ' $data['user_token'] . ' not found');
  1779.             }
  1780.         }
  1781.         $entityManager->flush($chatSession);
  1782.         if ($data['event_name'] == 'chat_accepted') {
  1783.             $data['result'] = 'ok';
  1784.             $user $chatSession->getUser();
  1785.             if ($user) {
  1786.                 $data['custom_data'][0]['title'] = 'Баланс';
  1787.                 $data['custom_data'][0]['content'] = number_format($user->getFullBalance(), 2);
  1788.                 $data['contact_info']['name'] = $user->getFirstName();
  1789.                 $data['contact_info']['phone'] = $user->getPhone();
  1790.                 $data['contact_info']['email'] = $user->getEmail();
  1791.                 $data['contact_info']['description'] = '';
  1792.             }
  1793.             $response = new JsonResponse();
  1794.             $response->setCharset('UTF-8');
  1795.             $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
  1796.             $response->setData($data);
  1797.             return $response;
  1798.         }
  1799.         return new Response();
  1800.     }
  1801.     /**
  1802.      * @Route("/subscribe")
  1803.      */
  1804.     public function subscribeAction(Request $requestMailer $mailer) {
  1805.         $email mb_strtolower(trim($request->request->get('email')));
  1806.         $entityManager $this->getDoctrine()->getManager();
  1807.         $user $entityManager->getRepository(User::class)->loadUserByUsername($emailfalse);
  1808.         if ($user && ($user->getAcceptNewsletter() || $user->getID() == $this->getUser()->getID())) {
  1809.             if (!$user->getAcceptNewsletter()) {
  1810.                 $user->setAcceptNewsletter(true);
  1811.                 $entityManager->flush($user);
  1812.             }
  1813.             return new Response('0');
  1814.         }
  1815.         $subscriber $entityManager->getRepository(Subscriber::class)->findOneByEmail($email);
  1816.         if ($subscriber && $subscriber->getConfirmationCode() == '') {
  1817.             return new Response('0');
  1818.         }
  1819.         if (!$subscriber) {
  1820.             $validator $this->get('validator');
  1821.             $emailConstraint = new Email();
  1822.             if ($email == '' || $validator->validate($email$emailConstraint) != '') {
  1823.                 return new Response('1');
  1824.             }
  1825.             $subscriber = new Subscriber();
  1826.             $subscriber->setEmail($email);
  1827.             $entityManager->persist($subscriber);
  1828.             $confirmationCode md5($subscriber->getID() . $subscriber->getEmail());
  1829.             $subscriber->setConfirmationCode($confirmationCode);
  1830.             $entityManager->flush($subscriber);
  1831.         }
  1832.         $messageBody $this->get('twig')->render('Slivki/emails/confirm_email.html.twig', ['confirmationCode' => $subscriber->getConfirmationCode()]);
  1833.         $message $mailer->createMessage('Вы станете богаче!'$messageBody'text/html')->addTo($email)->addFrom('info@slivki.by');
  1834.         $mailer->send($message);
  1835.         return new Response('2');
  1836.     }
  1837.     /** @Route("/subscribe-from-email/{userHash}") */
  1838.     public function subscribeFromEmailAction(Request $request$userHash) {
  1839.         $entityManager $this->getDoctrine()->getManager();
  1840.         $user null;
  1841.         $sql "select email from customer where md5(id || email) = '" pg_escape_string($userHash) . "'";
  1842.         $query $entityManager->getConnection()->executeQuery($sql);
  1843.         if ($query->rowCount() != 1) {
  1844.             return $this->redirect('/');
  1845.         }
  1846.         $user $entityManager->getRepository(User::class)->loadUserByUsername($query->fetchColumn(), false);
  1847.         if (!$user) {
  1848.             return $this->redirect('/');
  1849.         }
  1850.         $currentUser $this->getUser();
  1851.         if (!$currentUser || ($currentUser->getID() != $user->getID())) {
  1852.             $passwordToken = new UsernamePasswordToken($user$user->getPassword(), 'main'$user->getRoles());
  1853.             $this->get('security.token_storage')->setToken($passwordToken);
  1854.             $event = new InteractiveLoginEvent($request$passwordToken);
  1855.             $this->get('event_dispatcher')->dispatch('security.interactive_login'$event);
  1856.         }
  1857.         return $this->redirect('/profile' '#profile_subscribe');
  1858.     }
  1859.     /**
  1860.      * @Route("/confirm/email/{confirmationCode}")
  1861.      */
  1862.     public function confirmEmailAction($confirmationCode) {
  1863.         $confirmationCode pg_escape_string($confirmationCode);
  1864.         $entityManager $this->getDoctrine()->getManager();
  1865.         $sql "select id, email from subscriber where md5(id::text || email) = '$confirmationCode'";
  1866.         $subscriber $entityManager->getConnection()->executeQuery($sql)->fetch();
  1867.         if (!$subscriber) {
  1868.             $this->addFlash(self::SHOW_INFO_DIALOG_PARAMETER'Пользователь не найден');
  1869.             return $this->redirect(CityRepository::$mainPageURL);
  1870.         }
  1871.         $user $entityManager->getRepository(User::class)->loadUserByUsername($subscriber['email'], false);
  1872.         if ($user) {
  1873.             $user->setAcceptNewsletter(true);
  1874.             $entityManager->flush($user);
  1875.             $entityManager->getConnection()->executeQuery("delete from subscriber where id = $subscriber[id]");
  1876.         } else {
  1877.             $entityManager->getConnection()->executeQuery("update subscriber set confirmation_code = '' where id = $subscriber[id]");
  1878.         }
  1879.         $this->addFlash(self::SHOW_INFO_DIALOG_PARAMETER'Вы успешно подписаны на рассылку');
  1880.         return $this->redirect(CityRepository::$mainPageURL);
  1881.     }
  1882.     /**
  1883.      * @Route("/oplata-promokoda-azs")
  1884.      */
  1885.     public function getGasStationCode(
  1886.         Request $request,
  1887.         OfferCacheService $offerCacheService,
  1888.         SubscriptionService $subscriptionService
  1889.     ): Response {
  1890.         $entityManager $this->getDoctrine()->getManager();
  1891.         $user $this->getUser();
  1892.         $userID $user->getID();
  1893.         $offerID Offer::PETROL_OFFER_ID;
  1894.         $sql "select id from offer_order where user_id = $userID and offer_id = $offerID order by id DESC limit 1";
  1895.         $orderID $entityManager->getConnection()->executeQuery($sql)->fetchColumn();
  1896.         if ($orderID) {
  1897.             $entityOption$entityManager->getRepository(EntityOption::class)->findBy(['entityID' => $orderID]);
  1898.             foreach ($entityOption as $val) {
  1899.                 switch ($val->getName()) {
  1900.                     case "car_model":
  1901.                         $data['carModel'] = $val->getValue();
  1902.                         break;
  1903.                     case "car_number":
  1904.                         $data['carNumber'] = $val->getValue();
  1905.                         break;
  1906.                     case "phone_number":
  1907.                         $data['phoneNumber'] = $val->getValue();
  1908.                         break;
  1909.                 }
  1910.             }
  1911.         }
  1912.         $data['offerID'] = Offer::PETROL_OFFER_ID;
  1913.         $offerRepository $this->getOfferRepository();
  1914.         $offer $offerCacheService->getOffer(Offer::PETROL_OFFER_ID);
  1915.         $data['codeCost'] = $offerRepository->getCodeCost($offer);
  1916.         $data['freeCodesCount'] = $offer->getFreeCodesCount();
  1917.         $data['freeCode'] = $offerRepository->isOfferFreeForUser($offer$this->getUser());
  1918.         $data['useBalance'] =  $this->getUser()->getFullBalance() >= $offerRepository->getCodeCost($offer);
  1919.         $userPhone $user->getCurrentPhone();
  1920.         if ($userPhone) {
  1921.             $data['phoneNumber'] = $userPhone->getPhoneNumber();
  1922.         }
  1923.         $siteSettings $this->getSiteSettings();
  1924.         $data['subscriptionPrice'] = $subscriptionService->isSubscriptionFinished($user)
  1925.             ? $siteSettings->getSubscriptionPrice()
  1926.             : $siteSettings->getSubscriptionFirstPayment();
  1927.         $data['subscriptionFullPrice'] = $siteSettings->getSubscriptionPrice();
  1928.         $subscription $subscriptionService->getSubscription($user);
  1929.         $data['allowedCodesCountBySubscription'] = $subscriptionService->isSubscriber($user)
  1930.             ? $subscription->getNumberOfCodes()
  1931.             : 0;
  1932.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/payment/fuel.html.twig'
  1933.             'Slivki/offers/get_code_for_gas_station.html.twig'$data);
  1934.     }
  1935.     /**
  1936.      * @Route("/get_offer_comment_medias_list")
  1937.      */
  1938.     public function getOfferCommentMediasList(Request $request) {
  1939.         $entityID $request->request->get('entityID');
  1940.         $entityType $request->request->get('entityType');
  1941.         $offset $request->request->get('offset');
  1942.         $limit $request->request->get('limit');
  1943.         switch ($entityType) {
  1944.             case 'category':
  1945.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaListByCategoryID($entityID$offset$limit);
  1946.                 break;
  1947.             case 'offer':
  1948.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaListByOfferID($entityID$offset$limit);
  1949.                 break;
  1950.             case 'all':
  1951.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaList($offset$limit);
  1952.                 break;
  1953.         }
  1954.         return $this->render('Slivki/comments/media_block_list.html.twig'$data);
  1955.     }
  1956.     /**
  1957.      * @Route("/get_top_comment_list")
  1958.      */
  1959.     public function getTopCommentList(Request $request) {
  1960.         $offset $request->request->get('offset');
  1961.         $limit $request->request->get('limit');
  1962.         $data['commentList'] = $this->getCommentRepository()->findBy(['checked' => true'rating' => 5], ['ID' => 'DESC'], $limit$offset);
  1963.         return $this->render('Slivki/category_dividers/comment_list.html.twig'$data);
  1964.     }
  1965.     /** @Route("/ne-nashli-chto-iskali") */
  1966.     public function lookingForAction(Request $request) {
  1967.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/looking_for.html.twig' 'Slivki/looking_for.html.twig');
  1968.     }
  1969.     /** @Route("/send-looking-for") */
  1970.     public function sendLookingForAction(Request $requestMailer $mailer) {
  1971.         if (!$request->getMethod('POST')) {
  1972.             return new Response();
  1973.         }
  1974.         $message $mailer->createMessage();
  1975.         $mailBody "<b>Текст:</b><br>"
  1976.             $request->request->get('text')
  1977.             . "<br><br><b>Email:</b><br>"
  1978.             $request->request->get('email')
  1979.             . "<br><br><b>Телефон:</b><br>"
  1980.             $request->request->get('phone');
  1981.         $message->setSubject("Не нашли, что искали")
  1982.             ->setFrom('info@slivki.by''Slivki.by')
  1983.             ->setTo('info@slivki.by')
  1984.             ->setBody($mailBody'text/html');
  1985.         $mailer->send($message);
  1986.         return new Response();
  1987.     }
  1988.     /**
  1989.      * @Route("/get_sidebar")
  1990.      */
  1991.     public function getSidebar(SlivkiTwigExtension $extension) {
  1992.         return new Response($extension->getSidebar($this->get('twig')));
  1993.     }
  1994.     /**
  1995.      * @Route("/get_sidebar_item_list")
  1996.      */
  1997.     public function getSidebarItemListContent(
  1998.         Request $request,
  1999.         SidebarCacheService $sidebarCacheService
  2000.     ): Response {
  2001.         $offset $request->request->get('offset'0);
  2002.         $length $request->request->get('length'20);
  2003.         $sidebarCached $sidebarCacheService->getSidebarCached();
  2004.         if (null === $sidebarCached) {
  2005.             return new Response('');
  2006.         }
  2007.         $sidebarItemList array_slice($sidebarCached->getItemList(), $offset$length);
  2008.         if (empty($sidebarItemList)) {
  2009.             return new Response('');
  2010.         }
  2011.         $sidebarContent implode(''$sidebarItemList);
  2012.         return new Response($sidebarContent);
  2013.     }
  2014.     /**
  2015.      * @Route("/widget/{alias}")
  2016.      * @Route("/widget/map/{alias}")
  2017.      */
  2018.     public function widgetMapTireAction($alias) {
  2019.         $softCache = new SoftCache('tire-widget');
  2020.         $result $softCache->get($alias);
  2021.         if ($result) {
  2022.             return new Response($result);
  2023.         }
  2024.         $offers null;
  2025.         if ($alias == 'map_tire') {
  2026.             $offers $this->getOfferRepository()->getActiveOffersByCategoryIDNoCache(492);
  2027.         }
  2028.         if (!$offers) {
  2029.             $seo $this->getSeoRepository()->getByAlias('/' $alias);
  2030.             if (!$seo) {
  2031.                 return new Response();
  2032.             }
  2033.             switch ($seo->getResourceURL()) {
  2034.                 case SeoRepository::RESOURCE_URL_OFFER_CATEGORY:
  2035.                     $offers $this->getOfferRepository()->getActiveOffersByCategoryID($seo->getEntityID());
  2036.                     break;
  2037.                 case SeoRepository::RESOURCE_URL_OFFER_DETAILS:
  2038.                     $offer $this->getOfferRepository()->getAnyWay($seo->getEntityID());
  2039.                     if ($offer) {
  2040.                         $offers[] = $offer;
  2041.                     }
  2042.             }
  2043.         }
  2044.         if (!$offers || count($offers) == 0) {
  2045.             return new Response();
  2046.         }
  2047.         $result = [];
  2048.         $i 0;
  2049.         $seoRepository $this->getSeoRepository(Seo::class);
  2050.         foreach($offers as $offer) {
  2051.             if (!$offer) {
  2052.                 continue;
  2053.             }
  2054.             $geoLocations $offer->getGeoLocations();
  2055.             foreach ($geoLocations as $geoLocation) {
  2056.                 $geoLocationInfos['markerAnnotation'] = $geoLocation->getDescription();
  2057.                 $geoLocationInfos['latitude'] = $geoLocation->getLatitude();
  2058.                 $geoLocationInfos['longitude'] = $geoLocation->getLongitude();
  2059.                 $result[$i]['geoLocationInfos'][] = $geoLocationInfos;
  2060.                 $seo $seoRepository->getByEntity('Slivki:Default:details'$offer->getID());
  2061.                 $url '';
  2062.                 if ($seo) {
  2063.                     $url $seo->getMainAlias();
  2064.                 }
  2065.                 $result[$i]['longMarkerDescription'] = "<div class=\"map-balloon-description--description\">" $offer->getTitle() . "</div><div class=\"map-balloon-description--link\"><a target='_blank' href=\"" $url "\">Подробнее</a></div>";
  2066.                 $i++;
  2067.             }
  2068.         }
  2069.         $result $this->renderView('Slivki/widget/map_tire.html.twig', ['placemarkList' => $result]);
  2070.         $softCache->set($alias$result12 60 60);
  2071.         return new Response($result);
  2072.     }
  2073.     /** @Route("/get_sidebar_banner/{cityID}") */
  2074.     public function getSidebarBanner(BannerService $bannerService$cityID) {
  2075.         $cityID = (int)$cityID;
  2076.         if (!$cityID) {
  2077.             $cityID City::DEFAULT_CITY_ID;
  2078.         }
  2079.         return new JsonResponse($bannerService->getSidebarBannerCached($cityID));
  2080.     }
  2081.     /** @Route("/log/browser") */
  2082.     public function browserLogAction(Request $request) {
  2083.         Logger::instance('BrowserLog')->info($request->request->get('message'));
  2084.         return new Response();
  2085.     }
  2086.     /** @Route("/category/filter/map/{categoryID}") */
  2087.     public function categoryMapFilterAction(Request $requestCacheService $cacheService$categoryID) {
  2088.         ini_set('memory_limit''512M');
  2089.         $offerIDList $request->request->get('offerList', []);
  2090.         $teaserList $cacheService->getTeaserList($offerIDListCommonUtil::isMobileDevice($request));
  2091.         $result = ['html' => '''count' => 0];
  2092.         if ($teaserList) {
  2093.             $data = ['offerList' => array_values($teaserList), 'offersInARow' => self::getMobileDevice($request) ? 3];
  2094.             $result = [
  2095.                 'html' => $this->get('twig')->render('Slivki/offers/teasers.html.twig'$data),
  2096.                 'count' => count($teaserList)
  2097.             ];
  2098.         }
  2099.         return new JsonResponse($result);
  2100.     }
  2101.     /** @Route("/category/location-info/{categoryID}/{limit}/{offset}") */
  2102.     public function getLocationInfoAction($categoryID$limit$offset) {
  2103.         $offerGeoLocationCache = new SoftCache(OfferRepository::CACHE_NAME_GEO_LOCATION_DATA);
  2104.         $features $offerGeoLocationCache->get($categoryID, []);
  2105.         if (!$features) {
  2106.             $features = [];
  2107.         }
  2108.         $features array_slice($features$offset$limit);
  2109.         if (empty($features)) {
  2110.             return new Response(json_encode([]));
  2111.         }
  2112.         $getLocationData = ['type' => 'FeatureCollection''features' => $features];
  2113.         return new Response(json_encode($getLocationData));
  2114.     }
  2115.     /** @Route("/top500") */
  2116.     public function topAction() {
  2117.         $data['infoPage'] = new InfoPage();
  2118.         $data['text'] = $data['infoPage']->getContent();
  2119.         return $this->render('Slivki/pages/pages.html.twig'$data);
  2120.     }
  2121.     /** @Route("/category/get_supplier_address_tab/{directorID}") */
  2122.     public function getSupplierAddressTab(Request $request$directorID) {
  2123.         $entityManager $this->getDoctrine()->getManager();
  2124.         $director $entityManager->getRepository(Director::class)->find($directorID);
  2125.         if (!$director) {
  2126.             return new Response();
  2127.         }
  2128.         $directorUniqueGeoLocations = [];
  2129.         /** @var Offer $offer */
  2130.         foreach ($director->getOffers() as $offer) {
  2131.             if (!$offer->isActive() || !$offer->isInActivePeriod()) {
  2132.                 continue;
  2133.             }
  2134.             /** @var GeoLocation $geoLocation */
  2135.             foreach ($offer->getGeoLocations() as $geoLocation) {
  2136.                 $isUniqueGeoLoation true;
  2137.                 /** @var GeoLocation $uniqueGeoLocation */
  2138.                 foreach ($directorUniqueGeoLocations as $uniqueGeoLocation) {
  2139.                     if ($geoLocation->getCity() == $uniqueGeoLocation->getCity() && $geoLocation->getStreet() == $uniqueGeoLocation->getStreet()
  2140.                         && $geoLocation->getHouse() == $uniqueGeoLocation->getHouse()) {
  2141.                         $isUniqueGeoLoation false;
  2142.                         break;
  2143.                     }
  2144.                 }
  2145.                 if ($isUniqueGeoLoation) {
  2146.                     $directorUniqueGeoLocations[] = $geoLocation;
  2147.                 }
  2148.             }
  2149.         }
  2150.         $data['geoLocationList'] = $directorUniqueGeoLocations;
  2151.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/offer/supplier_address_tab.html.twig'
  2152.             'Slivki/offers/supplier_address_tab.html.twig'$data);
  2153.     }
  2154.     /** @Route("/category/get_supplier_photoguide_tab/{directorID}") */
  2155.     public function getSupplierPhotoguideTab($directorID) {
  2156.         $entityManager $this->getDoctrine()->getManager();
  2157.         $director $entityManager->getRepository(Director::class)->find($directorID);
  2158.         if (!$director) {
  2159.             return new Response();
  2160.         }
  2161.         $teaserList = [];
  2162.         $saleRepository $this->getSaleRepository();
  2163.         /** @var Sale $sale */
  2164.         foreach ($director->getSales() as $sale) {
  2165.             $saleCached $saleRepository->findCached($sale->getID());
  2166.             $teaserList[] = $this->renderView('Slivki/sale/teaser.html.twig', ['sale' => $saleCached]);
  2167.         }
  2168.         $data['teaserList'] = $teaserList;
  2169.         return $this->render('Slivki/offers/supplier_photoguide_tab.html.twig'$data);
  2170.     }
  2171.     /** @Route("/get-sorted-sidebar") */
  2172.     public function getSortedSidebar(Request $request) {
  2173.         if (!$request->isMethod(Request::METHOD_POST)) {
  2174.             return $this->redirectToRoute('homepage');
  2175.         }
  2176.         $requestParameters $request->request->all();
  2177.         if (!isset($requestParameters['sortBy'])) {
  2178.             $requestParameters['sortBy'] = 'default';
  2179.         }
  2180.         $categoryID $requestParameters['categoryID'] ? $requestParameters['categoryID'] : null;
  2181.         $coordinates $requestParameters['coordinates'] != '' explode(','$requestParameters['coordinates']) : null;
  2182.         $sortedSaleIDList $this->getSaleRepository()->getSaleIDSorted(
  2183.             $requestParameters['sortBy'], $categoryID$requestParameters['offset'],
  2184.             $requestParameters['limit'], $coordinates);
  2185.         $softCache = new SoftCache(SaleRepository::CACHE_NAME);
  2186.         $sortedSaleList $softCache->getMulti($sortedSaleIDList);
  2187.         if (!is_array($sortedSaleList)) {
  2188.             $sortedSaleList = [];
  2189.         }
  2190.         $sidebarContent '';
  2191.         foreach ($sortedSaleList as $sale) {
  2192.             if (!$sale) {
  2193.                 continue;
  2194.             }
  2195.             $sidebarContent .= $this->renderView('Slivki/sidebar/sale_teaser.html.twig', ['sale' => $sale]);
  2196.         }
  2197.         return new Response($sidebarContent);
  2198.     }
  2199.     /** @Route("/offer/food-extension-order") */
  2200.     public function offerFoodExtensionOrder(Request $request) {
  2201.         if (!self::getMobileDevice($request)) {
  2202.             return $this->redirectToRoute('homepage');
  2203.         }
  2204.         return $this->render('Slivki/offers/food_extension/mobile/order.html.twig');
  2205.     }
  2206.     /** @Route("/offer/food-extension-order-confirm") */
  2207.     public function offerFoodExtensionOrderConfirm(Request $request) {
  2208.         if (!self::getMobileDevice($request)) {
  2209.             return $this->redirectToRoute('homepage');
  2210.         }
  2211.         return $this->render('Slivki/offers/food_extension/mobile/order_confirm.html.twig');
  2212.     }
  2213.     /** @Route("/food-order/check/{orderID}") */
  2214.     public function checkFoodOrderStateActioin($orderID) {
  2215.         $order $this->getDoctrine()->getManager()->find(FoodOrder::class, $orderID);
  2216.         if (!$order || $order->getStatus() != OfferOrder::STATUS_INIT) {
  2217.             return new Response('paid');
  2218.         }
  2219.         return new Response();
  2220.     }
  2221.     /** @Route("/offer_supplier_image/{offerID}/{limit}/{offset}") */
  2222.     public function getOfferSupplierSliderAction(CacheService $cacheService$offerID$limit$offset) {
  2223.         $supplierOfferPhotoList $cacheService->getMediaList($offerIDMedia\OfferSupplierPhotoMedia::TYPE$offset$limit);
  2224.         if (empty($supplierOfferPhotoList)) {
  2225.             return new Response('');
  2226.         }
  2227.         return $this->render('Slivki/comments/offer_supplier_photos.html.twig',
  2228.             ['supplierOfferPhotoList' => $supplierOfferPhotoList]);
  2229.     }
  2230.     /** @Route("/location/confirm/test") */
  2231.     public function testLocationConfirmAction(Request $request) {
  2232.         $request->request->set('showLocationConfirm'true);
  2233.         return $this->indexAction($request);
  2234.     }
  2235.     /**
  2236.      * @Route("/dreamland-registration/{code}")
  2237.      */
  2238.     public function dreamlandPartnerAction(Request $request$code) {
  2239.         $entityManager $this->getDoctrine()->getManager();
  2240.         $entityOptionRepository $entityManager->getRepository(EntityOption::class);
  2241.         $partnerCode $entityOptionRepository->findOneBy([
  2242.             'entityTypeID' => null,
  2243.             'name' => EntityOption::OPTION_DREAMLAND_PARTNER,
  2244.             'value' => $code
  2245.         ]);
  2246.         if (!$partnerCode) {
  2247.             return $this->redirect('/');
  2248.         }
  2249.         if ($this->getUser()) {
  2250.             $option $entityOptionRepository->findOneBy([
  2251.                 'entityTypeID' => EntityOption::USER_TYPE,
  2252.                 'name' => EntityOption::OPTION_DREAMLAND_PARTNER,
  2253.                 'entityID' => $this->getUser()->getID()
  2254.             ]);
  2255.             if (!$option) {
  2256.                 $option = new EntityOption();
  2257.                 $option->setEntityTypeID(EntityOption::USER_TYPE);
  2258.                 $option->setEntityID($this->getUser()->getID());
  2259.                 $option->setName(EntityOption::OPTION_DREAMLAND_PARTNER);
  2260.                 $option->setValue($code);
  2261.                 $entityManager->persist($option);
  2262.                 $entityManager->flush();
  2263.             }
  2264.             return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2265.         }
  2266.         $request->getSession()->set(EntityOption::OPTION_DREAMLAND_PARTNER$code);
  2267.         if (CommonUtil::isMobileDevice($request)) {
  2268.             return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2269.         }
  2270.         return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2271.     }
  2272.     /** @Route("/newadformat") */
  2273.     public function newAdFormatActioin() {
  2274.         return $this->render('Slivki/newadformat/index.html.twig');
  2275.     }
  2276.     public function domainPlaceHolderAction(Request $request$entityID) {
  2277.         $offer $this->getDoctrine()->getManager()->find(Offer::class, $entityID);
  2278.         $director $offer->getDirectors()->first();
  2279.         return $this->render(CommonUtil::isMobileDevice($request) ? 'Slivki/m/mobile/index.html.twig' 'Slivki/m/index.html.twig', ['director' => $director]);
  2280.     }
  2281.     /** @Route("/email-test") */
  2282.     public function emailTestAction(Mailer $mailer) {
  2283.         $message $mailer->createMessage('test''test');
  2284.         $message->addTo('igoradv@gmail.com');
  2285.         $message->setFrom('info@slivki.by''Slivki.by');
  2286.         $mailer->send($message);
  2287.         return new Response('sent');
  2288.     }
  2289.     /** @Route("/prilozhenie-skidok", name = "mobileApp") */
  2290.     public function appPageAction(Request $request) {
  2291.         $view CommonUtil::isMobileDevice($request) ? 'Slivki/mobile/mobile_app.html.twig' 'Slivki/mobile_app.html.twig';
  2292.         return $this->render($view);
  2293.     }
  2294. }