Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/catalog/lib/v2/Contractor/Provider/ |
Upload File : |
<?php namespace Bitrix\Catalog\v2\Contractor\Provider; use Bitrix\Main\Event; use Bitrix\Main\EventResult; use Bitrix\Catalog\v2\Contractor\IConverter; /** * Class Manager * * @package Bitrix\Catalog\v2\Contractor\Provider */ class Manager { public const PROVIDER_STORE_DOCUMENT = 'StoreDocument'; public const PROVIDER_AGENT_CONTRACT = 'AgentContract'; private const ON_GET_PROVIDER_EVENT = 'onGetContractorsProvider'; private const ON_GET_CONVERTER_EVENT = 'onGetContractorsConverter'; /** * @param string $providerName Contractor provider name. * @return IProvider|null */ public static function getActiveProvider(string $providerName): ?IProvider { $converter = self::getConverter(); if (!$converter) { return null; } static $isMigrating = false; if (!$converter::isMigrated()) { if (!$isMigrating) { $isMigrating = true; $converter::runMigration(); } return null; } return self::getProvider($providerName); } public static function isActiveProviderExists(): bool { $event = new Event('catalog', self::ON_GET_PROVIDER_EVENT); $event->send(); $resultList = $event->getResults(); if (is_array($resultList)) { /** @var EventResult $eventResult */ foreach ($resultList as $eventResult) { $providers = $eventResult->getParameters(); foreach ($providers as $provider) { if ($provider instanceof IProvider) { return true; } } } } return false; } /** * @param string $providerName Contractor provider name. * @param string $moduleId Module identifier. * @return bool */ public static function isActiveProviderByModule(string $providerName, string $moduleId): bool { $provider = self::getActiveProvider($providerName); return $provider && $provider::getModuleId() === $moduleId; } /** * @return string */ public static function getMigrationProgressHtml(): string { ob_start(); $converter = self::getConverter(); if ( $converter && !$converter::isMigrated() ) { $converter::showMigrationProgress(); } return ob_get_clean(); } /** * @param string $providerName Contractor provider name. * @return IProvider|null */ private static function getProvider(string $providerName): ?IProvider { $event = new Event('catalog', self::ON_GET_PROVIDER_EVENT); $event->send(); $resultList = $event->getResults(); if (is_array($resultList)) { /** @var EventResult $eventResult */ foreach ($resultList as $eventResult) { $providers = $eventResult->getParameters(); foreach ($providers as $name => $provider) { if ($name === $providerName && $provider instanceof IProvider) { return $provider; } } } } return null; } private static function getConverter(): ?IConverter { $event = new Event('catalog', self::ON_GET_CONVERTER_EVENT); $event->send(); $resultList = $event->getResults(); if (is_array($resultList)) { /** @var EventResult $eventResult */ foreach ($resultList as $eventResult) { $provider = $eventResult->getParameters(); if ($provider instanceof IConverter) { return $provider; } } } return null; } }