src/Controller/DefaultController.php line 511

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