src/WebBundle/Controller/PageController.php line 55

Open in your IDE?
  1. <?php
  2. namespace WebBundle\Controller;
  3. use AdmBundle\Helper\Adm;
  4. use Exception;
  5. use FlexApp\Helper\GeoHelper;
  6. use FlexApp\Helper\MetaHelper;
  7. use FlexApp\Repository\CountryAndLangSpecificDataRepository;
  8. use FlexApp\Service\CalendarService;
  9. use FlexApp\Service\CommentablePageDataProvider;
  10. use FlexApp\Service\ConsDataForContactsPageProvider;
  11. use FlexApp\Service\TimeFormatTransformer;
  12. use FlexApp\Service\TimezoneManager;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  18. use WebBundle\Entity\Factory;
  19. use WebBundle\Entity\IdeasShare;
  20. use WebBundle\Entity\ListCountry;
  21. use WebBundle\Helper\App;
  22. use WebBundle\Helper\ArrHelper;
  23. use WebBundle\Helper\CalendarHelper;
  24. use WebBundle\Helper\LocaleHelper;
  25. use WebBundle\Helper\TwilioHelper;
  26. use WebBundle\Helper\UserHelper;
  27. use WebBundle\Repository\FactoryRepository;
  28. use WebBundle\Repository\IdeasShareRepository;
  29. use WebBundle\Repository\ListCountryRepository;
  30. use WebBundle\Repository\StaticPageRepository;
  31. class PageController extends ExtendedController
  32. {
  33.     /** @required */
  34.     public ListCountryRepository $listCountryRepository;
  35.     /** @required */
  36.     public StaticPageRepository $staticPageRepository;
  37.     /** @required */
  38.     public IdeasShareRepository $ideasShareRepository;
  39.     /** @required */
  40.     public CountryAndLangSpecificDataRepository $countryAndLangSpecificDataRepository;
  41.     /** @required */
  42.     public FactoryRepository $factoryRepository;
  43.     /**
  44.      * @param string $url
  45.      * @param null $type
  46.      *
  47.      * @return Response
  48.      *
  49.      * @throws Exception
  50.      */
  51.     public function indexAction(string $url$type null)
  52.     {
  53.         $lc App::getCurLocale();
  54.         $cn App::getCurCountry();
  55.         // логика под варианты с группами стран. Редиректим от прямых ссылок
  56.         // https://te2.remote.team/discus/5E802239-CA11-A3D8-6A54-C25E8F7C58A5
  57.         if (preg_match('#(.*)-(rf|eu|eact|usca|new)$#isUu'$url$m)) {
  58.             return new RedirectResponse(App::generateUrl('app_page', ['url' => $m[1]]), 301);
  59.         }
  60.         $rfCns = ['ru'];
  61.         // проставляем префикс для тематических страниц
  62.         $urlAlt null;
  63.         if (in_array($cn$rfCns) and in_array($url, ['payment''conditions''policy-personal-data-process'])) {
  64.             $urlAlt $url '-rf';
  65.         }
  66.         // переадрессовал на переделанную страницу оплаты и доставки
  67.         if ($url == 'payment') {
  68.             $urlAlt 'payment-new';
  69.         }
  70.         if (null !== $type and 'career' == $type) {
  71.             $lc 'ru';
  72.             $cn 'ru';
  73.             $indexHtml '@Web/Vacancy/Page/index.html.twig';
  74.         } else {
  75.             $indexHtml '@Web/Page/index.html.twig';
  76.         }
  77.         $page null;
  78.         // ищем сначала тематическую страницу
  79.         if ($urlAlt) {
  80.             $page $this->staticPageRepository->getPage($urlAlt$lc$cn);
  81.         }
  82.         // отдаем стандартную страницу для если тематическая не готова
  83.         if (!$page) {
  84.             $page $this->staticPageRepository->getPage($url$lc$cn);
  85.         }
  86.         if (!$page) {
  87.             throw new NotFoundHttpException('Not found.');
  88.         }
  89.         $page['body'] = LocaleHelper::fixLink($page['body']);
  90.         $metaManager MetaHelper::getManager($page);
  91.         $this->addIdAndUnidOfStaticPageToReact($page);
  92.         return $this->render($indexHtml, [
  93.             'page' => $page,
  94.             '_country' => $cn,
  95.             'linkEdit' => Adm::linkEdit('adm.static.page.edit'$page['id']),
  96.             'meta' => [
  97.                 'title' => $metaManager->getTitle($lc),
  98.                 'description' => $metaManager->getDescription($lc),
  99.                 'keywords' => $metaManager->getKeywords($lc),
  100.             ],
  101.         ]);
  102.     }
  103.     /**
  104.      * @deprecated
  105.      */
  106.     public function saveClickIdeaShareToSocialAction(Request $request): Response
  107.     {
  108.         $response = [
  109.             'link' => $request->request->get('link'null),
  110.             'url' => $request->request->get('url'null),
  111.             'soc' => $request->request->get('social'null),
  112.             'ideaId' => $request->request->get('ideaId'null),
  113.             'token' => UserHelper::getInstance()->getToken(),
  114.         ];
  115.         $share = new IdeasShare($response);
  116.         $this->ideasShareRepository->save($share);
  117.         $clickIdeaShareToSocialCount $this->ideasShareRepository->getClickIdeaShareToSocialCount($response);
  118.         return new Response($clickIdeaShareToSocialCount ?: 'nodata');
  119.     }
  120.     public function contactsAction(): Response
  121.     {
  122.         $localeNames LocaleHelper::$localesName;
  123.         // available and sorted locales
  124.         $locales LocaleHelper::getListCode();
  125.         $locale App::getCurLocale();
  126.         $locale in_array($locale$locales) ? $locale 'en';
  127.         $locales array_diff($locales, [$locale => $locale]);
  128.         $data compact('localeNames''locale''locales');
  129.         $data['showChat'] = 1;
  130.         $countries $this->listCountryRepository->getListForLocalize();
  131.         $data['country'] = $this->translate('country.other');
  132.         $data['countryEntity'] = App::getCurCountryEntity();
  133.         $countryEntity $data['countryEntity'];
  134.         if (!$countryEntity) {
  135.             throw new Exception(sprintf('Не найдена страна "%s" в базе'App::getCountryCode()));
  136.         }
  137.         $userCountry $countryEntity->getCode();
  138.         /** @var ListCountry $country */
  139.         foreach ($countries as $country) {
  140.             if ($country['code'] == $userCountry) {
  141.                 $data['country'] = $this->translate($country['alias']);
  142.                 break;
  143.             }
  144.         }
  145.         //для выпадающего списка смены страны
  146.         $countryList App::getCountryList();
  147.         //Сортируем страны по имени в текущей локали
  148.         uasort($countryList, function ($a$b) {
  149.             return $a['name'] <=> $b['name'];
  150.         });
  151.         $data['countryList'] = $countryList;
  152.         $code App::getCurCountry();
  153.         $availableLanguages ArrHelper::get($data['countryList'], "{$code}.localesArr");
  154.         if (false === array_search('en'$availableLanguages ?? [])) {
  155.             $availableLanguages[] = 'en';
  156.         }
  157.         $data['availableLanguages'] = $data['countryList'][App::getCurCountry()]['localesArr'] ?? ['en'];
  158.         // определяем потдержку браузером WebRTC
  159.         $data['xRPC'] = TwilioHelper::detectWebRTC();
  160.         // =========================
  161.         $data['calendar'] = CalendarHelper::findClosestHolidaysInCalendar();
  162.         $data['capital'] = GeoHelper::country()->getCurCapital() ?: '';
  163.         $data['lang'] = App::getCurLocale();
  164.         $data['countryCode'] = App::getCurCountry();
  165.         $dataEntity $this
  166.             ->countryAndLangSpecificDataRepository
  167.             ->getDataEntityByCountryAndLang($countryEntityApp::getCurLocale());
  168.         $data['phone'] = $dataEntity->getPhone();
  169.         $data['email'] = $dataEntity->getEmail();
  170.         $data['startDay'] = $dataEntity->getStartDay();
  171.         $data['endDay'] = $dataEntity->getEndDay();
  172.         $data['startHour'] = $dataEntity->getStartHour() . ':00';
  173.         $data['endHour'] = $dataEntity->getEndHour() . ':00';
  174.         $data['twilioId'] = $dataEntity->getTwilioId();
  175.         $data['time'] = $data['startHour'] . ' - ' $data['endHour'];
  176.         $monday 1;
  177.         $saturday 6;
  178.         /** @var TimezoneManager $timezoneManager */
  179.         $timezoneManager App::getContainer()->get(TimezoneManager::class);
  180.         $data['workDaysTime'] = $timezoneManager->getTimeWithDiff($dataEntity->getTime($monday'start')) . ' - ' $timezoneManager->getTimeWithDiff($dataEntity->getTime($monday'end'));
  181.         $data['weekendDaysTime'] = $timezoneManager->getTimeWithDiff($dataEntity->getTime($saturday'start')) . ' - ' $timezoneManager->getTimeWithDiff($dataEntity->getTime($saturday'end'));
  182.         $data['weekendIsOnline'] = isset($dataEntity->getWorkDays()[$saturday]);
  183.         $data['isUnionWorkDaysAndWeekend'] = ($data['workDaysTime'] === $data['weekendDaysTime']) && $data['weekendIsOnline'];
  184.         if ($data['isUnionWorkDaysAndWeekend']) {
  185.             $data['unionTime'] = $timezoneManager->getTimeWithDiff($dataEntity->getTime($monday'start')) . ' - ' $timezoneManager->getTimeWithDiff($dataEntity->getTime($saturday'end'));
  186.         }
  187.         /** @var TimeFormatTransformer $timeFormatTransformer */
  188.         $timeFormatTransformer $this->container->get(TimeFormatTransformer::class);
  189.         $data['time'] = $timeFormatTransformer->transform($data['time'], App::getCurCountry(), App::getCurLocale());
  190.         /** @var ConsDataForContactsPageProvider $consDataProvider */
  191.         $consDataProvider $this->container->get(ConsDataForContactsPageProvider::class);
  192.         $data['avapath'] = $consDataProvider->getAvaUrl();
  193.         $data['consAlias'] = $consDataProvider->getAlias();
  194.         $metaManager MetaHelper::getManager($data);
  195.         $data['meta'] = [
  196.             'title' => $metaManager->getTitle(),
  197.             'description' => $metaManager->getDescription(),
  198.             'keywords' => $metaManager->getKeywords(),
  199.         ];
  200.         $calendarService $this->get(CalendarService::class);
  201.         $holidays = [
  202.             'holidaysString' => $calendarService->getHolidaysString(CalendarHelper::HOLIDAY_TYPE),
  203.             'halfHolidaysString' => $calendarService->getHolidaysString(CalendarHelper::HALF_HOLIDAY_TYPE),
  204.         ];
  205.         return $this->render('contacts/contacts.html.twig'array_merge($data$holidays));
  206.     }
  207.     /**
  208.      * Вывод всех фабрик со статусами для портала или 1с
  209.      *
  210.      * @return JsonResponse
  211.      */
  212.     public function getAllFactoryAction(): JsonResponse
  213.     {
  214.         $factories $this->factoryRepository->findAll();
  215.         $arr = [];
  216.         /** @var Factory $factor */
  217.         foreach ($factories as $factor) {
  218.             $arr[] = [
  219.                 'id' => $factor->getId(),
  220.                 'name' => $factor->getName(),
  221.                 'status' => $factor->getStatus(),
  222.             ];
  223.         }
  224.         $response = new JsonResponse($arr);
  225.         $response->setCache([
  226.             'max_age' => 600,
  227.             's_maxage' => 600,
  228.             'public' => true,
  229.         ]);
  230.         return $response;
  231.     }
  232.     /**
  233.      * @param $page
  234.      * @throws Exception
  235.      */
  236.     private function addIdAndUnidOfStaticPageToReact($page): void
  237.     {
  238.         $commentablePageDataProvider App::getContainer()->get(CommentablePageDataProvider::class);
  239.         $commentablePageDataProvider->setStaticPageId($page['id']);
  240.         $commentablePageDataProvider->setStaticPageUnid($page['unid']);
  241.     }
  242. }