src/Controller/DefaultController.php line 2482

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