src/WebBundle/Twig/AppExtension.php line 93

Open in your IDE?
  1. <?php
  2. namespace WebBundle\Twig;
  3. use DateTime;
  4. use Doctrine\DBAL\DBALException;
  5. use Exception;
  6. use FlexApp\Constant\TimeConstant;
  7. use FlexApp\Repository\BoolDBSettingRepository;
  8. use FlexApp\Repository\ChatBMessageRepository;
  9. use FlexApp\Repository\ChatBRepository;
  10. use FlexApp\Repository\WidgetRepository;
  11. use FlexApp\Service\CalendarService;
  12. use FlexApp\Service\JWTGenerator;
  13. use Imagick;
  14. use ImagickException;
  15. use Import1CBundle\Helper\v3\BiConst;
  16. use Import1CBundle\Helper\v3\TranslitNameHelper;
  17. use Memcache;
  18. use ReflectionClass;
  19. use Symfony\Component\DependencyInjection\ContainerInterface;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Symfony\Contracts\Translation\TranslatorInterface;
  22. use Twig\Extension\AbstractExtension;
  23. use Twig\Extension\GlobalsInterface;
  24. use Twig\TwigFilter;
  25. use Twig\TwigFunction;
  26. use WebBundle\Entity\Article;
  27. use WebBundle\Entity\ArticlePriceDiscount;
  28. use WebBundle\Entity\BuyOrder;
  29. use WebBundle\Entity\BuyOrderArticle;
  30. use WebBundle\Entity\Factory;
  31. use WebBundle\Entity\ListStyle;
  32. use WebBundle\Enum\BuyOrderStatusEnum;
  33. use WebBundle\Enum\CountryNumberEnum;
  34. use WebBundle\Helper\App;
  35. use WebBundle\Helper\CalendarHelper;
  36. use WebBundle\Helper\ConversionHelper;
  37. use WebBundle\Helper\CookieHelper;
  38. use WebBundle\Helper\HumanDataHelper;
  39. use WebBundle\Helper\LocaleHelper;
  40. use WebBundle\Helper\OrderHelper;
  41. use WebBundle\Helper\OrderItemHelper;
  42. use WebBundle\Helper\PathHelper;
  43. use WebBundle\Helper\SliderHelper;
  44. use WebBundle\Helper\StrHelper;
  45. use WebBundle\Helper\TranslitHelper;
  46. use WebBundle\Helper\TwigTe;
  47. use WebBundle\Helper\UserHelper;
  48. class AppExtension extends AbstractExtension implements GlobalsInterface
  49. {
  50.     /** @required */
  51.     public ChatBRepository $chatBRepository;
  52.     /** @required */
  53.     public ChatBMessageRepository $chatBMessageRepository;
  54.     /** @required */
  55.     public BoolDBSettingRepository $boolDBSettingRepository;
  56.     /** @required */
  57.     public WidgetRepository $widgetRepository;
  58.     /** @required */
  59.     public JWTGenerator $jwtGenerator;
  60.     private ContainerInterface $container;
  61.     private TranslatorInterface $translator;
  62.     private UrlGeneratorInterface $urlGenerator;
  63.     public function __construct(
  64.         ContainerInterface $container,
  65.         TranslatorInterface $translator,
  66.         UrlGeneratorInterface $urlGenerator
  67.     ) {
  68.         $this->container $container;
  69.         $this->translator $translator;
  70.         $this->urlGenerator $urlGenerator;
  71.     }
  72.     public function getName(): string
  73.     {
  74.         return 'app_extension';
  75.     }
  76.     /**
  77.      * Регистрируем глобальные переменные
  78.      * @throws Exception
  79.      */
  80.     public function getGlobals(): array
  81.     {
  82.         return [
  83.             'fullDomain' => App::getParameter('full_domain'),
  84.             'userSession' => $_COOKIE,
  85.             'te' => TwigTe::that(),
  86.             'csrf_token' => App::getContainer()->get('security.csrf.token_manager')->getToken('authenticate')->getValue(),
  87.             'portalWsServer' => $this->container->getParameter('portal_ws_server'),
  88.             'token' => UserHelper::getInstance()->getToken(),
  89.             'centrifugoConnectionUrl' => $this->container->getParameter('centrifugo.connection_url'),
  90.         ];
  91.     }
  92.     public function getClassName($entity): string
  93.     {
  94.         return (new ReflectionClass($entity))->getShortName();
  95.     }
  96.     public function getFunctions(): array
  97.     {
  98.         return [
  99.             'className' => new TwigFunction('className', [$this'getClassName']),
  100.             'measureGb' => new TwigFunction('measureGb', [$this'measureGb']),
  101.             'currency' => new TwigFunction('currency', [$this'currency']),
  102.             'userLocale' => new TwigFunction('userLocale', [$this'userLocale']),
  103.             'orderItemTime' => new TwigFunction('orderItemTime', [$this'orderItemTime']),
  104.             'dateMask' => new TwigFunction('dateMask', [$this'dateMask']),
  105.             'userCurrency' => new TwigFunction('userCurrency', [$this'userCurrency']),
  106.             'userGA' => new TwigFunction('userGA', [$this'userGA']),
  107.             'userCountry' => new TwigFunction('userCountry', [$this'userCountry']),
  108.             'userMeasure' => new TwigFunction('userMeasure', [$this'userMeasure']),
  109.             'prMin' => new TwigFunction('prMin', [$this'prMin']),
  110.             'price' => new TwigFunction('price', [$this'price']),
  111.             'priceDiscount' => new TwigFunction('priceDiscount', [$this'priceDiscount']),
  112.             'typeTime' => new TwigFunction('typeTime', [$this'typeTime']),
  113.             'pathGenerate' => new TwigFunction('pathGenerate', [$this'pathGenerate']),
  114.             'timestamp' => new TwigFunction('timestamp', [$this'timestamp']),
  115.             'getCurLocale' => new TwigFunction('getCurLocale', [$this'getCurLocale']),
  116.             'footerLinks' => new TwigFunction('footerLinks', [$this'footerLinks']),
  117.             'curLimit' => new TwigFunction('curLimit', [$this'curLimit']),
  118.             'curLimitEx' => new TwigFunction('curLimitEx', [$this'curLimitEx']),
  119.             'curLimitVal' => new TwigFunction('curLimitVal', [$this'curLimitVal']),
  120.             'getCoords' => new TwigFunction('getCoords', [$this'getCoords']),
  121.             'getInteriorHead' => new TwigFunction('getInteriorHead', [$this'getInteriorHead']),
  122.             'show_attributes' => new TwigFunction('show_attributes', [$this'showAttributes']),
  123.             'wrapCents' => new TwigFunction('wrapCents', [$this'wrapCents']),
  124.             'show_style_attributes' => new TwigFunction('show_style_attributes', [$this'showStyleAttributes']),
  125.             'setides' => new TwigFunction('setides', [$this'setIdes']),
  126.             'isLogged' => new TwigFunction('isLogged', [$this'isLogged']),
  127.             'humanData' => new TwigFunction('humanData', [$this'humanData']),
  128.             'isEmployee' => new TwigFunction('isEmployee', [$this'isEmployee']),
  129.             'humanSampleType' => new TwigFunction('humanSampleType', [$this'humanSampleType']),
  130.             'SampleFormat' => new TwigFunction('SampleFormat', [$this'SampleFormat']),
  131.             'isWithoutVATPrice' => new TwigFunction('isWithoutVATPrice', [$this'isWithoutVATPrice']),
  132.             'includeVATAlways' => new TwigFunction('includeVATAlways', [$this'includeVATAlways']),
  133.             'baseProps' => new TwigFunction('baseProps', [$this'baseProps']),
  134.             'VatRequiredState' => new TwigFunction('VatRequiredState', [$this'vatRequiredState']),
  135.             'OrderPercent' => new TwigFunction('OrderPercent', [$this'orderPercent']),
  136.             'getPercent' => new TwigFunction('getPercent', [$this'getPercent']),
  137.             'sampleFormat' => new TwigFunction('sampleFormat', [$this'sampleFormat']),
  138.             'readyCreate' => new TwigFunction('readyCreate', [$this'readyCreate']),
  139.             'checkForSend' => new TwigFunction('checkForSend', [$this'checkForSend']),
  140.             'orderSum' => new TwigFunction('orderSum', [$this'orderSum']),
  141.             'availabilityItemOrder' => new TwigFunction('availabilityItemOrder', [$this'availabilityItemOrder']),
  142.             'asVat' => new TwigFunction('asVat', [$this'asVat']),
  143.             'homeCountryVat' => new TwigFunction('homeCountryVat', [$this'homeCountryVat']),
  144.             'deliveryWVat' => new TwigFunction('deliveryWVat', [$this'deliveryWVat']),
  145.             'paymentPercent' => new TwigFunction('paymentPercent', [$this'paymentPercent']),
  146.             'orderParams' => new TwigFunction('orderParams', [$this'orderParams']),
  147.             'vatFactor' => new TwigFunction('vatFactor', [$this'vatFactor']),
  148.             'isHoliday' => new TwigFunction('isHoliday', [$this'isHoliday']),
  149.             'totalSum' => new TwigFunction('totalSum', [$this'totalSum']),
  150.             'statePaymentButton' => new TwigFunction('statePaymentButton', [$this'statePaymentButton']),
  151.             'onlySamples' => new TwigFunction('onlySamples', [$this'onlySamples']),
  152.             'noVat' => new TwigFunction('noVat', [$this'noVat']),
  153.             'cmToInch' => new TwigFunction('cmToInch', [$this'cmToInch']),
  154.             'resolverScriptSize' => new TwigFunction('resolverScriptSize', [$this'resolverScriptSize']),
  155.             'getUnreadCount' => new TwigFunction('getUnreadCount', [$this'getUnreadCount']),
  156.             'getJwt' => new TwigFunction('getJwt', [$this'getJwt']),
  157.             'getUserChannel' => new TwigFunction('getUserChannel', [$this'getUserChannel']),
  158.             'OrderVatText' => new TwigFunction('OrderVatText', [$this'orderVatText']),
  159.             'OrderMsg' => new TwigFunction('OrderMsg', [$this'orderMsg']),
  160.             'orderStatusAliasByStatusId' => new TwigFunction('orderStatusAliasByStatusId', [$this'orderStatusAliasByStatusId']),
  161.             'assetAdm' => new TwigFunction('assetAdm', function ($link) {
  162.                 $asset = !App::isGeneral() ? time() : App::getParameter('assets.version.adm');
  163.                 return "{$link}?{$asset}";
  164.             }),
  165.             'useRTWidget' => new TwigFunction('useRTWidget', [$this'useRTWidget']),
  166.             'getWidgetId' => new TwigFunction('getWidgetId', [$this'getWidgetId']),
  167.             'getUrlForPaymentByVisa' => new TwigFunction('getUrlForPaymentByVisa', [$this'getUrlForPaymentByVisa']),
  168.             'getUrlForPaymentByAmex' => new TwigFunction('getUrlForPaymentByAmex', [$this'getUrlForPaymentByAmex']),
  169.         ];
  170.     }
  171.     public function getFilters(): array
  172.     {
  173.         return [
  174.             new TwigFilter('emphasis', [$this'emphasisFilter']),
  175.             new TwigFilter('q_change', [$this'qChangeFilter']),
  176.             new TwigFilter('url_clear', [$this'urlClearFilter']),
  177.             new TwigFilter('preg_replace', [$this'pReplaceFilter']),
  178.             new TwigFilter('data_last', [$this'dataLastFilter']),
  179.             new TwigFilter('slice_word', [$this'cutTextForWords']),
  180.             new TwigFilter('insertHolidays', [$this'insertHolidays']),
  181.             new TwigFilter('convert_text', [$this'convertText']),
  182.             new TwigFilter('friendly_date', [$this'friendlyDate']),
  183.             new TwigFilter('caseString', [$this'getCase']),
  184.             new TwigFilter('separator_word', [$this'separatorWord']),
  185.             new TwigFilter('u_first', [$this'uFirst']),
  186.             new TwigFilter('l_first', [$this'lFirst']),
  187.             new TwigFilter('u_print', [$this'uPrint']),
  188.             new TwigFilter('strspaceless', [$this'strSpaceless']),
  189.             new TwigFilter('InteriorSizeTiny', [$this'interiorSizeTiny']),
  190.             new TwigFilter('path_collection', [$this'pathCollection']),
  191.             new TwigFilter('actual_name', [$this'actualName']),
  192.             new TwigFilter('less_content', [$this'lessContent']),
  193.             new TwigFilter('convertDate', [$this'convertDate']),
  194.             new TwigFilter('transform', [$this'transform']),
  195.             new TwigFilter('replace_umlaut', [$this'replaceUmlautChar']),
  196.             new TwigFilter('decodeHtml', [$this'decodeHtml']),
  197.             new TwigFilter('strPos', [$this'strPos']),
  198.             new TwigFilter('getFractPartLength', [$this'getFractPartLength']),
  199.             new TwigFilter('short_fio', [$this'getShortFio']),
  200.             new TwigFilter('transLit', [$this'transLit']),
  201.             new TwigFilter('makeThumbnail', [$this'makeThumbnail']),
  202.             new TwigFilter('prime', [$this'prime']),
  203.             new TwigFilter('mb_strlen', [$this'mbStrlen']),
  204.             new TwigFilter('setDataHistoryOrder', [$this'setDataHistoryOrder']),
  205.             new TwigFilter('convertToHours', [$this'convertToHours']),
  206.             new TwigFilter('price', [$this'price']),
  207.             new TwigFilter('priceMq', [$this'priceMq']),
  208.             new TwigFilter('measure', [$this'measure']),
  209.             new TwigFilter('currency', [$this'currency']),
  210.             new TwigFilter('convertFt', [$this'convertFt']),
  211.             new TwigFilter('convertSqFt', [$this'convertSqFt']),
  212.             new TwigFilter('convertKgLb', [$this'convertKgLb']),
  213.             new TwigFilter('packagingCount', [$this'packagingCount']),
  214.             new TwigFilter('pallet', [$this'pallet']),
  215.             new TwigFilter('amount', [$this'amount']),
  216.             new TwigFilter('weight', [$this'weight']),
  217.             new TwigFilter('weightLabel', [$this'weightLabel']),
  218.             new TwigFilter('measureGb', [$this'measureGb']),
  219.             new TwigFilter('convertInch', [$this'convertInch']),
  220.             new TwigFilter('replace_symbols_title', [$this'replaceSymbolsTitleFilter']),
  221.             new TwigFilter('floatSing', [$this'floatSing']),
  222.             new TwigFilter('bcdiv', [$this'bcdiv']),
  223.             new TwigFilter('floatSingDec', [$this'floatSingDec']),
  224.             new TwigFilter('removeDec', [$this'removeDec']),
  225.             new TwigFilter('pad', [$this'pad']),
  226.             new TwigFilter('HSCCard', [$this'HSCCard']),
  227.             new TwigFilter('symbolCyrillicUnderline', [$this'symbolCyrillicUnderline']),
  228.             new TwigFilter('lenThanSomeSymbol', [$this'lenThanSomeSymbol']),
  229.             new TwigFilter('declension', [$this'declension']),
  230.         ];
  231.     }
  232.     /**
  233.      * передаём перевод для "артикул" с нужным окончанием, в зависимости от кол-ва и языка
  234.      *
  235.      * @param $num
  236.      * @param $expressions
  237.      * @param $lang
  238.      *
  239.      * @return mixed|null
  240.      */
  241.     public function declension($num$expressions$lang)
  242.     {
  243.         $result null;
  244.         $count null;
  245.         $count $num 100;
  246.         if (== $num) {
  247.             $result $expressions['0'];
  248.         } elseif ('ru' != $lang && 'pl' != $lang) {
  249.             $result $expressions['1'];
  250.         } elseif ($count >= && $count <= 20) {
  251.             $result $expressions['2'];
  252.         } else {
  253.             $count $count 10;
  254.             if (== $count && 'ru' == $lang) {
  255.                 $result $expressions['0'];
  256.             } elseif ($count >= && $count <= 4) {
  257.                 $result $expressions['1'];
  258.             } else {
  259.                 $result $expressions['2'];
  260.             }
  261.         }
  262.         return $result;
  263.     }
  264.     /**
  265.      * @param $str
  266.      *
  267.      * @return mixed
  268.      */
  269.     public function HSCCard($str)
  270.     {
  271.         return htmlspecialchars($strENT_COMPAT ENT_HTML401'UTF-8');
  272.     }
  273.     /**
  274.      * записать в кеш список ид артикулов распродажи
  275.      *
  276.      * @param $ides
  277.      *
  278.      * @return string
  279.      */
  280.     public function setIdes($ides)
  281.     {
  282.         $memkey 'memkey-' UserHelper::getInstance()->getToken();
  283.         $memcache = new Memcache();
  284.         $memcache->connect(App::getParameter('memcache_host'), App::getParameter('memcache_port'));
  285.         if ($ides) {
  286.             $memcache->add($memkey$idesfalse, (int) TimeConstant::HOUR);
  287.         } else {
  288.             $memcache->delete($memkey);
  289.         }
  290.         return $memkey;
  291.     }
  292.     /**
  293.      * @return bool
  294.      *
  295.      * @throws Exception
  296.      */
  297.     public function isLogged()
  298.     {
  299.         return (bool) App::getCurUser();
  300.     }
  301.     public function pad($str$padLength$sign)
  302.     {
  303.         return str_pad($str$padLength$signSTR_PAD_LEFT);
  304.     }
  305.     public function mbStrlen($content)
  306.     {
  307.         return mb_strlen($content'utf-8');
  308.     }
  309.     public function transLit($str)
  310.     {
  311.         return TranslitHelper::convert($strLocaleHelper::getDefault());
  312.     }
  313.     /**
  314.      * Отчищает строку от лишних знаков для адреса url
  315.      *
  316.      * @param string $string
  317.      * @param bool $flag
  318.      *
  319.      * @return string
  320.      */
  321.     public function urlClearFilter($string$flag true)
  322.     {
  323.         if ($flag) {
  324.             $s = ['('')''&''/''\\''`''\'''%'',''.''#''?''"'];
  325.         } else {
  326.             $s = ['('')''/''\\''`''\'''%'',''.''#''?''"'];
  327.         }
  328.         $string str_replace($s''$string);
  329.         return preg_replace('#[\s]#i''-'trim($string));
  330.     }
  331.     /**
  332.      * Отчищает строку от лишних знаков для адреса url
  333.      *
  334.      * @param string $string
  335.      *
  336.      * @return string
  337.      */
  338.     public function qChangeFilter($string)
  339.     {
  340.         return TranslitNameHelper::replacePrime($stringfalse);
  341.     }
  342.     /**
  343.      * Для пользовательских регулярных выражений в шаблонах
  344.      *
  345.      * @param string $string
  346.      * @param string|array $pattern строка или массив регулярных выражений
  347.      * @param string|array $replacement массив замены
  348.      *
  349.      * @return string
  350.      */
  351.     public function pReplaceFilter($string$pattern$replacement)
  352.     {
  353.         return preg_replace($pattern$replacement$string);
  354.     }
  355.     /**
  356.      * Меняет большую гласную букву на маленькую с ударением
  357.      *
  358.      * @param string $str преобразуемая строка
  359.      *
  360.      * @return string
  361.      */
  362.     public function emphasisFilter($str)
  363.     {
  364.         $str preg_replace('#\s+#isUu'' '$str);
  365.         $words explode(' '$str);
  366.         $newWords = [];
  367.         foreach ($words as $word) {
  368.             preg_match_all('#[А-Я|A-Z]#u'$word$matches);
  369.             $ch_str '';
  370.             foreach (array_reverse($matches[0]) as $match) {
  371.                 if (
  372.                     in_array($match, [
  373.                     'a',
  374.                     'e',
  375.                     'i',
  376.                     'o',
  377.                     'u',
  378.                     'A',
  379.                     'E',
  380.                     'I',
  381.                     'O',
  382.                     'U',
  383.                     'а',
  384.                     'е',
  385.                     'ё',
  386.                     'и',
  387.                     'о',
  388.                     'у',
  389.                     'э',
  390.                     'ю',
  391.                     'я',
  392.                     'А',
  393.                     'Е',
  394.                     'Ё',
  395.                     'И',
  396.                     'О',
  397.                     'У',
  398.                     'Э',
  399.                     'Ю',
  400.                     'Я',
  401.                     ])
  402.                 ) {
  403.                     $ch_str str_replace($matchmb_convert_case($matchMB_CASE_LOWER'UTF-8') . '&#x301;'$word);
  404.                     break;
  405.                 }
  406.             }
  407.             if (empty($ch_str)) {
  408.                 $ch_str $word;
  409.             }
  410.             $newWords[] = $ch_str;
  411.         }
  412.         return mb_convert_case(implode(' '$newWords), MB_CASE_LOWER'UTF-8');
  413.     }
  414.     /**
  415.      * @param DateTime $date
  416.      *
  417.      * @return string
  418.      */
  419.     public static function dataLastFilter($date)
  420.     {
  421.         $now date('d.m.y');
  422.         $yesterday date('d.m.y'strtotime(date('Y-m-d')) - 3600 24);
  423.         switch ($date) {
  424.             case $date == $now:
  425.                 $result 'main_menu_today';
  426.                 break;
  427.             case $date == $yesterday:
  428.                 $result 'main_menu_yesterday';
  429.                 break;
  430.             default:
  431.                 $result false;
  432.                 break;
  433.         }
  434.         return $result;
  435.     }
  436.     /**
  437.      * @param string $date
  438.      * @param string $p
  439.      *
  440.      * @return string
  441.      */
  442.     public static function convertDate($date$p)
  443.     {
  444.         return date($pstrtotime($date));
  445.     }
  446.     /**
  447.      * Функция обрезки текста по словам
  448.      *
  449.      * @param string $text - исходный текст
  450.      * @param int $length - максимальная длина получаемого текста
  451.      * @param bool $addDots
  452.      *
  453.      * @return string
  454.      */
  455.     public static function cutTextForWords($text$length$addDots false)
  456.     {
  457.         return StrHelper::cutText($text$length$addDots);
  458.     }
  459.     /**
  460.      * @param string $text
  461.      *
  462.      * @return string|string[]
  463.      *
  464.      * @throws Exception
  465.      */
  466.     public function insertHolidays(string $text)
  467.     {
  468.         // Получаем строки выходных и сокращенных дней только один раз
  469.         if (!isset($this->holidaysString)) {
  470.             $calendarService $this->container->get(CalendarService::class);
  471.             $this->holidaysString $calendarService->getHolidaysString(CalendarHelper::HOLIDAY_TYPE);
  472.         }
  473.         if (!isset($this->halfHolidaysString)) {
  474.             $calendarService $this->container->get(CalendarService::class);
  475.             $this->halfHolidaysString $calendarService->getHolidaysString(CalendarHelper::HALF_HOLIDAY_TYPE);
  476.         }
  477.         $text str_replace('%holidays%'$this->holidaysString$text);
  478.         $text str_replace('%half-holidays%'$this->halfHolidaysString$text);
  479.         return $text;
  480.     }
  481.     /**
  482.      * Обработка текста перед выводом в блогах
  483.      *
  484.      * @param string $text - исходный текст
  485.      *
  486.      * @return string
  487.      */
  488.     public static function convertText($text)
  489.     {
  490.         $out str_replace([
  491.             'https://portal.treto.ru/portal.nsf/v0/',
  492.             'http://portal.treto.ru/portal.nsf/v0/',
  493.             'https://treto.ru/attach/v0/',
  494.             'http://treto.ru/attach/v0/',
  495.             '../v0',
  496.         ], 'https://te.remote.team/v0/'$text);
  497.         $out str_replace(['<iframe''</iframe>'], ['<span class="blog-video-outer-wrapper"><span class="blog-video-inner-wrapper"><iframe''</iframe></span></span>'], $out);
  498.         //<div class="blog-video-wrapper"></div>
  499.         //<p><br><iframe src="//www.youtube.com/embed/2TRNuSKglwc" width="854" height="510" frameborder="0"></iframe></p>
  500.         return $out;
  501.     }
  502.     /**
  503.      * @param DateTime $date
  504.      *
  505.      * @return string
  506.      */
  507.     public static function friendlyDate($date)
  508.     {
  509.         if (empty($date)) {
  510.             return null;
  511.         }
  512.         $now date('d.m.y');
  513.         if ($date->format('d.m.y') == $now) {
  514.             return $date->format('H:i');
  515.         } else {
  516.             return $date->format('d.m.y');
  517.         }
  518.     }
  519.     /**
  520.      * @param $num - число
  521.      * @param $words - массив падежей слова ([1], [2-4], [остальное])
  522.      *
  523.      * @return string
  524.      */
  525.     public static function getCase($num$words)
  526.     {
  527.         return TranslitHelper::getCase($num$words);
  528.     }
  529.     /**
  530.      * @param string $text
  531.      * @param int $length
  532.      *
  533.      * @return string
  534.      */
  535.     public static function separatorWord($text$length 20)
  536.     {
  537.         return wordwrap(str_replace(['~q~''?'], ['\'''&oslash;'], $text), $length"\n"1);
  538.     }
  539.     /**
  540.      * @param string $text
  541.      *
  542.      * @return string
  543.      */
  544.     public static function uFirst($text)
  545.     {
  546.         $text trim($text);
  547.         return mb_convert_case(mb_substr($text01'UTF-8'), MB_CASE_UPPER'UTF-8') . mb_convert_case(mb_substr($text1mb_strlen($text), 'UTF-8'), MB_CASE_LOWER'UTF-8');
  548.     }
  549.     /**
  550.      * @param string $text
  551.      *
  552.      * @return string
  553.      */
  554.     public static function lFirst($text)
  555.     {
  556.         return mb_convert_case(mb_substr($text01'UTF-8'), MB_CASE_LOWER'UTF-8') . mb_substr($text1mb_strlen($text), 'UTF-8');
  557.     }
  558.     /**
  559.      * @param string $text
  560.      *
  561.      * @return string
  562.      */
  563.     public static function uPrint($text)
  564.     {
  565.         return '<pre>' print_r($texttrue) . '</pre>';
  566.     }
  567.     public static function strSpaceless($value)
  568.     {
  569.         return preg_replace('/\s+/'''$value);
  570.     }
  571.     /**
  572.      * @param array $interior
  573.      * @param string $type
  574.      *
  575.      * @return int
  576.      */
  577.     public function interiorSizeTiny($interior$type 'x')
  578.     {
  579.         if ('x' == strtolower($type)) {
  580.             if ($interior['fileSizeZX'] && $interior['fileSizeZY']) {
  581.                 return $interior['fileSizeZX'];
  582.             }
  583.             if ($interior['fileSizeX'] && $interior['fileSizeY']) {
  584.                 return $interior['fileSizeX'];
  585.             }
  586.             if ($interior['fileSizeHDX'] && $interior['fileSizeHDY']) {
  587.                 return $interior['fileSizeHDX'];
  588.             }
  589.             if ($interior['fileSizeSHDX'] && $interior['fileSizeSHDY']) {
  590.                 return $interior['fileSizeSHDX'];
  591.             }
  592.         } elseif ('y' == strtolower($type)) {
  593.             if ($interior['fileSizeZX'] && $interior['fileSizeZY']) {
  594.                 return $interior['fileSizeZY'];
  595.             }
  596.             if ($interior['fileSizeX'] && $interior['fileSizeY']) {
  597.                 return $interior['fileSizeY'];
  598.             }
  599.             if ($interior['fileSizeHDX'] && $interior['fileSizeHDY']) {
  600.                 return $interior['fileSizeHDY'];
  601.             }
  602.             if ($interior['fileSizeSHDX'] && $interior['fileSizeSHDY']) {
  603.                 return $interior['fileSizeSHDY'];
  604.             }
  605.         }
  606.         return 0;
  607.     }
  608.     /**
  609.      * Строит путь до папки коллекции
  610.      *
  611.      * @param $collection
  612.      *
  613.      * @return string
  614.      */
  615.     public function pathCollection($collection)
  616.     {
  617.         $path '';
  618.         if (BiConst::CHOICE_ADDRESS_URL) {
  619.             if (!empty($collection['factory']['url']) && !empty($collection['url'])) {
  620.                 $path PathHelper::getImgWebPath() .
  621.                     $collection['factory']['url'] . '/' $collection['url'] .
  622.                     '/' BiConst::PER_SITO '/';
  623.             }
  624.         } else {
  625.             if (!empty($collection['factory']['name']) && !empty($collection['name'])) {
  626.                 $path PathHelper::getImgWebPath() . rawurlencode(TranslitNameHelper::replacePrime($collection['factory']['name'], false)) . '/' rawurlencode(TranslitNameHelper::replacePrime($collection['name'], false)) .
  627.                     '/' BiConst::PER_SITO '/';
  628.             }
  629.         }
  630.         return $path;
  631.     }
  632.     public function prime($str)
  633.     {
  634.         return TranslitNameHelper::replacePrime($strfalse);
  635.     }
  636.     /**
  637.      * @param $data
  638.      *
  639.      * @return string
  640.      */
  641.     public function actualName($data)
  642.     {
  643.         if (is_array($data)) {
  644.             if (!empty($data['alternateName'])) {
  645.                 return $data['alternateName'];
  646.             } else {
  647.                 return $data['name'];
  648.             }
  649.         } else {
  650.             /* @var Factory $data */
  651.             return null != $data->getAlternateName() ? $data->getAlternateName() : $data->getName();
  652.         }
  653.     }
  654.     public function lessContent($text$length$lessText$moreText)
  655.     {
  656.         $text htmlspecialchars_decode($text);
  657.         if (mb_strlen(preg_replace('/<.*?>/'''$text), 'UTF-8') <= $length) {
  658.             return $text;
  659.         }
  660.         $totalLength 0;
  661.         $openTags = [];
  662.         $truncate '';
  663.         preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/'$text$tagsPREG_SET_ORDER);
  664.         foreach ($tags as $tag) {
  665.             if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s'$tag[2])) {
  666.                 if (preg_match('/<[\w]+[^>]*>/s'$tag[0])) {
  667.                     array_unshift($openTags$tag[2]);
  668.                 } else {
  669.                     if (preg_match('/<\/([\w]+)[^>]*>/s'$tag[0], $closeTag)) {
  670.                         $pos array_search($closeTag[1], $openTags);
  671.                         if (false !== $pos) {
  672.                             array_splice($openTags$pos1);
  673.                         }
  674.                     }
  675.                 }
  676.             }
  677.             $truncate .= $tag[1];
  678.             $contentLength mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i'' '$tag[3]), 'UTF-8');
  679.             if ($contentLength $totalLength $length) {
  680.                 $left $length $totalLength;
  681.                 $entitiesLength 0;
  682.                 if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i'$tag[3], $entitiesPREG_OFFSET_CAPTURE)) {
  683.                     foreach ($entities[0] as $entity) {
  684.                         if ($entity[1] + $entitiesLength <= $left) {
  685.                             --$left;
  686.                             $entitiesLength += mb_strlen($entity[0], 'UTF-8');
  687.                         } else {
  688.                             break;
  689.                         }
  690.                     }
  691.                 }
  692.                 $truncate .= mb_substr($tag[3], 0$left $entitiesLength'UTF-8');
  693.                 break;
  694.             } else {
  695.                 $truncate .= $tag[3];
  696.                 $totalLength += $contentLength;
  697.             }
  698.             if ($totalLength >= $length) {
  699.                 break;
  700.             }
  701.         }
  702.         $truncate .= '...';
  703.         foreach ($openTags as $tag) {
  704.             $truncate .= '</' $tag '>';
  705.         }
  706.         return '<div class="content-less">' $truncate '</div>' .
  707.             '<div class="content-full">' $text '</div>' .
  708.             '<a class="content-more-link" rel="nofollow" data-action="open"' .
  709.             ' data-more-up="' $lessText '"' .
  710.             ' data-more-down="' $moreText '">' .
  711.             $moreText '</a>';
  712.     }
  713.     public function transform($text)
  714.     {
  715.         return TranslitNameHelper::replacePrime($textfalse);
  716.     }
  717.     public function replaceUmlautChar($text)
  718.     {
  719.         return StrHelper::replaceUmlautChar($text);
  720.     }
  721.     public function decodeHtml($str)
  722.     {
  723.         return htmlspecialchars_decode($str);
  724.     }
  725.     /**
  726.      * @param $str
  727.      * @param $needle
  728.      * @param int $offset
  729.      *
  730.      * @return bool|int
  731.      */
  732.     public function strPos($str$needle$offset 0)
  733.     {
  734.         return strpos($str$needle$offset);
  735.     }
  736.     /**
  737.      * Функция возврата количества символов в дробной части числа
  738.      *
  739.      * @param $str
  740.      *
  741.      * @return int
  742.      */
  743.     public function getFractPartLength($str)
  744.     {
  745.         $result 0;
  746.         $str str_replace(',''.'$str);
  747.         if (strpos($str'.')) {
  748.             $fractPart explode('.'$str);
  749.             $result strlen($fractPart[1]);
  750.         }
  751.         return $result;
  752.     }
  753.     /**
  754.      * @param $text
  755.      *
  756.      * @return string
  757.      */
  758.     public static function getShortFio($text)
  759.     {
  760.         $fio explode(' '$text);
  761.         $c count($fio);
  762.         if ($c 2) {
  763.             return $text;
  764.         }
  765.         //        mb_internal_encoding("UTF-8");
  766.         $newFio = [];
  767.         foreach ($fio as $key => $n) {
  768.             if ($key 0) {
  769.                 $n mb_substr($n01'UTF-8') . '.';
  770.             }
  771.             $newFio[] = $n;
  772.         }
  773.         return implode(' '$newFio);
  774.     }
  775.     /**
  776.      * @param $imagePath
  777.      *
  778.      * @return string
  779.      *
  780.      * @throws ImagickException
  781.      */
  782.     public function makeThumbnail($imagePath)
  783.     {
  784.         //try {
  785.         $whitelist = [
  786.             '127.0.0.1',
  787.             '::1',
  788.         ];
  789.         //$imageClearPath = htmlentities($imagePath);
  790.         $remoteAddr $_SERVER['REMOTE_ADDR'];
  791.         $docRoot $_SERVER['DOCUMENT_ROOT'];
  792.         if (strrpos($docRoot'https://tile.expert') || in_array($remoteAddr$whitelist)) {
  793.             $newImg explode('/'$imagePath);
  794.             $newImg urldecode($newImg[count($newImg) - 1]);
  795.             if (!is_dir($docRoot '/media/cache/slide-show/')) {
  796.                 mkdir($docRoot '/media/cache/slide-show/'0777);
  797.             }
  798.             if (!file_exists($docRoot '/media/cache/slide-show/' $newImg)) {
  799.                 if (in_array($remoteAddr$whitelist)) {
  800.                     $imgSrc $docRoot '/media/cache/slide-show/new-' $newImg;
  801.                     copy($imagePath$imgSrc);
  802.                 } else {
  803.                     $imgSrc $imagePath;
  804.                 }
  805.                 $image = new Imagick($imgSrc);
  806.                 $image->thumbnailImage(110110);
  807.                 $image->writeImage($docRoot '/media/cache/slide-show/' $newImg);
  808.             }
  809.             return '/media/cache/slide-show/' $newImg;
  810.         } else {
  811.             return $imagePath;
  812.         }
  813.         /*} catch(Exception $e) {
  814.             echo 'Exception: ', $e->getMessage(), "n";
  815.         }*/
  816.     }
  817.     /**
  818.      * @param $str
  819.      * @param $data
  820.      * @param null $number
  821.      * @param int $sex
  822.      * @param null $bankTransfer
  823.      *
  824.      * @return mixed
  825.      *
  826.      * @throws Exception
  827.      */
  828.     public function setDataHistoryOrder($str$data$number null$sex 1$bankTransfer null)
  829.     {
  830.         $mask = [
  831.             '%table%' => '',
  832.             '%table2%' => '',
  833.             '%tableForReview%' => '',
  834.             '%managerName%' => '',
  835.             '%managerEmail%' => '',
  836.             '%managerPhone%' => '',
  837.         ];
  838.         if (!empty($number)) {
  839.             $mask['%number%'] = '<a href="#">' $number '</a>';
  840.         }
  841.         unset($data['country']);
  842.         if (isset($data['%lift%'])) {
  843.             $data['%lift%'] = App::trans($data['%lift%'], App::getCurLocale());
  844.         }
  845.         $data['%link%'] = '#';
  846.         $data['%acceptLink%'] = '#confirmTheDateBlock';
  847.         $data['%setDateLink%'] = '#confirmTheDateBlock';
  848.         $data['%cancelLink%'] = '#confirmTheDateBlock';
  849.         $data['%designLinkLeft%'] = '';
  850.         $data['%designLinkRight%'] = '';
  851.         $data['%designFooterStart%'] = '';
  852.         $data['%designFooterEnd%'] = '';
  853.         $data['%bankTransfer%'] = $bankTransfer App::trans('var_bank_transfer') : '';
  854.         if (!empty($data['%sysPayment%'])) {
  855.             $data['%sysPayment%'] = App::trans($data['%sysPayment%'], App::getCurLocale());
  856.         }
  857.         if (!empty($data['%sysPayment2%'])) {
  858.             $data['%sysPayment2%'] = App::trans($data['%sysPayment2%'], App::getCurLocale());
  859.         }
  860.         if (empty($data['%offsetDate2%'])) {
  861.             $data['%offsetDate2%'] = App::trans('buyOrder.offsetData_2'App::getCurLocale());
  862.             $data['%OffsetDate2%'] = StrHelper::ucFirstOnly($data['%offsetDate2%']);
  863.         }
  864.         $data['%fio%'] = $data['%fio%'] ?? '';
  865.         $t App::trans((== $sex 'title.man' 'title.woman'), App::getCurLocale());
  866.         if ('fr' != App::getCurLocale()) {
  867.             $data['%fio%'] = $t ' ' $data['%fio%'];
  868.         } else {
  869.             $data['%fio%'] = $t;
  870.         }
  871.         $data['%fio%'] .= App::getCurLocale() ? '!' ',';
  872.         $data array_merge($mask$data);
  873.         $dataKey array_keys($data);
  874.         $data array_values($data);
  875.         // получаем необходимое письма и подставляем переменные
  876.         return str_replace($dataKey$data$str);
  877.     }
  878.     /**
  879.      * @param DateTime $date
  880.      *
  881.      * @return mixed
  882.      *
  883.      * @throws Exception
  884.      */
  885.     public function convertToHours($date)
  886.     {
  887.         $d = new DateTime();
  888.         return $d->diff($date)->format('%d') * 24;
  889.     }
  890.     /**
  891.      * @param Article $article
  892.      * @param array $param
  893.      *
  894.      * @return string
  895.      *
  896.      * @throws Exception
  897.      */
  898.     public function price($article$param = [])
  899.     {
  900.         return LocaleHelper::getPrice($article$param);
  901.     }
  902.     /**
  903.      * @param ArticlePriceDiscount $priceDiscount
  904.      * @param array $param
  905.      *
  906.      * @return array
  907.      *
  908.      * @throws Exception
  909.      */
  910.     public function priceDiscount($priceDiscount$param = [])
  911.     {
  912.         return LocaleHelper::getPriceDiscount($priceDiscount$param);
  913.     }
  914.     /**
  915.      * @param Article $article
  916.      * @param array $param
  917.      *
  918.      * @return string
  919.      *
  920.      * @throws Exception
  921.      */
  922.     public function priceMq($article$param = [])
  923.     {
  924.         return LocaleHelper::getPriceMq($article$param);
  925.     }
  926.     /**
  927.      * @param Article $article
  928.      * @param array $param
  929.      * @param int $type
  930.      *
  931.      * @return string
  932.      *
  933.      * @throws Exception
  934.      */
  935.     public function measure($article$param = [], $type 1)
  936.     {
  937.         return LocaleHelper::getMeasure($article$param$type);
  938.     }
  939.     /**
  940.      * @param $val
  941.      * @param int $type
  942.      *
  943.      * @return float
  944.      */
  945.     public function convertFt($val$type 1): float
  946.     {
  947.         return ConversionHelper::convertFt((float) $val$type);
  948.     }
  949.     /**
  950.      * @param $val
  951.      * @param int $type
  952.      *
  953.      * @return float
  954.      */
  955.     public function convertSqFt($val$type 1): float
  956.     {
  957.         return ConversionHelper::convertSqFt((float) $val$type);
  958.     }
  959.     /**
  960.      * @param $val
  961.      * @param int $type
  962.      *
  963.      * @return float
  964.      */
  965.     public function convertKgLb($val$type 1): float
  966.     {
  967.         return ConversionHelper::convertKgLb((float) $val$type);
  968.     }
  969.     /**
  970.      * @param $str
  971.      * @return string
  972.      * @throws Exception
  973.      */
  974.     public function currency($str null)
  975.     {
  976.         return LocaleHelper::getCurrency($str);
  977.     }
  978.     /**
  979.      * @param BuyOrder $order
  980.      * @return array
  981.      * @throws Exception
  982.      */
  983.     public function orderSum(BuyOrder $order)
  984.     {
  985.         return OrderHelper::sum($order);
  986.     }
  987.     /**
  988.      * @param BuyOrderArticle $item
  989.      * @param BuyOrder $order
  990.      * @return bool
  991.      */
  992.     public function availabilityItemOrder(BuyOrderArticle $itemBuyOrder $order)
  993.     {
  994.         $specPrice $order->getSpecPrice();
  995.         $orderStatusId $order->getStatus();
  996.         return OrderHelper::availabilityItemOrder($item$specPrice$orderStatusId);
  997.     }
  998.     /**
  999.      * @param BuyOrder $order
  1000.      * @return float
  1001.      * @throws Exception
  1002.      */
  1003.     public function deliveryWVat(BuyOrder $order)
  1004.     {
  1005.         return OrderHelper::deliveryWVat($order);
  1006.     }
  1007.     /**
  1008.      * @param BuyOrder $order
  1009.      * @return bool
  1010.      * @throws Exception
  1011.      */
  1012.     public function asVat(BuyOrder $order)
  1013.     {
  1014.         return OrderHelper::asVat($order);
  1015.     }
  1016.     /**
  1017.      * @param BuyOrder $order
  1018.      * @return bool
  1019.      * @throws Exception
  1020.      */
  1021.     public function homeCountryVat(BuyOrder $order)
  1022.     {
  1023.         return OrderHelper::homeCountryVat($order);
  1024.     }
  1025.     /**
  1026.      * @param Article $article
  1027.      * @param array $param
  1028.      * @param int $type
  1029.      *
  1030.      * @return string
  1031.      *
  1032.      * @throws Exception
  1033.      */
  1034.     public function packagingCount($article$param = [], $type 1)
  1035.     {
  1036.         return LocaleHelper::getPackagingCount($article$param$type);
  1037.     }
  1038.     /**
  1039.      * @param Article $article
  1040.      * @param array $param
  1041.      *
  1042.      * @return string
  1043.      *
  1044.      * @throws Exception
  1045.      */
  1046.     public function pallet($article$param = [])
  1047.     {
  1048.         return LocaleHelper::getPallet($article$param);
  1049.     }
  1050.     /**
  1051.      * @param Article $article
  1052.      * @param float|null $amount
  1053.      * @param array $param
  1054.      * @param int $type
  1055.      *
  1056.      * @return string
  1057.      *
  1058.      * @throws Exception
  1059.      */
  1060.     public function amount($article$amount null$param = [], $type 1)
  1061.     {
  1062.         return LocaleHelper::getAmount($article$amount$param$type);
  1063.     }
  1064.     /**
  1065.      * @param Article $article
  1066.      * @param array $param
  1067.      *
  1068.      * @return string
  1069.      *
  1070.      * @throws Exception
  1071.      */
  1072.     public function weight($article$param = [])
  1073.     {
  1074.         return LocaleHelper::getWeight($article$param);
  1075.     }
  1076.     /**
  1077.      * @param float|null $weight
  1078.      * @param bool $with
  1079.      * @param BuyOrder|null $order
  1080.      *
  1081.      * @return string
  1082.      *
  1083.      * @throws Exception
  1084.      */
  1085.     public function weightLabel(?float $weight 1.0bool $with true, ?string $measure null): string
  1086.     {
  1087.         return LocaleHelper::weightLabel($weight$with$measure);
  1088.     }
  1089.     /**
  1090.      * @param array $param
  1091.      *
  1092.      * @return bool
  1093.      *
  1094.      * @throws Exception
  1095.      */
  1096.     public function measureGb($param = [])
  1097.     {
  1098.         return LocaleHelper::measureGb($param);
  1099.     }
  1100.     /**
  1101.      * @param $orderItem
  1102.      *
  1103.      * @return string
  1104.      *
  1105.      * @throws Exception
  1106.      */
  1107.     public function orderItemTime(BuyOrderArticle $orderItem): string
  1108.     {
  1109.         return OrderItemHelper::getItemTime($orderItem);
  1110.     }
  1111.     /**
  1112.      * @param int $type
  1113.      * @param null $country
  1114.      *
  1115.      * @return string
  1116.      *
  1117.      * @throws Exception
  1118.      */
  1119.     public function dateMask($type 1$country null)
  1120.     {
  1121.         return LocaleHelper::dateMask($type$country);
  1122.     }
  1123.     /**
  1124.      * @return mixed|string|null
  1125.      *
  1126.      * @throws Exception
  1127.      */
  1128.     public function userCurrency()
  1129.     {
  1130.         return LocaleHelper::getCur();
  1131.     }
  1132.     /**
  1133.      * @throws Exception
  1134.      */
  1135.     public function userGA()
  1136.     {
  1137.         return CookieHelper::get('_ga');
  1138.     }
  1139.     /**
  1140.      * @return string
  1141.      *
  1142.      * @throws Exception
  1143.      */
  1144.     public function userCountry()
  1145.     {
  1146.         return App::getCurCountry();
  1147.     }
  1148.     /**
  1149.      * @return string|null
  1150.      *
  1151.      * @throws Exception
  1152.      */
  1153.     public function userMeasure()
  1154.     {
  1155.         return LocaleHelper::getUserMeasure();
  1156.     }
  1157.     /**
  1158.      * @param array $params
  1159.      *
  1160.      * @return bool
  1161.      *
  1162.      * @throws Exception
  1163.      */
  1164.     public function curLimit($params = [])
  1165.     {
  1166.         return LocaleHelper::getCurLimit($params);
  1167.     }
  1168.     /**
  1169.      * @return string
  1170.      *
  1171.      * @throws Exception
  1172.      */
  1173.     public function curLimitEx()
  1174.     {
  1175.         return LocaleHelper::getCurLimitEx();
  1176.     }
  1177.     /**
  1178.      * Конвертация в дюймы
  1179.      *
  1180.      * @param float $val
  1181.      * @param int $type 1 - мм, 0 - inch
  1182.      *
  1183.      * @return float
  1184.      */
  1185.     public function convertInch($val$type 1): float
  1186.     {
  1187.         return ConversionHelper::convertInch((float) $val$type);
  1188.     }
  1189.     /**
  1190.      * Возвращает минимальное ограничение по заказу
  1191.      *
  1192.      * @param array $param
  1193.      *
  1194.      * @return int
  1195.      *
  1196.      * @throws Exception
  1197.      */
  1198.     public function curLimitVal($param = [])
  1199.     {
  1200.         return LocaleHelper::getCurLimitVal($param);
  1201.     }
  1202.     /**
  1203.      * Определяет летнее/зимнее время по Лондону
  1204.      *
  1205.      * @return bool
  1206.      */
  1207.     public function typeTime()
  1208.     {
  1209.         $old date_default_timezone_get();
  1210.         date_default_timezone_set('Europe/London');
  1211.         $ts time();
  1212.         $dy date('I'$ts);
  1213.         date_default_timezone_set($old);
  1214.         if (== $dy) {
  1215.             return (string) '1';
  1216.         } else {
  1217.             return (string) '0';
  1218.         }
  1219.     }
  1220.     /**
  1221.      * @param $string
  1222.      *
  1223.      * @return mixed
  1224.      */
  1225.     public function replaceSymbolsTitleFilter($string)
  1226.     {
  1227.         return TranslitHelper::replaceSymbolsTitleFilter($string);
  1228.     }
  1229.     /**
  1230.      * @param string $price
  1231.      *
  1232.      * @return mixed
  1233.      */
  1234.     public function wrapCents($price)
  1235.     {
  1236.         $price = (string) $price;
  1237.         $sign '.';
  1238.         if (!strpos($price$sign)) {
  1239.             $sign ',';
  1240.         }
  1241.         if (== count(explode($sign$price))) {
  1242.             return str_replace($sign$sign '<span class="top-aligned-cents">'$price) . '</span>';
  1243.         } else {
  1244.             return $price;
  1245.         }
  1246.     }
  1247.     /**
  1248.      * @param $coll
  1249.      * @param array $param
  1250.      *
  1251.      * @return mixed
  1252.      *
  1253.      * @throws Exception
  1254.      */
  1255.     public function prMin($coll$param = [])
  1256.     {
  1257.         return LocaleHelper::getPrMin($coll$param);
  1258.     }
  1259.     /**
  1260.      * @param string $type ['collection'|'article'|'factory'|'publication']
  1261.      * @param array|object $data
  1262.      *
  1263.      * @return mixed
  1264.      */
  1265.     public function pathGenerate($type$data)
  1266.     {
  1267.         return PathHelper::pathGenerate($type$data);
  1268.     }
  1269.     /**
  1270.      * получить координаты бирки
  1271.      *
  1272.      * @param $article
  1273.      * @param $interior
  1274.      *
  1275.      * @return mixed
  1276.      *
  1277.      * @throws DBALException
  1278.      */
  1279.     public function getCoords($article$interior)
  1280.     {
  1281.         return SliderHelper::getCoords($article$interior);
  1282.     }
  1283.     /**
  1284.      * возвращает является ли артикул заглавным в интерьере
  1285.      *
  1286.      * @param $article
  1287.      * @param $interior
  1288.      *
  1289.      * @return mixed
  1290.      *
  1291.      * @throws DBALException
  1292.      */
  1293.     public function getInteriorHead($article$interior)
  1294.     {
  1295.         return SliderHelper::getInteriorHead($article$interior);
  1296.     }
  1297.     public function timestamp()
  1298.     {
  1299.         return strtotime('now') + 5000;
  1300.     }
  1301.     /**
  1302.      * @param bool $full !deprecated
  1303.      *
  1304.      * @return string
  1305.      */
  1306.     public function getCurLocale($full false)
  1307.     {
  1308.         return App::getCurLocale($full);
  1309.     }
  1310.     /**
  1311.      * @param bool $full
  1312.      *
  1313.      * @return string
  1314.      */
  1315.     public function userLocale($full false)
  1316.     {
  1317.         return App::getCurLocale($full);
  1318.     }
  1319.     /**
  1320.      * Меняет точку на запятую в дробных значениях для стран где принят такой формат
  1321.      *
  1322.      * @param float $val
  1323.      * @param int $decimals
  1324.      * @param bool $float если true то вернёт цифровое значение
  1325.      *
  1326.      * @return mixed
  1327.      */
  1328.     public function floatSing($val$decimals 2$float false)
  1329.     {
  1330.         return LocaleHelper::floatSign($val$decimals$float);
  1331.     }
  1332.     public function bcdiv($val$decimals 2)
  1333.     {
  1334.         return bcdiv($val1$decimals);
  1335.     }
  1336.     /**
  1337.      * Меняет точку на запятую в дробных значениях для стран где принят такой формат;
  1338.      * для 3 знаков после запятой
  1339.      *
  1340.      * @param float $val
  1341.      * @param int $decimals
  1342.      * @param bool $float если true то вернёт цифровое значение
  1343.      *
  1344.      * @return mixed
  1345.      */
  1346.     public function floatSingDec($val$decimals 3$float false)
  1347.     {
  1348.         return LocaleHelper::floatSign($val$decimals$float);
  1349.     }
  1350.     /**
  1351.      * Удаляет дробную часть числа
  1352.      *
  1353.      * @param float $val
  1354.      *
  1355.      * @return int
  1356.      */
  1357.     public function removeDec($val)
  1358.     {
  1359.         return round($val0);
  1360.     }
  1361.     /**
  1362.      * вывод атрибутов в шаблоне
  1363.      *
  1364.      * @param array $attributes
  1365.      *
  1366.      * @return int
  1367.      */
  1368.     public function showAttributes($attributes)
  1369.     {
  1370.         $name = [];
  1371.         $locale App::getCurLocale();
  1372.         foreach ($attributes as $key => $attribute) {
  1373.             $a is_object($attribute) ? $attribute->getAlias() : $attribute['alias'];
  1374.             $alias $this->translator->trans($a);
  1375.             if ($key 0) {
  1376.                 if ('de' == $locale) {
  1377.                     $alias TranslitHelper::replaceAttributesTitle($alias);
  1378.                 } elseif ('left_menu_3d' == $a) {
  1379.                     $alias mb_strtoupper(TranslitHelper::replaceAttributesTitle($alias));
  1380.                 } else {
  1381.                     $alias mb_strtolower(TranslitHelper::replaceAttributesTitle($alias));
  1382.                 }
  1383.             }
  1384.             $name[] = trim($alias);
  1385.         }
  1386.         return implode(', '$name);
  1387.     }
  1388.     /**
  1389.      * вывод атрибутов style в шаблоне
  1390.      *
  1391.      * @param $attributes
  1392.      *
  1393.      * @return mixed
  1394.      */
  1395.     public function showStyleAttributes($attributes)
  1396.     {
  1397.         $name = [];
  1398.         $locale App::getCurLocale();
  1399.         /* @var ListStyle $style */
  1400.         if ('en' == $locale) {
  1401.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1402.             foreach ($attributes as $key => $style) {
  1403.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1404.                 $alias $this->translator->trans($a);
  1405.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1406.                 $name[] = trim($alias);
  1407.             }
  1408.             if ($count 1) {
  1409.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1410.             } else {
  1411.                 $output ucfirst(implode(', '$name));
  1412.             }
  1413.         } elseif ('it' == $locale) {
  1414.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1415.             foreach ($attributes as $key => $style) {
  1416.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1417.                 $alias $this->translator->trans($a);
  1418.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1419.                 $name[] = trim($alias);
  1420.             }
  1421.             if ($count 1) {
  1422.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1423.             } else {
  1424.                 $output ucfirst(implode(', '$name));
  1425.             }
  1426.         } elseif ('es' == $locale) {
  1427.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1428.             foreach ($attributes as $key => $style) {
  1429.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1430.                 $alias $this->translator->trans($a);
  1431.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1432.                 $name[] = trim($alias);
  1433.             }
  1434.             if ($count 1) {
  1435.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1436.             } else {
  1437.                 $output ucfirst(implode(', '$name));
  1438.             }
  1439.         } elseif ('fr' == $locale) {
  1440.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1441.             foreach ($attributes as $key => $style) {
  1442.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1443.                 $alias $this->translator->trans($a);
  1444.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1445.                 $name[] = trim($alias);
  1446.             }
  1447.             if ($count 1) {
  1448.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1449.             } else {
  1450.                 $output ucfirst(implode(', '$name));
  1451.             }
  1452.         } elseif ('de' == $locale) {
  1453.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1454.             foreach ($attributes as $key => $style) {
  1455.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1456.                 $alias $this->translator->trans($a);
  1457.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1458.                 $name[] = trim($alias);
  1459.             }
  1460.             if ($count 1) {
  1461.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1462.             } else {
  1463.                 $output ucfirst(implode(', '$name));
  1464.             }
  1465.             $output ucfirst(implode(', '$name));
  1466.         } elseif ('pl' == $locale) {
  1467.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1468.             foreach ($attributes as $key => $style) {
  1469.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1470.                 $alias $this->translator->trans($a);
  1471.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1472.                 $name[] = trim($alias);
  1473.             }
  1474.             if ($count 1) {
  1475.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1476.             } else {
  1477.                 $output ucfirst(implode(', '$name));
  1478.             }
  1479.         } elseif ('nl' == $locale) {
  1480.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1481.             foreach ($attributes as $key => $style) {
  1482.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1483.                 $alias $this->translator->trans($a);
  1484.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1485.                 $name[] = trim($alias);
  1486.             }
  1487.             if ($count 1) {
  1488.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1489.             } else {
  1490.                 $output ucfirst(implode(', '$name));
  1491.             }
  1492.         } elseif ('fi' == $locale) {
  1493.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1494.             foreach ($attributes as $key => $style) {
  1495.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1496.                 $alias $this->translator->trans($a);
  1497.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1498.                 $name[] = trim($alias);
  1499.             }
  1500.             if ($count 1) {
  1501.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1502.             } else {
  1503.                 $output ucfirst(implode(', '$name));
  1504.             }
  1505.         } else {
  1506.             $count is_object($attributes) ? count($attributes->count()) : count($attributes);
  1507.             foreach ($attributes as $key => $style) {
  1508.                 $a is_object($style) ? $style->getAlias() : $style['alias'];
  1509.                 $alias $this->translator->trans($a);
  1510.                 $alias $count mb_strtolower(TranslitHelper::replaceAttributesTitle($alias)) : mb_strtolower($alias);
  1511.                 $name[] = trim($alias);
  1512.             }
  1513.             if ($count 1) {
  1514.                 $output ucfirst(mb_strtolower($this->translator->trans('left_menu_style')) . ': ' implode(', '$name));
  1515.             } else {
  1516.                 $output ucfirst(implode(', '$name));
  1517.             }
  1518.         }
  1519.         return $output;
  1520.     }
  1521.     /**
  1522.      * @param $str
  1523.      *
  1524.      * @return string
  1525.      */
  1526.     public static function symbolCyrillicUnderline($str)
  1527.     {
  1528.         return TranslitNameHelper::returnStrCyrillicSymbolUnderline($str);
  1529.     }
  1530.     public function lenThanSomeSymbol($str)
  1531.     {
  1532.         return TranslitNameHelper::lenThanSomeSymbol($str);
  1533.     }
  1534.     /**
  1535.      * @param $date
  1536.      *
  1537.      * @return mixed|string
  1538.      */
  1539.     public static function humanData($date)
  1540.     {
  1541.         return HumanDataHelper::get((int) $date);
  1542.     }
  1543.     public function isEmployee(?string $email): bool
  1544.     {
  1545.         return UserHelper::isEmployee($email);
  1546.     }
  1547.     /**
  1548.      * @param ?int $type
  1549.      * @param ?string $locale
  1550.      *
  1551.      * @return array
  1552.      *
  1553.      * @throws Exception
  1554.      */
  1555.     public static function humanSampleType(?int $type 1, ?string $locale null): array
  1556.     {
  1557.         return OrderItemHelper::humanSampleType($type$locale);
  1558.     }
  1559.     /**
  1560.      * @param BuyOrderArticle|array $article
  1561.      * @param array $params
  1562.      * @param bool $inch
  1563.      * @param null $locale
  1564.      *
  1565.      * @return string
  1566.      *
  1567.      * @throws Exception
  1568.      */
  1569.     public static function sampleFormat($article$params$inch false$locale null)
  1570.     {
  1571.         return OrderItemHelper::sampleFormat($article$params$inch$locale);
  1572.     }
  1573.     /**
  1574.      * @param $order
  1575.      * @param bool $withLimit
  1576.      * @return bool
  1577.      * @throws Exception
  1578.      */
  1579.     public static function readyCreate($order$withLimit true)
  1580.     {
  1581.         return OrderHelper::readyCreate($order$withLimit);
  1582.     }
  1583.     /**
  1584.      * @param $order
  1585.      * @param bool $withLimit
  1586.      * @return bool
  1587.      * @throws Exception
  1588.      */
  1589.     public static function checkForSend($order$withLimit true)
  1590.     {
  1591.         return OrderHelper::checkForSend($order$withLimit);
  1592.     }
  1593.     /**
  1594.      * @return bool
  1595.      *
  1596.      * @throws Exception
  1597.      */
  1598.     public static function isWithoutVATPrice()
  1599.     {
  1600.         return false !== LocaleHelper::isWithoutVATPrice(10);
  1601.     }
  1602.     /**
  1603.      * @throws Exception
  1604.      */
  1605.     public static function includeVATAlways(): float
  1606.     {
  1607.         return LocaleHelper::includeVATAlways();
  1608.     }
  1609.     /**
  1610.      * @return array
  1611.      */
  1612.     public static function baseProps()
  1613.     {
  1614.         return [
  1615.             'baseUrl' => /*App::getRequest()->getSchemeAndHttpHost() . */ App::getRequest()->getBaseUrl(),
  1616.             'locale' => App::getCurLocale(true),
  1617.             'lang' => App::getCurLocale(),
  1618.         ];
  1619.     }
  1620.     public static function vatRequiredState(BuyOrder $order): bool
  1621.     {
  1622.         if ($order->getDeliveryCountry()) {
  1623.             $country strtolower($order->getDeliveryCountry()->getCode());
  1624.         } else {
  1625.             $country 'at';
  1626.         }
  1627.         return in_array($countryOrderHelper::vatRequired()['char']);
  1628.     }
  1629.     /**
  1630.      * @param BuyOrder $order
  1631.      * @return int
  1632.      * @throws Exception
  1633.      */
  1634.     public static function orderPercent(BuyOrder $order)
  1635.     {
  1636.         return OrderHelper::vatPercent($order);
  1637.     }
  1638.     /**
  1639.      * @param BuyOrder $order
  1640.      * @return string
  1641.      * @throws Exception
  1642.      */
  1643.     public static function orderVatText(BuyOrder $order)
  1644.     {
  1645.         return OrderHelper::vatText($order);
  1646.     }
  1647.     public static function orderMsg(BuyOrder $order)
  1648.     {
  1649.         return OrderHelper::msg($order);
  1650.     }
  1651.     /**
  1652.      * @param int $orderId
  1653.      * @return string
  1654.      */
  1655.     public static function orderStatusAliasByStatusId(int $orderId): string
  1656.     {
  1657.         return BuyOrderStatusEnum::from($orderId)->getAlias();
  1658.     }
  1659.     /**
  1660.      * @param BuyOrder $order
  1661.      * @param int|bool $flag
  1662.      * @return float|int
  1663.      * @throws Exception
  1664.      */
  1665.     public static function paymentPercent(BuyOrder $order$flag false)
  1666.     {
  1667.         return OrderHelper::paymentPercent($order$flag);
  1668.     }
  1669.     /**
  1670.      * @param $val
  1671.      * @param $percent
  1672.      * @param bool $type
  1673.      * @return float
  1674.      */
  1675.     public function getPercent($val$percent$type true)
  1676.     {
  1677.         return OrderHelper::percent($val$percent$type);
  1678.     }
  1679.     /**
  1680.      * @param BuyOrder $order
  1681.      * @return array
  1682.      * @throws Exception
  1683.      */
  1684.     public function orderParams(BuyOrder $order)
  1685.     {
  1686.         return OrderHelper::params($order);
  1687.     }
  1688.     /**
  1689.      * @param BuyOrder $order
  1690.      * @return float|int
  1691.      * @throws Exception
  1692.      */
  1693.     public function vatFactor(BuyOrder $order)
  1694.     {
  1695.         return OrderHelper::vatFactor(OrderHelper::vatPercent($order));
  1696.     }
  1697.     /**
  1698.      * @param BuyOrder $order
  1699.      * @return bool
  1700.      */
  1701.     public function isHoliday(BuyOrder $order)
  1702.     {
  1703.         return OrderHelper::isHoliday($order);
  1704.     }
  1705.     /**
  1706.      * @param BuyOrder $order
  1707.      * @param bool $euro
  1708.      * @return float
  1709.      */
  1710.     public function totalSum(BuyOrder $order$euro false)
  1711.     {
  1712.         return OrderHelper::totalSum($order$euro);
  1713.     }
  1714.     /**
  1715.      * @param BuyOrder $order
  1716.      * @return bool
  1717.      * @throws Exception
  1718.      */
  1719.     public function statePaymentButton(BuyOrder $order)
  1720.     {
  1721.         return OrderHelper::statePaymentButton($order);
  1722.     }
  1723.     /**
  1724.      * @param BuyOrder $order
  1725.      * @return bool
  1726.      * @throws Exception
  1727.      */
  1728.     public function onlySamples(BuyOrder $order)
  1729.     {
  1730.         return OrderHelper::onlySamples($order);
  1731.     }
  1732.     /**
  1733.      * @param BuyOrder $order
  1734.      * @return bool
  1735.      */
  1736.     public function noVat(BuyOrder $order): bool
  1737.     {
  1738.         return OrderHelper::noVat($order);
  1739.     }
  1740.     public function cmToInch($val): float
  1741.     {
  1742.         if (is_numeric($val)) {
  1743.             return ConversionHelper::convertInch((float) $valConversionHelper::CM);
  1744.         }
  1745.         return 0;
  1746.     }
  1747.     public function resolverScriptSize($item): string
  1748.     {
  1749.         if (is_array($item)) {
  1750.             if (!empty($item['shape']) && $item['shape'] == 7) {
  1751.                 return 'L';
  1752.             } else {
  1753.                 return '&#8960;';
  1754.             }
  1755.         } elseif ($item->getShape() && $item->getShape()->getId() == 7) {
  1756.             return 'L';
  1757.         } else {
  1758.             return '&#8960;';
  1759.         }
  1760.     }
  1761.     public function getUnreadCount(): int
  1762.     {
  1763.         $token UserHelper::getInstance()->getToken();
  1764.         $chat $this->chatBRepository->findOneBy(['token' => $token]);
  1765.         if ($chat) {
  1766.             return $this->chatBMessageRepository->getUnreadMessagesCountForChat($chat);
  1767.         }
  1768.         return 0;
  1769.     }
  1770.     public function getJwt(): string
  1771.     {
  1772.         $token UserHelper::getInstance()->getToken();
  1773.         return $this->jwtGenerator->generateJWT($token);
  1774.     }
  1775.     public function getUserChannel(): string
  1776.     {
  1777.         $token UserHelper::getInstance()->getToken();
  1778.         return "general#$token";
  1779.     }
  1780.     public function useRTWidget(): bool
  1781.     {
  1782.         $setting $this->boolDBSettingRepository->findOneByName('RTWidget');
  1783.         if (null === $setting) {
  1784.             return false;
  1785.         }
  1786.         return $setting->getVal();
  1787.     }
  1788.     /**
  1789.      * @throws Exception
  1790.      */
  1791.     public function getWidgetId(): string
  1792.     {
  1793.         $lang App::getCurLocale(false);
  1794.         $widget $this->widgetRepository->findOneBy(['lang' => $lang]);
  1795.         if (!$widget) {
  1796.             throw new Exception(sprintf('Для языка "%s" не заведен виджет в базе данных'$lang));
  1797.         }
  1798.         return $widget->getWidgetId();
  1799.     }
  1800.     /**
  1801.      * Для испанских клиентов делаем возможность платить Visa, MasterCard, Maestro через Адиен
  1802.      * Все остальные - через БрайнТри
  1803.      */
  1804.     public function getUrlForPaymentByVisa(BuyOrder $order): string
  1805.     {
  1806.         if (OrderHelper::country($order) === CountryNumberEnum::ES) {
  1807.             return $this->urlGenerator->generate('app_credit_card_form_old', ['hash' => $order->getHash()]);
  1808.         }
  1809.         return $this->urlGenerator->generate('app_credit_card_form', ['hash' => $order->getHash()]);
  1810.     }
  1811.     /**
  1812.      * Для испанских клиентов делаем возможность платить Amex через Адиен
  1813.      * Для валют, кроме евро, долларов и фунтов платить Amex через Адиен
  1814.      * Все остальные - платить Amex через БрайнТри
  1815.      */
  1816.     public function getUrlForPaymentByAmex(BuyOrder $order): string
  1817.     {
  1818.         if (OrderHelper::country($order) === CountryNumberEnum::ES) {
  1819.             return $this->urlGenerator->generate('app_credit_card_form_old', ['hash' => $order->getHash()]);
  1820.         }
  1821.         if (OrderHelper::availableAdyenAmex($order)) {
  1822.             return $this->urlGenerator->generate('app_credit_card_form_old', ['hash' => $order->getHash()]);
  1823.         }
  1824.         return $this->urlGenerator->generate('app_credit_card_form', ['hash' => $order->getHash()]);
  1825.     }
  1826. }