src/Controller/DefaultController.php line 143

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.         $data['defaultPickup'] = $onlineSettings && $onlineSettings->isDefaultPickup();
  882.         $view $isMobile 'Slivki/mobile/offer/details.html.twig' 'Slivki/offers/details.html.twig';
  883.         $response->setContent($this->renderView($view$data));
  884.         return $response;
  885.     }
  886.     /**
  887.      * @Route("/offer/comment/get/{offerID}/{page}")
  888.      */
  889.     public function getOfferComments(Request $requestOfferCacheService $offerCacheService$offerID$page) {
  890.         $offer $offerCacheService->getOffer($offerIDfalsetrue);
  891.         if (!$offer) {
  892.             return new Response();
  893.         }
  894.         $isMobile CommonUtil::isMobileDevice($request);
  895.         return new Response($this->getCommentsByOffer($offer->getID(), $pageCommentRepository::COMMENTS_PER_PAGE$isMobile));
  896.     }
  897.     private function getCommentsByOffer($offerID$page$perPage$isMobile) {
  898.         $entityManager $this->getDoctrine()->getManager();
  899.         $offset = ($page 1) * $perPage;
  900.         $commentList $entityManager->getRepository(Comment::class)->getCommentsByOfferIDReversed($offerID$offset$perPage);
  901.         $commentsAmount $this->getCommentRepository()->getCommentsCountByEntityID($offerIDComment::TYPE_OFFER_COMMENT);
  902.         return  $this->renderView($isMobile 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig', [
  903.             'comments' => $commentList,
  904.             'pagination' => $this->renderView('Slivki/pagination.html.twig', [
  905.                 'paginationID' => 'offerCommentPagination',
  906.                 'current' => $page,
  907.                 'total' => ceil($commentsAmount/$perPage),
  908.                 'url' => $entityManager->getRepository(Seo::class)->getOfferURL($offerID)->getMainAlias() . '?page='
  909.             ]),
  910.             'showBanners' => true,
  911.             'hasMore' => false
  912.         ]);
  913.     }
  914.     /**
  915.      * @Route("/additional_offer_details/{entityID}/{offerPreview}")
  916.      */
  917.     public function additionalOfferDetailsAction(Request $requestOfferCacheService $offerCacheService$entityID$offerPreview false) {
  918.         $entityManager $this->getDoctrine()->getManager();
  919.         $offerRepository $this->getOfferRepository();
  920.         $offer $offerCacheService->getOffer($entityIDfalsetrue);
  921.         $pastOffer false;
  922.         $timeNow = new \DateTime();
  923.         if (!$offer || $offerPreview) {
  924.             $offer $offerRepository->find($entityID);
  925.             if (!$offer || ((!$offer->isInVisiblePeriod() || !$offer->isActive()) && !$offerPreview)) {
  926.                 throw $this->createNotFoundException();
  927.             }
  928.             $mediaRepository $this->getMediaRepository();
  929.             $offer->setDetailMeidas($mediaRepository->getOfferDetailMedias($offer->getID()));
  930.             $offer->setShopMedias($mediaRepository->getOfferShopMedias($offer->getID()));
  931.         }
  932.         $data['parentCategoryList'] = null;
  933.         $data['offer'] = $offer;
  934.         $data['tour3dName'] = '';
  935.         $softCache = new SoftCache(OfferRepository::CACHE_NAME);
  936.         $cacheKey 'alt-offers-box-1-' $entityID;
  937.         $altOffersBox $softCache->get($cacheKey);
  938.         if ($altOffersBox == SoftCache::LOCKED_KEY) {
  939.             $altOffersBox $softCache->getDataForLockedKey($cacheKey30);
  940.         } else if (!$altOffersBox) {
  941.             $softCache->add($cacheKeySoftCache::LOCKED_KEY30);
  942.             $cacheExpire strtotime(date('Y-m-d 05:00:00'strtotime('+1 day'))) - time();
  943.             $altOffersBox "";
  944.             $altOfferList $this->getDoctrine()->getRepository(AlternativeOffer::class)->getByOfferID($entityID);
  945.             if ($altOfferList) {
  946.                 if (count($altOfferList) < 3) {
  947.                     $altOffersBox SoftCache::EMPTY_VALUE;
  948.                 } else {
  949.                     if (count($altOfferList) < 6) {
  950.                         $altOfferList array_slice($altOfferList03);
  951.                     }
  952.                     foreach ($altOfferList as $altOffer) {
  953.                         $alternativeOffer $offerCacheService->getOffer($altOffer->getAlternativeOfferID(), true);
  954.                         if ($alternativeOffer) {
  955.                             $altOffersBox .= $this->get('twig')->render('Slivki/offers/teaser.html.twig', ['offer' => $alternativeOffer'noLazyLoad' => true]);
  956.                         } else {
  957.                             $this->getLogger()->error('Alternative offer ' $altOffer->getOfferID() . " not found in cache");
  958.                             $altOffersBox "";
  959.                             break;
  960.                         }
  961.                     }
  962.                 }
  963.             }
  964.             $softCache->set($cacheKey$altOffersBox$cacheExpire);
  965.             if ($altOffersBox == SoftCache::EMPTY_VALUE) {
  966.                 $altOffersBox "";
  967.             }
  968.         }
  969.         $data['altOffersBox'] = $altOffersBox;
  970.         $view $request->query->get('offerCondition') ? 'Slivki/offers/condition.html.twig' 'Slivki/offers/additional_offer_details.html.twig';
  971.         if (self::getMobileDevice($request)) {
  972.             $view 'Slivki/mobile/offer/description.html.twig';
  973.         }
  974.         return $this->render($view$data);
  975.     }
  976.     /**
  977.      * @Route("/offer_location/{entityID}")
  978.      */
  979.     public function offerLocationAction(Request $requestOfferCacheService $offerCacheService$entityID) {
  980.         $offerRepository $this->getOfferRepository();
  981.         $offer $offerCacheService->getOffer($entityIDfalsetrue);
  982.         if (!$offer) {
  983.             $offer $offerRepository->find($entityID);
  984.             if (!$offer) {
  985.                 throw $this->createNotFoundException();
  986.             }
  987.             $mediaRepository $this->getMediaRepository();
  988.             $offer->setDetailMeidas($mediaRepository->getOfferDetailMedias($offer->getID()));
  989.             $offer->setShopMedias($mediaRepository->getOfferShopMedias($offer->getID()));
  990.         }
  991.         $data['offer'] = $offer;
  992.         $data['geoLocations'] = $offer->getGeoLocations();
  993.         return $this->render('Slivki/offers/location.html.twig'$data);
  994.     }
  995.     /**
  996.      * @Route("/get_comment_box/{type}/{entityID}/{mobileCache}")
  997.      */
  998.     public function getCommentBoxAction(Request $requestBannerService $bannerService$type$entityID$mobileCache null) {
  999.         if ($entityID == 140503) {
  1000.             Logger::instance('COMMENT-DEBUG')->info('start');
  1001.         }
  1002.         ini_set('memory_limit''512M');
  1003.         $directorID 0;
  1004.         if ($type == Comment::TYPE_OFFER_COMMENT) {
  1005.             $offer $this->getDoctrine()->getManager()->find(Offer::class, $entityID);
  1006.             if ($offer->getDirectors()->count() > 0) {
  1007.                 $directorID $offer->getDirectors()->first()->getID();
  1008.             }
  1009.         }
  1010.         if ($entityID == 140503) {
  1011.             Logger::instance('COMMENT-DEBUG')->info('05');
  1012.         }
  1013.         $cacheName $mobileCache CommentCacheService::MOBILE_CACHE_NAME CommentCacheService::CACHE_NAME;
  1014.         $data = [
  1015.             'entityID' => $entityID,
  1016.             'type' => $type,
  1017.             'comments' => $this->getComments($request$bannerService$entityID$type00$directorID$cacheName),
  1018.             'commentsAmount' => $this->getCommentRepository()->getCommentsCountByEntityID($entityID$type),
  1019.             'showCommentsAmount' => $type == Comment::TYPE_SALE_COMMENT false true
  1020.         ];
  1021.         if ($entityID == 140503) {
  1022.             Logger::instance('COMMENT-DEBUG')->info('1');
  1023.         }
  1024.         $view 'Slivki/comments/comments_list.html.twig';
  1025.         if ($entityID == 140503) {
  1026.             Logger::instance('COMMENT-DEBUG')->info('2');
  1027.         }
  1028.         if ($cacheName == CommentRepository::MOBILE_CACHE_NAME) {
  1029.             $view 'Slivki/mobile/comment/block.html.twig';
  1030.         }
  1031.         if ($entityID == 140503) {
  1032.             Logger::instance('COMMENT-DEBUG')->info('3');
  1033.         }
  1034.         $response = new Response();
  1035.         $response->setContent($this->get('twig')->render($view$data));
  1036.         if ($entityID == 140503) {
  1037.             Logger::instance('COMMENT-DEBUG')->info('status code ' $response->getStatusCode());
  1038.         }
  1039.         return $response;
  1040.     }
  1041.     /**
  1042.      * @Route("/landing")
  1043.      */
  1044.     public function mobileLandingAction(
  1045.         Request $request,
  1046.         OfferCacheService $offerCacheService,
  1047.         SubscriptionService $subscriptionService,
  1048.         DeviceTypeService $deviceTypeService,
  1049.         ServerFeatureStateChecker $serverFeatureStateChecker
  1050.     ): Response {
  1051.         if (!$deviceTypeService->isMobileDevice($request) || !$serverFeatureStateChecker->isServerFeatureEnabled(SwitcherFeatures::ALLOW_MOBILE_LANDING_PAGE())) {
  1052.             return $this->redirectToRoute('homepage');
  1053.         }
  1054.         $response = new Response();
  1055.         $entityManager $this->getDoctrine()->getManager();
  1056.         $user $this->getUser();
  1057.         $carouselOffersIDs = [Dominos::OFFER_IDSushiHouse::OFFER_IDOffer::KFC_OFFER_IDOffer::FREESTYLE_OFFER_IDDodo::OFFER_ID];
  1058.         $data['recomended'] = true;
  1059.         if ($user) {
  1060.             $sql 'select entity_id from visit where user_id = ' $user->getID()
  1061.                 . ' and entity_type_id = ' Category::OFFER_CATEGORY_ID
  1062.                 ' group by 1 order by max(created_on) desc limit 10';
  1063.             $visitedOfferIDs $this->getDoctrine()->getManager()->getConnection()->executeQuery($sql)->fetchAll(\PDO::FETCH_COLUMN);
  1064.             if (!empty($visitedOfferIDs)) {
  1065.                 $carouselOffersIDs $visitedOfferIDs;
  1066.                 $data['recomended'] = false;
  1067.             }
  1068.         }
  1069.         $carouselOffers $offerCacheService->getOffers($carouselOffersIDs);
  1070.         if ($data['recomended']) {
  1071.             shuffle($carouselOffers);
  1072.         }
  1073.         $data['carouselOffers'] = $carouselOffers;
  1074.         $data['categoryList'] = $this->getCategoryRepository()->getUserFavouriteCategories($user);
  1075.         $data['showWatchList'] = $user && $this->getUser() && $this->getVisitedByUserCount($user->getID()) > 0;
  1076.         $abTestViews = [
  1077.             'Slivki/mobile/landing_new.html.twig'
  1078.         ];
  1079.         $landingABCookieName 'landingab';
  1080.         $landingABCookieValue $request->cookies->get($landingABCookieName);
  1081.         if (!$landingABCookieValue) {
  1082.             $landingABCookieValue array_rand($abTestViews);
  1083.         } else {
  1084.             $landingABCookieValue = (int)$landingABCookieValue;
  1085.             $landingABCookieValue++;
  1086.             if ($landingABCookieValue >= count($abTestViews)) {
  1087.                 $landingABCookieValue 0;
  1088.             }
  1089.         }
  1090.         $landingABCookie Cookie::create($landingABCookieName$landingABCookieValuetime() + 315360000'/'$this->getParameter('base_domain'));
  1091.         $response->headers->setCookie($landingABCookie);
  1092.         $data['subscription'] = null !== $user $subscriptionService->getSubscription($user) : null;
  1093.         $data['hadSubscription'] = null !== $user $subscriptionService->isExistBySubscriber($user) : null;
  1094.         $landingBannerRepository $entityManager->getRepository(MobileLandingBanner::class);
  1095.         $bannerList $landingBannerRepository->findBy(['active' => true], ['position' => 'ASC']);
  1096.         $data['landingBannerHtmlTop'] = $this->get('twig')->render('Slivki/banners/landing_banner_top.html.twig', ['bannerList' => $bannerList]);
  1097.         $data['landingBannerHtmlBottom'] = $this->get('twig')->render('Slivki/banners/landing_banner_bottom.html.twig', ['bannerList' => $bannerList]);
  1098.         $response->setContent($this->renderView($abTestViews[$landingABCookieValue], $data));
  1099.         return $response;
  1100.     }
  1101.     private function getVisitedByUserCount($userID) {
  1102.         $sql 'select count(distinct entity_id) from visit where user_id = ' $userID ' and entity_type_id = ' Category::OFFER_CATEGORY_ID;
  1103.         return $this->getDoctrine()->getManager()->getConnection()->executeQuery($sql)->fetchColumn();
  1104.     }
  1105.     public function getRelatedOffersTeasers(CacheService $cacheService$offerID) {
  1106.         $entityManager $this->getDoctrine()->getManager();
  1107.         $offer $entityManager->find(Offer::class, $offerID);
  1108.         $defaultCategoryID $offer->getDefaultCategoryID();
  1109.         if (empty($defaultCategoryID)) {
  1110.             return '';
  1111.         }
  1112.         $entityIDList $this->offerDao->findActiveOffersByCategoryIds([$defaultCategoryID]);
  1113.         if (== count($entityIDList)) {
  1114.             return '';
  1115.         }
  1116.         $sql 'select entity_id, purchase_count_recent from purchase_count where entity_id in (' implode(','$entityIDList) . ') order by 2 desc limit 12;';
  1117.         try {
  1118.             $purschaseCountList $entityManager->getConnection()->executeQuery($sql)->fetchAll(\PDO::FETCH_KEY_PAIR);
  1119.         } catch (\PDOException $e) {
  1120.             Logger::instance('Related offers')->info($offerID);
  1121.         }
  1122.         return $cacheService->getTeaserList(array_keys($purschaseCountList), false);
  1123.     }
  1124.     /**
  1125.      * @Route("/comments/add_like/{commentID}")
  1126.      */
  1127.     public function addLike($commentIDRequest $request) {
  1128.         if ($this->isGranted(UserGroup::COMMENTS_BANNED_ROLE_NAME)) {
  1129.             return new Response();
  1130.         }
  1131.         $user $this->getUser();
  1132.         if(!$user) {
  1133.             return new Response(json_encode(['error' => 1]));
  1134.         }
  1135.         /** @var Comment $comment */
  1136.         $comment $this->getCommentRepository()->find($commentID);
  1137.         $like = new CommentLike();
  1138.         $like->setUserID($user->getID());
  1139.         $like->setVote((bool)$request->request->get('vote'));
  1140.         $comment->addLike($like);
  1141.         $entityManager $this->getDoctrine()->getManager();
  1142.         $entityManager->flush();
  1143.         $result $comment->getLikesAmount();
  1144.         $this->resetCommentsCache($comment->getEntityID(), $comment->getTypeID());
  1145.         return new Response(json_encode($result));
  1146.     }
  1147.     private function validateComment(Request $request) {
  1148.         $commentText trim($request->request->get('comment'''));
  1149.         if($commentText == '') {
  1150.             $result 'Отзыв не может быть пустым';
  1151.             return $result;
  1152.         }
  1153.         return true;
  1154.     }
  1155.     /**
  1156.      * @Route("/ostavit-otziv/{typeID}/{entityID}/{parentID}", defaults = {"parentID" = 0})
  1157.      */
  1158.     public function addComment($typeID$entityID$parentIDRequest $request) {
  1159.         if (!self::getMobileDevice($request)) {
  1160.             return $this->redirectToRoute('homepage');
  1161.         }
  1162.         $typeID = (int)$typeID;
  1163.         $entityID = (int)$entityID;
  1164.         $parentID = (int)$parentID;
  1165.         if (!in_array($typeID, [Comment::TYPE_OFFER_COMMENTComment::TYPE_SALE_COMMENTComment::TYPE_MALL_BRAND_COMMENTComment::TYPE_DIRECTOR_COMMENT])) {
  1166.             return $this->redirectToRoute('homepage');
  1167.         }
  1168.         if ($parentID 0) {
  1169.             $parentComment $this->getCommentRepository()->find($parentID);
  1170.             if (!$parentComment || $parentComment->getEntityID() != $entityID) {
  1171.                 return $this->redirectToRoute('homepage');
  1172.             }
  1173.         }
  1174.         return $this->render('Slivki/mobile/comment/add.html.twig', [
  1175.             'typeID' => $typeID,
  1176.             'entityID' => $entityID,
  1177.             'parentID' => $parentID,
  1178.             'referer' => $request->headers->get('referer''/')
  1179.         ]);
  1180.     }
  1181.     /**
  1182.      * @Route("/redaktirovat-otziv/{commentID}")
  1183.      */
  1184.     public function editComment($commentIDRequest $request) {
  1185.         if (!self::getMobileDevice($request)) {
  1186.             return $this->redirectToRoute('homepage');
  1187.         }
  1188.         $commentRepository $this->getCommentRepository();
  1189.         /** @var Comment $comment */
  1190.         $comment $commentRepository->find($commentID);
  1191.         if (!$comment) {
  1192.             return $this->redirectToRoute('homepage');
  1193.         }
  1194.         $user $this->getUser();
  1195.         if (!$user || !($user->getID() == $comment->getUser()->getID())) {
  1196.             return $this->redirectToRoute('homepage');
  1197.         }
  1198.         $commentRating $comment->getRating();
  1199.         return $this->render('Slivki/mobile/comment/edit.html.twig', [
  1200.             'comment' => $comment,
  1201.             'commentRating' => $commentRating,
  1202.             'isUserAllowedToRate' => $commentRating 0,
  1203.             'referer' => $request->headers->get('referer''/')
  1204.         ]);
  1205.     }
  1206.     /**
  1207.      * @Route("/udalit-otziv/{commentID}")
  1208.      */
  1209.     public function deleteComment($commentIDRequest $request) {
  1210.         if (!self::getMobileDevice($request)) {
  1211.             return $this->redirectToRoute('homepage');
  1212.         }
  1213.         $comment $this->getCommentRepository()->find($commentID);
  1214.         if (!$comment) {
  1215.             return $this->redirectToRoute('homepage');
  1216.         }
  1217.         $user $this->getUser();
  1218.         if (!$user || !($user->getID() == $comment->getUser()->getID())) {
  1219.             return $this->redirectToRoute('homepage');
  1220.         }
  1221.         return $this->render('Slivki/mobile/comment/delete.html.twig', [
  1222.             'comment' => $comment,
  1223.             'referer' => $request->headers->get('referer''/')
  1224.         ]);
  1225.     }
  1226.     /**
  1227.      * @Route("/comments/add/{type}/{entityID}")
  1228.      */
  1229.     public function commentAdd(
  1230.         int $type,
  1231.         int $entityID,
  1232.         Request $request,
  1233.         Mailer $mailer,
  1234.         ServerFeatureStateChecker $serverFeatureStateChecker,
  1235.         VoiceMessageUploader $voiceMessageUploader
  1236.     ): Response {
  1237.         $user $this->getUser ();
  1238.         if (!$user) {
  1239.             return new Response('Войдите, чтобы мы могли учесть Ваше мнение!');
  1240.         }
  1241.         if ($this->isGranted(UserGroup::COMMENTS_BANNED_ROLE_NAME)) {
  1242.             return new Response('Добавление комментариев заблокировано администратором');
  1243.         }
  1244.         $validateCommentResult $this->validateComment($request);
  1245.         if ($validateCommentResult !== true) {
  1246.             return new Response($validateCommentResult);
  1247.         }
  1248.         $parentCommentID = (int)$request->request->get('parentVoteId');
  1249.         $commentText trim($request->request->get('comment'''));
  1250.         if (Censure::parse($commentText)) {
  1251.             $response = new Response();
  1252.             $response->setStatusCode(406);
  1253.             return $response;
  1254.         }
  1255.         $entityManager $this->getDoctrine()->getManager();
  1256.         $userPhone $user->getCurrentPhone();
  1257.         $confirmedPhone true;
  1258.         if ($serverFeatureStateChecker->isServerFeatureEnabled(SwitcherFeatures::NEED_CONFIRM_PHONE_TO_COMMENT())
  1259.             && (!$userPhone || !$userPhone->isConfirmed() || !$userPhone->isBelorussian())) {
  1260.             $confirmedPhone false;
  1261.         }
  1262.         if ($type == Comment::TYPE_OFFER_COMMENT) {
  1263.             $sql 'DELETE FROM offer_rate_schedule WHERE user_id = ' . (int)$user->getID() . ' AND offer_id = ' . (int)$entityID;
  1264.             $entityManager->getConnection()->executeQuery($sql);
  1265.         }
  1266.         $parentComment $this->getCommentRepository()->find($parentCommentID);
  1267.         $comment = new Comment();
  1268.         $comment->setComment($this->prepareCommentText($commentText));
  1269.         $rating $request->request->get('actionRating');
  1270.         $comment->setRating($rating);
  1271.         if ($parentComment) {
  1272.             $comment->setParentComment($parentComment);
  1273.         }
  1274.         $comment->setEntityID($entityID);
  1275.         $comment->setHidden(false);
  1276.         $comment->setTypeID($type);
  1277.         $comment->setMobileVersion(CommonUtil::isMobileDevice($request));
  1278.         $comment->setChecked(false);
  1279.         $comment->setUser ($user);
  1280.         $comment->setConfirmedPhone($confirmedPhone);
  1281.         if ($userPhone instanceof UserPhone) {
  1282.             $comment->setPhone($userPhone->getPhoneNumber());
  1283.         }
  1284.         $comment->setAllowToContact($request->request->getBoolean('allowToContact'));
  1285.         $voiceFile $request->files->get('voice_message');
  1286.         if ($voiceFile) {
  1287.             $voicePath $voiceMessageUploader->upload($voiceFile);
  1288.             if ($voicePath !== null) {
  1289.                 $comment->setVoicePath($voicePath);
  1290.             }
  1291.         }
  1292.         $entityManager->persist($comment);
  1293.         $session $request->getSession();
  1294.         $userCommentImages $session->get('userCommentImages', []);
  1295.         foreach ($userCommentImages as $key => $value) {
  1296.             $media = new Media\CommentMedia();
  1297.             $media->setMediaType($entityManager->getRepository(MediaType::class)->find(MediaType::TYPE_USER_VOTE_IMAGE_ID));
  1298.             $media->setPath(MediaType::TYPE_USER_VOTE_IMAGE_PATH);
  1299.             $media->setName($value);
  1300.             $media->setSortOrder($key);
  1301.             $comment->addMedia($media);
  1302.         }
  1303.         $session->set('userCommentImages', []);
  1304.         $entityManager->flush($comment);
  1305.         if ($type == Comment::TYPE_OFFER_COMMENT && $confirmedPhone) {
  1306.             $offer $this->getOfferRepository()->find($entityID);
  1307.             $this->sendOfferCommentNotice($mailer$offer$comment$parentComment);
  1308.         }
  1309.         $this->resetCommentsCache($entityID$type);
  1310.         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');
  1311.     }
  1312.     /**
  1313.      * @Route("/comments-live")
  1314.      * @Route("/comments-live/{alias}")
  1315.      */
  1316.     public function commentsLiveRedirect($alias null) {
  1317.         $routeName 'commentsLive';
  1318.         $routeParameters = [];
  1319.         if ($alias != '') {
  1320.             $routeName 'commentsByCategory';
  1321.             $routeParameters['alias'] = $alias;
  1322.         }
  1323.         return $this->redirectToRoute($routeName$routeParameters301);
  1324.     }
  1325.     /**
  1326.      * @Route("/otzyvy", name="commentsLive")
  1327.      */
  1328.     public function commentsLiveAction(Request $request) { //TODO: total refactoring commentsLiveAction and commentsByCategory
  1329.         $isMobileDevice self::getMobileDevice($request);
  1330.         $commentRepository $this->getCommentRepository();
  1331.         $topMenu $commentRepository->getTopMenu();
  1332.         $data['offerRateSchedule'] = $this->getOfferRateSchedule($request->getSession());
  1333.         $data['comments'] = $commentRepository->getLiveComments(20);
  1334.         $data['isLiveComments'] = 1;
  1335.         $data['hasMore'] = true;
  1336.         $data['commentsAmount'] = 20;
  1337.         $comments $this->get('twig')->render($isMobileDevice 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig'$data);
  1338.         $deviceType self::getMobileDevice($request) ? self::DEVICE_TYPE_MOBILE self::DEVICE_TYPE_DESKTOP;
  1339.         $this->addVisit(0Visit::TYPE_COMMENTS_MAIN_PAGE$deviceType$this->getUser(), $request->getClientIp(), $request->headers->get('referer'''));
  1340.         return $this->render($isMobileDevice 'Slivki/mobile/comment/index.html.twig' 'Slivki/comments/comments_live.html.twig', [
  1341.             'comments' => $comments,
  1342.             'topMenu' => $topMenu
  1343.         ]);
  1344.     }
  1345.     /**
  1346.      * @Route("/otzyvy/{alias}", name="commentsByCategory")
  1347.      */
  1348.     public function commentsByCategoryAction(Request $request$alias null) {
  1349.         $page $request->query->get('page'1);
  1350.         $isMobileDevice self::getMobileDevice($request);
  1351.         $seo $request->attributes->get(SiteController::PARAMETER_META_INFO);
  1352.         if (!$seo && $alias) {
  1353.             $seo $this->getSeoRepository()->findOneBy(['mainAlias' => '/' $alias]);
  1354.         }
  1355.         if (!$seo) {
  1356.             return $this->redirectToRoute('commentsLive');
  1357.         }
  1358.         $seoType $seo->getResourceURL();
  1359.         $entityID $seo->getEntityID();
  1360.         $commentRepository $this->getCommentRepository();
  1361.         switch($seoType) {
  1362.             case SeoRepository::RESOURCE_URL_CATEGORY_COMMENTS:
  1363.             case SeoRepository::RESOURCE_URL_OFFER_CATEGORY:
  1364.                 $categoryRepository $this->getCategoryRepository();
  1365.                 $categoryCached $categoryRepository->findCached($entityID);
  1366.                 if(!$categoryCached) {
  1367.                     return $this->redirectToRoute('commentsLive');
  1368.                 }
  1369.                 $category $categoryCached['category'];
  1370.                 $subCategories $categoryRepository->getSubCategories($category);
  1371.                 $data['isLiveComments'] = 1;
  1372.                 $data['hasMore'] = true;
  1373.                 $data['categoryID'] = $entityID;
  1374.                 $data['commentsAmount'] = 10;
  1375.                 if ($category->getTypeID() == Category::SUPPLIER_CATEGORY_TYPE) {
  1376.                     $data['comments'] = $commentRepository->getOfferCategoryComments($entityID$page);
  1377.                     $data['hasMore'] = false;
  1378.                 } else {
  1379.                     $data['comments'] = $commentRepository->getCommentsByCategoryID($category->getID(), $data['commentsAmount']);
  1380.                 }
  1381.                 $comments $this->renderView($isMobileDevice 'Slivki/mobile/comment/list.html.twig' 'Slivki/comments/comments.html.twig'$data);
  1382.                 $title mb_strtoupper('<h1>ОТЗЫВЫ ' $category->getName() . '</h1>');
  1383.                 return $this->render($isMobileDevice 'Slivki/mobile/comment/index.html.twig' 'Slivki/comments/comments_live.html.twig', [
  1384.                     'commentsCount' => $commentRepository->getOfferCategoryCommentsCount($category->getID()),
  1385.                     'page' => $page,
  1386.                     'comments' => $comments,
  1387.                     'subCategories' => $subCategories,
  1388.                     'title' => $title,
  1389.                     'categoryID' => $entityID,
  1390.                     'category' => $category,
  1391.                     'parentCategories' => $categoryRepository->getCategoryParentList($category)
  1392.                 ]);
  1393.                 break;
  1394.             case SeoRepository::RESOURCE_URL_OFFER_DETAILS:
  1395.             case SeoRepository::RESOURCE_URL_SALE_DETAILS:
  1396.                 return $this->redirect('/' $alias301);
  1397.                 break;
  1398.         }
  1399.         return $this->redirect(CityRepository::$mainPageURL);
  1400.     }
  1401.     /**
  1402.      * @Route("/comments/load")
  1403.      */
  1404.     public function commentLoad(Request $requestBannerService $bannerService) {
  1405.         $offerID $request->request->get('marketActionOID');
  1406.         $typeID $request->request->get('typeID');
  1407.         $lastCommentID $request->request->get('lastCommentOID');
  1408.         $categoryID $request->request->getInt('categoryID');
  1409.         $directorID $request->request->getInt('directorID');
  1410.         $cacheName $request->request->getInt('isMobileCache') == CommentCacheService::CACHE_NAME CommentCacheService::MOBILE_CACHE_NAME;
  1411.         return new Response($this->getComments($request$bannerService$offerID$typeID$lastCommentID$categoryID$directorID$cacheName));
  1412.     }
  1413.     /**
  1414.      * @Route("/comments/get_by_user/{userID}")
  1415.      */
  1416.     public function commentsGetByUser($userIDRequest $request) {
  1417.         $offerID $request->query->get('offerID');
  1418.         if (!$offerID) {
  1419.             return new Response();
  1420.         }
  1421.         $dql "select comment from Slivki:Comment comment 
  1422.             where comment.userID = :userID and comment.entityID = :offerID 
  1423.             and (comment.hidden = false or comment.hidden is null)
  1424.             and (comment.deleted = false or comment.deleted is null)
  1425.             and comment.confirmedPhone = true
  1426.             order by comment.createdOn desc";
  1427.         $data['comments'] = $this->getDoctrine()->getManager()->createQuery($dql)
  1428.             ->setParameter('userID'$userID)
  1429.             ->setParameter('offerID'$offerID)
  1430.             ->getResult();
  1431.         return $this->render('Slivki/comments/comments_by_user.html.twig'$data);
  1432.     }
  1433.     /**
  1434.      * @Route("/comment/image_upload")
  1435.      */
  1436.     public function commentImageUpload(Request $requestKernelInterface $kernel) {
  1437.         $imageFolder $kernel->getProjectDir() . '/public' ImageService::MEDIA_ROOT ImageService::INITIAL_PATH MediaType::TYPE_USER_VOTE_IMAGE_PATH;
  1438.         $uploadedFile $request->files->get('imageUploadForm');
  1439.         if ($uploadedFile) {
  1440.             if (!in_array(mb_strtolower($uploadedFile->getClientOriginalExtension()), ['jpg''png''gif''jpeg'])) {
  1441.                 return new Response("error=true;result=Разрешены только .jpg, .jpeg, .png или .gif изображения");
  1442.             };
  1443.             $fs = new Filesystem();
  1444.             $newFileName time() . '_' $uploadedFile->getClientOriginalName();
  1445.             while($fs->exists($imageFolder $newFileName)) {
  1446.                 $newFileName time() . '_' $newFileName;
  1447.             }
  1448.             $uploadedFile->move($imageFolder$newFileName);
  1449.             $session $request->getSession();
  1450.             $userCommentImages $session->get('userCommentImages', []);
  1451.             $userCommentImages[] = $newFileName;
  1452.             $session->set('userCommentImages'$userCommentImages);
  1453.             return new Response("error=false;result=" ImageService::MEDIA_ROOT ImageService::INITIAL_PATH MediaType::TYPE_USER_VOTE_IMAGE_PATH $newFileName);
  1454.         } else {
  1455.             return new Response("error=true;result=Error");
  1456.         }
  1457.     }
  1458.     /**
  1459.      * @Route("/comment/image_remove")
  1460.      */
  1461.     public function commentImageRemove(Request $request) {
  1462.         $imageIndex $request->request->get('imageIndex');
  1463.         $mediaID $request->request->getInt('id');
  1464.         if ($mediaID != 0) {
  1465.             $entityManager $this->getDoctrine()->getManager();
  1466.             $media $entityManager->getRepository(Media\CommentMedia::class)->find($mediaID);
  1467.             if ($media && $this->getUser() && $media->getComment()->getUserID() == $this->getUser()->getID()) {
  1468.                 $entityManager->remove($media);
  1469.                 $entityManager->flush();
  1470.             }
  1471.         }
  1472.         $session $request->getSession();
  1473.         $userCommentImages $session->get('userCommentImages', []);
  1474.         if (isset($userCommentImages[$imageIndex])) {
  1475.             unset($userCommentImages[$imageIndex]);
  1476.         }
  1477.         $session->set('userCommentImages'array_values($userCommentImages));
  1478.         return new Response("error=false;result=");
  1479.     }
  1480.     /**
  1481.      * @Route("/comment/get/{commentID}")
  1482.      */
  1483.     public function commentGet($commentID) {
  1484.         $comment $this->getCommentRepository()->find($commentID);
  1485.         return new Response(json_encode([
  1486.             'comment' => $comment,
  1487.             'commentMediasHtml' => $this->renderView('Slivki/comments/medias_preview.html.twig', ['medias' => $comment->getMedias()])
  1488.         ]));
  1489.     }
  1490.     /**
  1491.      * @Route("/comment/is_user_allowed_to_rate/{typeID}/{entityID}")
  1492.      */
  1493.     public function isUserAllowedToRate($typeID$entityID) {
  1494.         $user $this->getUser();
  1495.         if (!$user) {
  1496.             return new JsonResponse(json_encode(false));
  1497.         }
  1498.         return new Response(json_encode($this->getCommentRepository()->isUserAllowedToRate($user->getID(), $entityID$typeID)));
  1499.     }
  1500.     /**
  1501.      * @Route("/comment/edit/{commentID}")
  1502.      */
  1503.     public function commentEdit($commentIDRequest $request) {
  1504.         $entityManager $this->getDoctrine()->getManager();
  1505.         /** @var \Slivki\Entity\Comment $comment */
  1506.         $comment $this->getCommentRepository()->find($commentID);
  1507.         if (!$comment) {
  1508.             return new Response('');
  1509.         }
  1510.         if ($comment->getCreatedOn()->format('U') < strtotime('-7 days') || $comment->getUserID() != $this->getUser()->getID()) {
  1511.             return new Response('');
  1512.         }
  1513.         $commentText trim($request->request->get('comment'''));
  1514.         if (Censure::parse($commentText)) {
  1515.             $response = new Response();
  1516.             $response->setStatusCode(406);
  1517.             return $response;
  1518.         }
  1519.         if ($comment->getRating() > 0) {
  1520.             $rating $request->request->getInt('rating');
  1521.             if ($rating $comment->getRating()) {
  1522.                 $comment->setRating($rating);
  1523.             }
  1524.         }
  1525.         $commentChildren $comment->getChildren()->toArray();
  1526.         if (empty($commentChildren)) {
  1527.             $comment->setComment($this->prepareCommentText($commentText));
  1528.             $comment->setChecked(false);
  1529.         }
  1530.         $comment->setAllowToContact($request->request->getBoolean('allowToContact'));
  1531.         $session $request->getSession();
  1532.         $userCommentImages $session->get('userCommentImages', []);
  1533.         $mediaTypeRepository $entityManager->getRepository(MediaType::class);
  1534.         foreach ($userCommentImages as $key=>$value) {
  1535.             $media = new Media\CommentMedia();
  1536.             $media->setMediaType($mediaTypeRepository->find(MediaType::TYPE_USER_VOTE_IMAGE_ID));
  1537.             $media->setPath(MediaType::TYPE_USER_VOTE_IMAGE_PATH);
  1538.             $media->setName($value);
  1539.             $media->setSortOrder($key);
  1540.             $comment->addMedia($media);
  1541.         }
  1542.         $session->set('userCommentImages', []);
  1543.         $entityManager->flush();
  1544.         $this->resetCommentsCache($comment->getEntityID(), $comment->getTypeID());
  1545.         $comment->setComment(nl2br($comment->getComment()));
  1546.         return new Response(json_encode([
  1547.             'comment' => $comment,
  1548.             'mediasHtml' => $this->renderView('Slivki/comments/medias.html.twig', ['medias' => $comment->getMedias()->toArray()])
  1549.         ]));
  1550.     }
  1551.     /**
  1552.      * @Route("/comment/delete/{commentID}")
  1553.      */
  1554.     public function commentDelete($commentIDRequest $request) {
  1555.         /** @var \Slivki\Entity\Comment $comment */
  1556.         $entityManager $this->getDoctrine()->getManager();
  1557.         $comment $entityManager->getRepository(Comment::class)->find($commentID);
  1558.         if (!$comment) {
  1559.             return new Response('');
  1560.         }
  1561.         if ($comment->getCreatedOn()->format('U') < strtotime('-24 hours') || $comment->getUserID() != $this->getUser()->getID()) {
  1562.             return new Response('');
  1563.         }
  1564.         $commentTypeID $comment->getTypeID();
  1565.         $commentEntityID $comment->getEntityID();
  1566.         $comment->setDeleted(true);
  1567.         $comment->setChecked(false);
  1568.         $comment->setRating(0);
  1569.         $entityManager->flush();
  1570.         $this->resetCommentsCache($commentEntityID$commentTypeID);
  1571.         return new Response('');
  1572.     }
  1573.     /**
  1574.      * @Route("/mailing_seen_it_cheaper")
  1575.      */
  1576.     public function seenCheaperAction(Request $requestMailer $mailer){
  1577.         $email $request->request->get("sender_email");
  1578.         $body $request->request->get("body");
  1579.         $link $request->request->get("link_to_sale");
  1580.         if($this->checkSeenCheaperForm($request)) {
  1581.             $message $mailer->createMessage();
  1582.             $message->setSubject("ОКО: Лучшее предложение")
  1583.                 ->setFrom("info@slivki.by"'Slivki.by')
  1584.                 ->setTo('info@slivki.by')
  1585.                 ->setBody($this->renderView('Slivki/emails/seen_it_cheaper.html.twig',
  1586.                     array('email' => $email'message' => $body'link' => $link)),
  1587.                     'text/html');
  1588.             $mailer->send($message);
  1589.             $result['status'] = "success";
  1590.         } else {
  1591.             $result['status'] = "error";
  1592.         }
  1593.         return new Response(json_encode($result));
  1594.     }
  1595.     public function checkSeenCheaperForm(Request $request){
  1596.         $email $request->request->get("sender_email");
  1597.         if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  1598.             return false;
  1599.         }
  1600.         return true;
  1601.     }
  1602.     /**
  1603.      * @Route("/ajax_get_map_placemarks_by_category")
  1604.      */
  1605.     public function ajaxGetMapPlacemarksByCategory(Request $request) {
  1606.         if (!$request->isXmlHttpRequest()) {
  1607.             return $this->redirect("/");
  1608.         }
  1609.         ini_set('memory_limit''1024m');
  1610.         $categoryID $request->request->get('categoryOID');
  1611.         $result = array();
  1612.         $offerRepository $this->getOfferRepository();
  1613.         $offers $offerRepository->getActiveOffersByCategoryID($categoryID);
  1614.         foreach($offers as $offer) {
  1615.             if (!$offer) {
  1616.                 continue;
  1617.             }
  1618.             $result array_merge($result$offerRepository->getOfferGeoLocations($offer));
  1619.         }
  1620.         return new Response(json_encode($result));
  1621.     }
  1622.     /**
  1623.      * @Route("/mailing_campaign/{mailingCampaignID}")
  1624.      */
  1625.     public function mailingCampaignAction($mailingCampaignID) {
  1626.         $entityManager $this->getDoctrine()->getManager();
  1627.         $mailingCampaignRepository $entityManager->getRepository(MailingCampaign::class);
  1628.         $mailingCampaign $mailingCampaignRepository->find($mailingCampaignID);
  1629.         if(!$mailingCampaign) {
  1630.             return $this->redirect("/");
  1631.         }
  1632.         $mailBody $mailingCampaign->getMailBody();
  1633.         $template $this->get('twig')->createTemplate($mailBody);
  1634.         return new Response($template->render([]));
  1635.     }
  1636.     public function sendOfferMessageFormAction(Request $request) {
  1637.         return $this->render(self::getMobileDevice($request) ?
  1638.             'Slivki/mobile/offer/create_own_offer.html.twig' 'Slivki/offers/send_offer_messsage.html.twig');
  1639.     }
  1640.     /**
  1641.      * @Route("/send_offer_message")
  1642.      */
  1643.     public function sendOfferMessage(Request $requestMailer $mailer) {
  1644.         $offerProposal = new OfferProposal();
  1645.         $offerProposal->setType(OfferProposal::PROPOSAL_TYPE);
  1646.         $offerProposal->setPhone($request->request->get('offerPhone'));
  1647.         $offerProposal->setEmail($request->request->get('offerEmail'));
  1648.         $offerProposal->setBuisnessName($request->request->get('offerBuisness'));
  1649.         $offerProposal->setOfferConditions($request->request->get('termsOfPromotion'));
  1650.         $subject 'NEW: Разместить акцию';
  1651.         $messageText '<b>Телефон:</b> ' $request->request->get('offerPhone') . '<br>'
  1652.             '<b>E-mail:</b> ' $request->request->get('offerEmail') . '<br>'
  1653.             '<b>Юр.лицо:</b> ' $request->request->get('offerBuisness') . '<br>'
  1654.             '<b>Условия акции:</b> ' $request->request->get('termsOfPromotion') . '<br>';
  1655.         $message $mailer->createMessage();
  1656.         $message->setSubject($subject)
  1657.             ->setFrom("info@slivki.by"'Slivki.by')
  1658.             ->setTo('info@slivki.by')
  1659.             ->setBody(
  1660.                 $messageText,
  1661.                 'text/html'
  1662.             );
  1663.         $mailer->send($message);
  1664.         try {
  1665.             $em $this->getDoctrine()->getManager();
  1666.             $em->persist($offerProposal);
  1667.             $em->flush();
  1668.         } catch (\Exception $e) {
  1669.             return new Response('Ваше сообщение успешно отправлено');
  1670.         }
  1671.         return new Response('Ваше сообщение успешно отправлено');
  1672.     }
  1673.     /**
  1674.      * @Route("/humorfm")
  1675.      */
  1676.     public function humorFM(Request $request) {
  1677.         if($this->getMobileDevice($request)){
  1678.             return $this->render('Slivki/mobile_humorfm.html.twig');
  1679.         } else{
  1680.             return $this->render('Slivki/humorfm.html.twig');
  1681.         }
  1682.     }
  1683.     /**
  1684.      * @Route("/subscribe/mobile")
  1685.      */
  1686.     public function subscribeForm(Request $request) {
  1687.         if ($this->getMobileDevice($request) and (!$this->getUser() or !$this->getUser()->getAcceptNewsletter())) {
  1688.             return $this->render('Slivki/subscribe_mobile.html.twig');
  1689.         } else {
  1690.             return $this->redirect("/");
  1691.         }
  1692.     }
  1693.     /**
  1694.      * @Route("/send-contact-form")
  1695.      */
  1696.     public function sendContactForm(Request $requestMailer $mailer) {
  1697.         $data = [
  1698.             'email' => $request->request->get('email'''),
  1699.             'name' => $request->request->get('name'''),
  1700.             'body' => $request->request->get('body''')
  1701.         ];
  1702.         $error '';
  1703.         if (!filter_var(trim($data['email'], FILTER_VALIDATE_EMAIL))) {
  1704.             $error .= 'Пожалуйста, введите Ваш E-Mail.<br>';
  1705.         }
  1706.         if (trim($data['body']) == '') {
  1707.             $error .= 'Пожалуйста, введите текст сообщения.<br>';
  1708.         }
  1709.         if ($error != '') {
  1710.             return new Response($error);
  1711.         }
  1712.         $recipientEmail = (strpos($request->headers->get('referer'), '/beznal')) ? 'beznal@slivki.by' 'info@slivki.by';
  1713.         $message $mailer->createMessage();
  1714.         $message->setSubject("Сообщение")
  1715.             ->setFrom("info@slivki.by"'Slivki.by')
  1716.             ->setTo($recipientEmail)
  1717.             ->setBody(
  1718.                 $this->renderView(
  1719.                     'Slivki/emails/contact_email.html.twig',
  1720.                     $data
  1721.                 ),
  1722.                 'text/html'
  1723.             );
  1724.         $mailer->send($message);
  1725.         return new Response();
  1726.     }
  1727.     /**
  1728.      * @Route("/contact-mail-result")
  1729.      */
  1730.     public function contactMailResult(Request $request) {
  1731.         $data['lastComments'] = $this->getDoctrine()->getRepository(Comment::class)->findBy(["hidden" => false], ["createdOn" => "desc"], 3);
  1732.         return $this->render(CommonUtil::isMobileDevice($request) ?
  1733.             'Slivki/mobile/info_pages/contacts_form_result.html.twig' 'Slivki/contact_mail_result.html.twig'$data);
  1734.     }
  1735.     /**
  1736.      * @Route("/readability_sale_stat")
  1737.      */
  1738.     public function readabilitySaleStat(Request $request) {
  1739.         $id $request->request->get('saleID');
  1740.         $timeOnPage $request->request->get('timeOnPage');
  1741.         $percentOfScrolling $request->request->get('percentOfScrolling');
  1742.         $userID $this->getUser();
  1743.         if ($userID) {
  1744.             $userID $this->getUser()->getID();
  1745.         }
  1746.         $pageHeight $request->request->get('pageHeight');
  1747.         $readPx $request->request->get('readPx');
  1748.         $date = new \DateTime();
  1749.         $readabilityStat = new ReadabilityStat();
  1750.         $readabilityStat->setEntityID($id);
  1751.         $readabilityStat->setPercentOfScrolling($percentOfScrolling);
  1752.         $readabilityStat->setTimeOnPage($timeOnPage);
  1753.         $readabilityStat->setCreatedOn($date);
  1754.         $readabilityStat->setUserID($userID);
  1755.         $readabilityStat->setPageHeight($pageHeight);
  1756.         $readabilityStat->setReadPx($readPx);
  1757.         $em $this->getDoctrine()->getManager();
  1758.         $em->persist($readabilityStat);
  1759.         $em->flush($readabilityStat);
  1760.         return new Response('');
  1761.     }
  1762.     /**
  1763.      * @Route("/jivo/hooks")
  1764.      */
  1765.     public function jivoHookAction(Request $request) {
  1766.         $data json_decode($request->getContent(), true);
  1767.         $logger Logger::instance('JIVO HOOK');
  1768.         $entityManager $this->getDoctrine()->getManager();
  1769.         $chatSession null;
  1770.         switch ($data['event_name']) {
  1771.             case 'chat_accepted':
  1772.                 $chatSession = new ChatSession();
  1773.                 $chatSession->setChatID($data['chat_id']);
  1774.                 $entityManager->persist($chatSession);
  1775.                 $chatSession->setOperatorEmail($data['agent']['email']);
  1776.                 $chatSession->setOperatorName($data['agent']['name']);
  1777.                 break;
  1778.             case 'chat_finished':
  1779.                 $chatSession $entityManager->getRepository(ChatSession::class)->findOneByChatID($data['chat_id']);
  1780.                 if (!$chatSession) {
  1781.                     $logger->info('Chat ' $data['chat_id'] . ' not found');
  1782.                     return new Response();
  1783.                 }
  1784.                 $chatSession->setFinishedOn(new \DateTime());
  1785.                 $chatHistory '';
  1786.                 foreach ($data['chat']['messages'] as $message) {
  1787.                     $chatHistory .= date('d.m.Y'$message['timestamp']) . '<br>';
  1788.                     $chatHistory .= ($message['type'] == 'agent' 'Консультант' 'Клиент') . '<br>';
  1789.                     $chatHistory .= $message['message'] . '<br><br>';
  1790.                 }
  1791.                 $chatSession->setChatHistory($chatHistory);
  1792.                 break;
  1793.             default:
  1794.                 return new Response();
  1795.         }
  1796.         if (!$chatSession->getUser() && isset($data['user_token'])) {
  1797.             $user $entityManager->getRepository(User::class)->find($data['user_token']);
  1798.             if ($user) {
  1799.                 $chatSession->setUser($user);
  1800.             } else {
  1801.                 $logger->info('User ' $data['user_token'] . ' not found');
  1802.             }
  1803.         }
  1804.         $entityManager->flush($chatSession);
  1805.         if ($data['event_name'] == 'chat_accepted') {
  1806.             $data['result'] = 'ok';
  1807.             $user $chatSession->getUser();
  1808.             if ($user) {
  1809.                 $data['custom_data'][0]['title'] = 'Баланс';
  1810.                 $data['custom_data'][0]['content'] = number_format($user->getFullBalance(), 2);
  1811.                 $data['contact_info']['name'] = $user->getFirstName();
  1812.                 $data['contact_info']['phone'] = $user->getPhone();
  1813.                 $data['contact_info']['email'] = $user->getEmail();
  1814.                 $data['contact_info']['description'] = '';
  1815.             }
  1816.             $response = new JsonResponse();
  1817.             $response->setCharset('UTF-8');
  1818.             $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
  1819.             $response->setData($data);
  1820.             return $response;
  1821.         }
  1822.         return new Response();
  1823.     }
  1824.     /**
  1825.      * @Route("/subscribe")
  1826.      */
  1827.     public function subscribeAction(Request $requestMailer $mailer) {
  1828.         $email mb_strtolower(trim($request->request->get('email')));
  1829.         $entityManager $this->getDoctrine()->getManager();
  1830.         $user $entityManager->getRepository(User::class)->loadUserByUsername($emailfalse);
  1831.         if ($user && ($user->getAcceptNewsletter() || $user->getID() == $this->getUser()->getID())) {
  1832.             if (!$user->getAcceptNewsletter()) {
  1833.                 $user->setAcceptNewsletter(true);
  1834.                 $entityManager->flush($user);
  1835.             }
  1836.             return new Response('0');
  1837.         }
  1838.         $subscriber $entityManager->getRepository(Subscriber::class)->findOneByEmail($email);
  1839.         if ($subscriber && $subscriber->getConfirmationCode() == '') {
  1840.             return new Response('0');
  1841.         }
  1842.         if (!$subscriber) {
  1843.             $validator $this->get('validator');
  1844.             $emailConstraint = new Email();
  1845.             if ($email == '' || $validator->validate($email$emailConstraint) != '') {
  1846.                 return new Response('1');
  1847.             }
  1848.             $subscriber = new Subscriber();
  1849.             $subscriber->setEmail($email);
  1850.             $entityManager->persist($subscriber);
  1851.             $confirmationCode md5($subscriber->getID() . $subscriber->getEmail());
  1852.             $subscriber->setConfirmationCode($confirmationCode);
  1853.             $entityManager->flush($subscriber);
  1854.         }
  1855.         $messageBody $this->get('twig')->render('Slivki/emails/confirm_email.html.twig', ['confirmationCode' => $subscriber->getConfirmationCode()]);
  1856.         $message $mailer->createMessage('Вы станете богаче!'$messageBody'text/html')->addTo($email)->addFrom('info@slivki.by');
  1857.         $mailer->send($message);
  1858.         return new Response('2');
  1859.     }
  1860.     /**
  1861.      * @Route("/confirm/email/{confirmationCode}")
  1862.      */
  1863.     public function confirmEmailAction($confirmationCode) {
  1864.         $confirmationCode pg_escape_string($confirmationCode);
  1865.         $entityManager $this->getDoctrine()->getManager();
  1866.         $sql "select id, email from subscriber where md5(id::text || email) = '$confirmationCode'";
  1867.         $subscriber $entityManager->getConnection()->executeQuery($sql)->fetch();
  1868.         if (!$subscriber) {
  1869.             $this->addFlash(self::SHOW_INFO_DIALOG_PARAMETER'Пользователь не найден');
  1870.             return $this->redirect(CityRepository::$mainPageURL);
  1871.         }
  1872.         $user $entityManager->getRepository(User::class)->loadUserByUsername($subscriber['email'], false);
  1873.         if ($user) {
  1874.             $user->setAcceptNewsletter(true);
  1875.             $entityManager->flush($user);
  1876.             $entityManager->getConnection()->executeQuery("delete from subscriber where id = $subscriber[id]");
  1877.         } else {
  1878.             $entityManager->getConnection()->executeQuery("update subscriber set confirmation_code = '' where id = $subscriber[id]");
  1879.         }
  1880.         $this->addFlash(self::SHOW_INFO_DIALOG_PARAMETER'Вы успешно подписаны на рассылку');
  1881.         return $this->redirect(CityRepository::$mainPageURL);
  1882.     }
  1883.     /**
  1884.      * @Route("/oplata-promokoda-azs")
  1885.      */
  1886.     public function getGasStationCode(
  1887.         Request $request,
  1888.         OfferCacheService $offerCacheService,
  1889.         SubscriptionService $subscriptionService
  1890.     ): Response {
  1891.         $entityManager $this->getDoctrine()->getManager();
  1892.         $user $this->getUser();
  1893.         $userID $user->getID();
  1894.         $offerID Offer::PETROL_OFFER_ID;
  1895.         $sql "select id from offer_order where user_id = $userID and offer_id = $offerID order by id DESC limit 1";
  1896.         $orderID $entityManager->getConnection()->executeQuery($sql)->fetchColumn();
  1897.         if ($orderID) {
  1898.             $entityOption$entityManager->getRepository(EntityOption::class)->findBy(['entityID' => $orderID]);
  1899.             foreach ($entityOption as $val) {
  1900.                 switch ($val->getName()) {
  1901.                     case "car_model":
  1902.                         $data['carModel'] = $val->getValue();
  1903.                         break;
  1904.                     case "car_number":
  1905.                         $data['carNumber'] = $val->getValue();
  1906.                         break;
  1907.                     case "phone_number":
  1908.                         $data['phoneNumber'] = $val->getValue();
  1909.                         break;
  1910.                 }
  1911.             }
  1912.         }
  1913.         $data['offerID'] = Offer::PETROL_OFFER_ID;
  1914.         $offerRepository $this->getOfferRepository();
  1915.         $offer $offerCacheService->getOffer(Offer::PETROL_OFFER_ID);
  1916.         $data['codeCost'] = $offerRepository->getCodeCost($offer);
  1917.         $data['freeCodesCount'] = $offer->getFreeCodesCount();
  1918.         $data['freeCode'] = $offerRepository->isOfferFreeForUser($offer$this->getUser());
  1919.         $data['useBalance'] =  $this->getUser()->getFullBalance() >= $offerRepository->getCodeCost($offer);
  1920.         $userPhone $user->getCurrentPhone();
  1921.         if ($userPhone) {
  1922.             $data['phoneNumber'] = $userPhone->getPhoneNumber();
  1923.         }
  1924.         $siteSettings $this->getSiteSettings();
  1925.         $data['subscriptionPrice'] = $subscriptionService->isSubscriptionFinished($user)
  1926.             ? $siteSettings->getSubscriptionPrice()
  1927.             : $siteSettings->getSubscriptionFirstPayment();
  1928.         $data['subscriptionFullPrice'] = $siteSettings->getSubscriptionPrice();
  1929.         $subscription $subscriptionService->getSubscription($user);
  1930.         $data['allowedCodesCountBySubscription'] = $subscriptionService->isSubscriber($user)
  1931.             ? $subscription->getNumberOfCodes()
  1932.             : 0;
  1933.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/payment/fuel.html.twig'
  1934.             'Slivki/offers/get_code_for_gas_station.html.twig'$data);
  1935.     }
  1936.     /**
  1937.      * @Route("/get_offer_comment_medias_list")
  1938.      */
  1939.     public function getOfferCommentMediasList(Request $request) {
  1940.         $entityID $request->request->get('entityID');
  1941.         $entityType $request->request->get('entityType');
  1942.         $offset $request->request->get('offset');
  1943.         $limit $request->request->get('limit');
  1944.         switch ($entityType) {
  1945.             case 'category':
  1946.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaListByCategoryID($entityID$offset$limit);
  1947.                 break;
  1948.             case 'offer':
  1949.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaListByOfferID($entityID$offset$limit);
  1950.                 break;
  1951.             case 'all':
  1952.                 $data['commentAndMediaList'] = $this->getMediaRepository()->getOfferCommentMediaList($offset$limit);
  1953.                 break;
  1954.         }
  1955.         return $this->render('Slivki/comments/media_block_list.html.twig'$data);
  1956.     }
  1957.     /**
  1958.      * @Route("/get_top_comment_list")
  1959.      */
  1960.     public function getTopCommentList(Request $request) {
  1961.         $offset $request->request->get('offset');
  1962.         $limit $request->request->get('limit');
  1963.         $data['commentList'] = $this->getCommentRepository()->findBy(['checked' => true'rating' => 5], ['ID' => 'DESC'], $limit$offset);
  1964.         return $this->render('Slivki/category_dividers/comment_list.html.twig'$data);
  1965.     }
  1966.     /** @Route("/ne-nashli-chto-iskali") */
  1967.     public function lookingForAction(Request $request) {
  1968.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/looking_for.html.twig' 'Slivki/looking_for.html.twig');
  1969.     }
  1970.     /** @Route("/send-looking-for") */
  1971.     public function sendLookingForAction(Request $requestMailer $mailer) {
  1972.         if (!$request->getMethod('POST')) {
  1973.             return new Response();
  1974.         }
  1975.         $message $mailer->createMessage();
  1976.         $mailBody "<b>Текст:</b><br>"
  1977.             $request->request->get('text')
  1978.             . "<br><br><b>Email:</b><br>"
  1979.             $request->request->get('email')
  1980.             . "<br><br><b>Телефон:</b><br>"
  1981.             $request->request->get('phone');
  1982.         $message->setSubject("Не нашли, что искали")
  1983.             ->setFrom('info@slivki.by''Slivki.by')
  1984.             ->setTo('info@slivki.by')
  1985.             ->setBody($mailBody'text/html');
  1986.         $mailer->send($message);
  1987.         return new Response();
  1988.     }
  1989.     /**
  1990.      * @Route("/get_sidebar")
  1991.      */
  1992.     public function getSidebar(SlivkiTwigExtension $extension) {
  1993.         return new Response($extension->getSidebar($this->get('twig')));
  1994.     }
  1995.     /**
  1996.      * @Route("/get_sidebar_item_list")
  1997.      */
  1998.     public function getSidebarItemListContent(
  1999.         Request $request,
  2000.         SidebarCacheService $sidebarCacheService
  2001.     ): Response {
  2002.         $offset $request->request->get('offset'0);
  2003.         $length $request->request->get('length'20);
  2004.         $sidebarCached $sidebarCacheService->getSidebarCached();
  2005.         if (null === $sidebarCached) {
  2006.             return new Response('');
  2007.         }
  2008.         $sidebarItemList array_slice($sidebarCached->getItemList(), $offset$length);
  2009.         if (empty($sidebarItemList)) {
  2010.             return new Response('');
  2011.         }
  2012.         $sidebarContent implode(''$sidebarItemList);
  2013.         return new Response($sidebarContent);
  2014.     }
  2015.     /**
  2016.      * @Route("/widget/{alias}")
  2017.      * @Route("/widget/map/{alias}")
  2018.      */
  2019.     public function widgetMapTireAction($alias) {
  2020.         $softCache = new SoftCache('tire-widget');
  2021.         $result $softCache->get($alias);
  2022.         if ($result) {
  2023.             return new Response($result);
  2024.         }
  2025.         $offers null;
  2026.         if ($alias == 'map_tire') {
  2027.             $offers $this->getOfferRepository()->getActiveOffersByCategoryIDNoCache(492);
  2028.         }
  2029.         if (!$offers) {
  2030.             $seo $this->getSeoRepository()->getByAlias('/' $alias);
  2031.             if (!$seo) {
  2032.                 return new Response();
  2033.             }
  2034.             switch ($seo->getResourceURL()) {
  2035.                 case SeoRepository::RESOURCE_URL_OFFER_CATEGORY:
  2036.                     $offers $this->getOfferRepository()->getActiveOffersByCategoryID($seo->getEntityID());
  2037.                     break;
  2038.                 case SeoRepository::RESOURCE_URL_OFFER_DETAILS:
  2039.                     $offer $this->getOfferRepository()->getAnyWay($seo->getEntityID());
  2040.                     if ($offer) {
  2041.                         $offers[] = $offer;
  2042.                     }
  2043.             }
  2044.         }
  2045.         if (!$offers || count($offers) == 0) {
  2046.             return new Response();
  2047.         }
  2048.         $result = [];
  2049.         $i 0;
  2050.         $seoRepository $this->getSeoRepository(Seo::class);
  2051.         foreach($offers as $offer) {
  2052.             if (!$offer) {
  2053.                 continue;
  2054.             }
  2055.             $geoLocations $offer->getGeoLocations();
  2056.             foreach ($geoLocations as $geoLocation) {
  2057.                 $geoLocationInfos['markerAnnotation'] = $geoLocation->getDescription();
  2058.                 $geoLocationInfos['latitude'] = $geoLocation->getLatitude();
  2059.                 $geoLocationInfos['longitude'] = $geoLocation->getLongitude();
  2060.                 $result[$i]['geoLocationInfos'][] = $geoLocationInfos;
  2061.                 $seo $seoRepository->getByEntity('Slivki:Default:details'$offer->getID());
  2062.                 $url '';
  2063.                 if ($seo) {
  2064.                     $url $seo->getMainAlias();
  2065.                 }
  2066.                 $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>";
  2067.                 $i++;
  2068.             }
  2069.         }
  2070.         $result $this->renderView('Slivki/widget/map_tire.html.twig', ['placemarkList' => $result]);
  2071.         $softCache->set($alias$result12 60 60);
  2072.         return new Response($result);
  2073.     }
  2074.     /** @Route("/get_sidebar_banner/{cityID}") */
  2075.     public function getSidebarBanner(BannerService $bannerService$cityID) {
  2076.         $cityID = (int)$cityID;
  2077.         if (!$cityID) {
  2078.             $cityID City::DEFAULT_CITY_ID;
  2079.         }
  2080.         return new JsonResponse($bannerService->getSidebarBannerCached($cityID));
  2081.     }
  2082.     /** @Route("/log/browser") */
  2083.     public function browserLogAction(Request $request) {
  2084.         Logger::instance('BrowserLog')->info($request->request->get('message'));
  2085.         return new Response();
  2086.     }
  2087.     /** @Route("/category/filter/map/{categoryID}") */
  2088.     public function categoryMapFilterAction(Request $requestCacheService $cacheService$categoryID) {
  2089.         ini_set('memory_limit''512M');
  2090.         $offerIDList $request->request->get('offerList', []);
  2091.         $teaserList $cacheService->getTeaserList($offerIDListCommonUtil::isMobileDevice($request));
  2092.         $result = ['html' => '''count' => 0];
  2093.         if ($teaserList) {
  2094.             $data = ['offerList' => array_values($teaserList), 'offersInARow' => self::getMobileDevice($request) ? 3];
  2095.             $result = [
  2096.                 'html' => $this->get('twig')->render('Slivki/offers/teasers.html.twig'$data),
  2097.                 'count' => count($teaserList)
  2098.             ];
  2099.         }
  2100.         return new JsonResponse($result);
  2101.     }
  2102.     /** @Route("/category/location-info/{categoryID}/{limit}/{offset}") */
  2103.     public function getLocationInfoAction($categoryID$limit$offset) {
  2104.         $offerGeoLocationCache = new SoftCache(OfferRepository::CACHE_NAME_GEO_LOCATION_DATA);
  2105.         $features $offerGeoLocationCache->get($categoryID, []);
  2106.         if (!$features) {
  2107.             $features = [];
  2108.         }
  2109.         $features array_slice($features$offset$limit);
  2110.         if (empty($features)) {
  2111.             return new Response(json_encode([]));
  2112.         }
  2113.         $getLocationData = ['type' => 'FeatureCollection''features' => $features];
  2114.         return new Response(json_encode($getLocationData));
  2115.     }
  2116.     /** @Route("/top500") */
  2117.     public function topAction() {
  2118.         $data['infoPage'] = new InfoPage();
  2119.         $data['text'] = $data['infoPage']->getContent();
  2120.         return $this->render('Slivki/pages/pages.html.twig'$data);
  2121.     }
  2122.     /** @Route("/category/get_supplier_address_tab/{directorID}") */
  2123.     public function getSupplierAddressTab(Request $request$directorID) {
  2124.         $entityManager $this->getDoctrine()->getManager();
  2125.         $director $entityManager->getRepository(Director::class)->find($directorID);
  2126.         if (!$director) {
  2127.             return new Response();
  2128.         }
  2129.         $directorUniqueGeoLocations = [];
  2130.         /** @var Offer $offer */
  2131.         foreach ($director->getOffers() as $offer) {
  2132.             if (!$offer->isActive() || !$offer->isInActivePeriod()) {
  2133.                 continue;
  2134.             }
  2135.             /** @var GeoLocation $geoLocation */
  2136.             foreach ($offer->getGeoLocations() as $geoLocation) {
  2137.                 $isUniqueGeoLoation true;
  2138.                 /** @var GeoLocation $uniqueGeoLocation */
  2139.                 foreach ($directorUniqueGeoLocations as $uniqueGeoLocation) {
  2140.                     if ($geoLocation->getCity() == $uniqueGeoLocation->getCity() && $geoLocation->getStreet() == $uniqueGeoLocation->getStreet()
  2141.                         && $geoLocation->getHouse() == $uniqueGeoLocation->getHouse()) {
  2142.                         $isUniqueGeoLoation false;
  2143.                         break;
  2144.                     }
  2145.                 }
  2146.                 if ($isUniqueGeoLoation) {
  2147.                     $directorUniqueGeoLocations[] = $geoLocation;
  2148.                 }
  2149.             }
  2150.         }
  2151.         $data['geoLocationList'] = $directorUniqueGeoLocations;
  2152.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/offer/supplier_address_tab.html.twig'
  2153.             'Slivki/offers/supplier_address_tab.html.twig'$data);
  2154.     }
  2155.     /** @Route("/category/get_supplier_photoguide_tab/{directorID}") */
  2156.     public function getSupplierPhotoguideTab($directorID) {
  2157.         $entityManager $this->getDoctrine()->getManager();
  2158.         $director $entityManager->getRepository(Director::class)->find($directorID);
  2159.         if (!$director) {
  2160.             return new Response();
  2161.         }
  2162.         $teaserList = [];
  2163.         $saleRepository $this->getSaleRepository();
  2164.         /** @var Sale $sale */
  2165.         foreach ($director->getSales() as $sale) {
  2166.             $saleCached $saleRepository->findCached($sale->getID());
  2167.             $teaserList[] = $this->renderView('Slivki/sale/teaser.html.twig', ['sale' => $saleCached]);
  2168.         }
  2169.         $data['teaserList'] = $teaserList;
  2170.         return $this->render('Slivki/offers/supplier_photoguide_tab.html.twig'$data);
  2171.     }
  2172.     /** @Route("/get-sorted-sidebar") */
  2173.     public function getSortedSidebar(Request $request) {
  2174.         if (!$request->isMethod(Request::METHOD_POST)) {
  2175.             return $this->redirectToRoute('homepage');
  2176.         }
  2177.         $requestParameters $request->request->all();
  2178.         if (!isset($requestParameters['sortBy'])) {
  2179.             $requestParameters['sortBy'] = 'default';
  2180.         }
  2181.         $categoryID $requestParameters['categoryID'] ? $requestParameters['categoryID'] : null;
  2182.         $coordinates $requestParameters['coordinates'] != '' explode(','$requestParameters['coordinates']) : null;
  2183.         $sortedSaleIDList $this->getSaleRepository()->getSaleIDSorted(
  2184.             $requestParameters['sortBy'], $categoryID$requestParameters['offset'],
  2185.             $requestParameters['limit'], $coordinates);
  2186.         $softCache = new SoftCache(SaleRepository::CACHE_NAME);
  2187.         $sortedSaleList $softCache->getMulti($sortedSaleIDList);
  2188.         if (!is_array($sortedSaleList)) {
  2189.             $sortedSaleList = [];
  2190.         }
  2191.         $sidebarContent '';
  2192.         foreach ($sortedSaleList as $sale) {
  2193.             if (!$sale) {
  2194.                 continue;
  2195.             }
  2196.             $sidebarContent .= $this->renderView('Slivki/sidebar/sale_teaser.html.twig', ['sale' => $sale]);
  2197.         }
  2198.         return new Response($sidebarContent);
  2199.     }
  2200.     /** @Route("/offer/food-extension-order") */
  2201.     public function offerFoodExtensionOrder(Request $request) {
  2202.         if (!self::getMobileDevice($request)) {
  2203.             return $this->redirectToRoute('homepage');
  2204.         }
  2205.         return $this->render('Slivki/offers/food_extension/mobile/order.html.twig');
  2206.     }
  2207.     /** @Route("/offer/food-extension-order-confirm") */
  2208.     public function offerFoodExtensionOrderConfirm(Request $request) {
  2209.         if (!self::getMobileDevice($request)) {
  2210.             return $this->redirectToRoute('homepage');
  2211.         }
  2212.         return $this->render('Slivki/offers/food_extension/mobile/order_confirm.html.twig');
  2213.     }
  2214.     /** @Route("/food-order/check/{orderID}") */
  2215.     public function checkFoodOrderStateActioin($orderID) {
  2216.         $order $this->getDoctrine()->getManager()->find(FoodOrder::class, $orderID);
  2217.         if (!$order || $order->getStatus() != OfferOrder::STATUS_INIT) {
  2218.             return new Response('paid');
  2219.         }
  2220.         return new Response();
  2221.     }
  2222.     /** @Route("/offer_supplier_image/{offerID}/{limit}/{offset}") */
  2223.     public function getOfferSupplierSliderAction(CacheService $cacheService$offerID$limit$offset) {
  2224.         $supplierOfferPhotoList $cacheService->getMediaList($offerIDMedia\OfferSupplierPhotoMedia::TYPE$offset$limit);
  2225.         if (empty($supplierOfferPhotoList)) {
  2226.             return new Response('');
  2227.         }
  2228.         return $this->render('Slivki/comments/offer_supplier_photos.html.twig',
  2229.             ['supplierOfferPhotoList' => $supplierOfferPhotoList]);
  2230.     }
  2231.     /** @Route("/location/confirm/test") */
  2232.     public function testLocationConfirmAction(Request $request) {
  2233.         $request->request->set('showLocationConfirm'true);
  2234.         return $this->indexAction($request);
  2235.     }
  2236.     /**
  2237.      * @Route("/dreamland-registration/{code}")
  2238.      */
  2239.     public function dreamlandPartnerAction(Request $request$code) {
  2240.         $entityManager $this->getDoctrine()->getManager();
  2241.         $entityOptionRepository $entityManager->getRepository(EntityOption::class);
  2242.         $partnerCode $entityOptionRepository->findOneBy([
  2243.             'entityTypeID' => null,
  2244.             'name' => EntityOption::OPTION_DREAMLAND_PARTNER,
  2245.             'value' => $code
  2246.         ]);
  2247.         if (!$partnerCode) {
  2248.             return $this->redirect('/');
  2249.         }
  2250.         if ($this->getUser()) {
  2251.             $option $entityOptionRepository->findOneBy([
  2252.                 'entityTypeID' => EntityOption::USER_TYPE,
  2253.                 'name' => EntityOption::OPTION_DREAMLAND_PARTNER,
  2254.                 'entityID' => $this->getUser()->getID()
  2255.             ]);
  2256.             if (!$option) {
  2257.                 $option = new EntityOption();
  2258.                 $option->setEntityTypeID(EntityOption::USER_TYPE);
  2259.                 $option->setEntityID($this->getUser()->getID());
  2260.                 $option->setName(EntityOption::OPTION_DREAMLAND_PARTNER);
  2261.                 $option->setValue($code);
  2262.                 $entityManager->persist($option);
  2263.                 $entityManager->flush();
  2264.             }
  2265.             return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2266.         }
  2267.         $request->getSession()->set(EntityOption::OPTION_DREAMLAND_PARTNER$code);
  2268.         if (CommonUtil::isMobileDevice($request)) {
  2269.             return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2270.         }
  2271.         return $this->redirect($entityManager->getRepository(Seo::class)->getOfferURL(Offer::DREAMLAND_OFFER_ID)->getMainAlias());
  2272.     }
  2273.     /** @Route("/newadformat") */
  2274.     public function newAdFormatActioin() {
  2275.         return $this->render('Slivki/newadformat/index.html.twig');
  2276.     }
  2277.     public function domainPlaceHolderAction(Request $request$entityID) {
  2278.         $offer $this->getDoctrine()->getManager()->find(Offer::class, $entityID);
  2279.         $director $offer->getDirectors()->first();
  2280.         return $this->render(CommonUtil::isMobileDevice($request) ? 'Slivki/m/mobile/index.html.twig' 'Slivki/m/index.html.twig', ['director' => $director]);
  2281.     }
  2282.     /** @Route("/email-test") */
  2283.     public function emailTestAction(Mailer $mailer) {
  2284.         $message $mailer->createMessage('test''test');
  2285.         $message->addTo('igoradv@gmail.com');
  2286.         $message->setFrom('info@slivki.by''Slivki.by');
  2287.         $mailer->send($message);
  2288.         return new Response('sent');
  2289.     }
  2290.     /** @Route("/prilozhenie-skidok", name = "mobileApp") */
  2291.     public function appPageAction(Request $request) {
  2292.         $view CommonUtil::isMobileDevice($request) ? 'Slivki/mobile/mobile_app.html.twig' 'Slivki/mobile_app.html.twig';
  2293.         return $this->render($view);
  2294.     }
  2295.     /** @Route("/betera-advent") */
  2296.     public function beteraAdventCalendar(Request $request) {
  2297.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/betera_advent/base.html.twig' 'Slivki/betera_advent/base.html.twig');
  2298.     }
  2299.     /** @Route("/profile/oplata-pay") */
  2300.     public function balanceWirtuallWallet(Request $request) {
  2301.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/payment/slivki_pay/index.html.twig' 'Slivki/payment/slivki_pay/index.html.twig');
  2302.     }
  2303.     /** @Route("/virtual-wallet-pay") */
  2304.     public function balanceWirtuallWalletQuery(Request $request) {
  2305.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/payment/slivki_pay/wirtualWallet.html.twig' 'Slivki/payment/slivki_pay/wirtualWallet.html.twig');
  2306.     }
  2307.     /** @Route("/callback") */
  2308.     public function callbackRequest(Request $request) {
  2309.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/callback/index.html.twig' 'Slivki/callback/index.html.twig');
  2310.     }
  2311.     /** @Route("/profile/transfer-balance") */
  2312.     public function transferBalanceIsNotSlivkiPay(Request $request) {
  2313.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/transfer_balance/index.html.twig' 'Slivki/transfer_balance/index.html.twig');
  2314.     }
  2315.     /** @Route("/bonuses") */
  2316.     public function getBonusesPartner(Request $request) {
  2317.         return $this->render(self::getMobileDevice($request) ? 'Slivki/mobile/bonuses_partner/index.html.twig' 'Slivki/bonuses_partner/index.html.twig');
  2318.     }
  2319.     /** @Route("/error/{statusCode}") */
  2320.     public function errorAction($statusCode): Response {
  2321.         return new Response(''$statusCode);
  2322.     }
  2323. }