Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Manager.php
1<?php
2
4
8
15{
16 public const PROVIDER_STORE_DOCUMENT = 'StoreDocument';
17 public const PROVIDER_AGENT_CONTRACT = 'AgentContract';
18
19 private const ON_GET_PROVIDER_EVENT = 'onGetContractorsProvider';
20 private const ON_GET_CONVERTER_EVENT = 'onGetContractorsConverter';
21
25 public static function getActiveProvider(string $providerName): ?IProvider
26 {
27 $converter = self::getConverter();
28 if (!$converter)
29 {
30 return null;
31 }
32
33 static $isMigrating = false;
34 if (!$converter::isMigrated())
35 {
36 if (!$isMigrating)
37 {
38 $isMigrating = true;
39 $converter::runMigration();
40 }
41
42 return null;
43 }
44
45 return self::getProvider($providerName);
46 }
47
48 public static function isActiveProviderExists(): bool
49 {
50 $event = new Event('catalog', self::ON_GET_PROVIDER_EVENT);
51 $event->send();
52
53 $resultList = $event->getResults();
54
55 if (is_array($resultList))
56 {
58 foreach ($resultList as $eventResult)
59 {
60 $providers = $eventResult->getParameters();
61 foreach ($providers as $provider)
62 {
63 if ($provider instanceof IProvider)
64 {
65 return true;
66 }
67 }
68 }
69 }
70
71 return false;
72 }
73
78 public static function isActiveProviderByModule(string $providerName, string $moduleId): bool
79 {
80 $provider = self::getActiveProvider($providerName);
81
82 return $provider && $provider::getModuleId() === $moduleId;
83 }
84
88 public static function getMigrationProgressHtml(): string
89 {
90 ob_start();
91
92 $converter = self::getConverter();
93 if (
94 $converter
95 && !$converter::isMigrated()
96 )
97 {
98 $converter::showMigrationProgress();
99 }
100
101 return ob_get_clean();
102 }
103
107 private static function getProvider(string $providerName): ?IProvider
108 {
109 $event = new Event('catalog', self::ON_GET_PROVIDER_EVENT);
110 $event->send();
111
112 $resultList = $event->getResults();
113
114 if (is_array($resultList))
115 {
117 foreach ($resultList as $eventResult)
118 {
119 $providers = $eventResult->getParameters();
120 foreach ($providers as $name => $provider)
121 {
122 if ($name === $providerName && $provider instanceof IProvider)
123 {
124 return $provider;
125 }
126 }
127 }
128 }
129
130 return null;
131 }
132
133 private static function getConverter(): ?IConverter
134 {
135 $event = new Event('catalog', self::ON_GET_CONVERTER_EVENT);
136 $event->send();
137
138 $resultList = $event->getResults();
139
140 if (is_array($resultList))
141 {
143 foreach ($resultList as $eventResult)
144 {
145 $provider = $eventResult->getParameters();
146 if ($provider instanceof IConverter)
147 {
148 return $provider;
149 }
150 }
151 }
152
153 return null;
154 }
155}
static isActiveProviderByModule(string $providerName, string $moduleId)
Definition Manager.php:78
static getActiveProvider(string $providerName)
Definition Manager.php:25