src/Controller/DefaultController.php line 1441

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