Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
10
15
21{
29 public static function onConnectorListContact($data)
30 {
31 return $data;
32 }
33
41 public static function onConnectorListRecipient($data)
42 {
43 return $data;
44 }
45
52 public static function onConnectorList($data)
53 {
54 return Integration\EventHandler::onConnectorList($data);
55 }
56
63 public static function getFieldsFromEndpoint(array $endpointList)
64 {
65 $arResult = array();
66 foreach($endpointList as $endpoint)
67 {
68 $arResult[$endpoint['MODULE_ID']][$endpoint['CODE']][] = $endpoint['FIELDS'];
69 }
70
71 return $arResult;
72 }
73
80 public static function getEndpointFromFields(array $postData)
81 {
82 $result = null;
83 $fieldsTmp = array();
84
85 foreach($postData as $moduleId => $settings)
86 {
87 if (is_numeric($moduleId))
88 {
89 $moduleId = '';
90 }
91
92 foreach($settings as $code => $items)
93 {
94 foreach($items as $num => $field)
95 {
96 if (isset($fieldsTmp[$moduleId][$code][$num]) && is_array($field))
97 {
98 foreach($field as $fieldName => $fieldValue)
99 {
100 if(!isset($fieldsTmp[$moduleId][$code][$num][$fieldName]))
101 {
102 $fieldsTmp[$moduleId][$code][$num][$fieldName] = $fieldValue;
103 }
104 else
105 {
106 if(!is_array($fieldsTmp[$moduleId][$code][$num][$fieldName]))
107 {
108 $fieldsTmp[$moduleId][$code][$num][$fieldName] = array(
109 $fieldsTmp[$moduleId][$code][$num][$fieldName]
110 );
111 }
112
113 if(is_array($fieldValue))
114 {
115 $fieldsTmp[$moduleId][$code][$num][$fieldName] = array_merge(
116 $fieldsTmp[$moduleId][$code][$num][$fieldName],
117 $fieldValue
118 );
119 }
120 else
121 {
122 $fieldsTmp[$moduleId][$code][$num][$fieldName][] = $fieldValue;
123 }
124
125 }
126 }
127 }
128 else
129 {
130 if ($field && is_string($field))
131 {
132 try
133 {
134 $field = Json::decode($field);
135 }
136 catch (\Exception $exception)
137 {
138 }
139 }
140 else if ($field && is_array($field))
141 {
142 $fieldsTmp[$moduleId][$code][$num] = $field;
143 continue;
144 }
145 else
146 {
147 $field = null;
148 }
149 $fieldsTmp[$moduleId][$code][$num] = $field;
150 }
151 }
152 }
153 }
154
155
156 foreach($fieldsTmp as $moduleId => $settings)
157 {
158 if(is_numeric($moduleId))
159 {
160 $moduleId = '';
161 }
162
163 foreach($settings as $code => $items)
164 {
165 foreach($items as $filter => $fields)
166 {
167 if (!is_array($result))
168 {
169 $result = array();
170 }
171
172 $result[] = array(
173 'MODULE_ID' => $moduleId,
174 'CODE' => $code,
175 'FIELDS' => $fields,
176 'FILTER_ID' => $moduleId . "_" . $code . "_" . $filter,
177 );
178 }
179 }
180 }
181
182 return $result;
183 }
184
191 public static function getConnector(array $endpoint)
192 {
193 $connector = null;
194 $connectors = static::getConnectorList(array($endpoint));
195 foreach($connectors as $connector)
196 {
197 break;
198 }
199
200 return $connector;
201 }
202
209 public static function getConnectorList(array $endpointList = null)
210 {
211 $connectorList = array();
212
213 $connectorClassList = static::getConnectorClassList($endpointList);
214 foreach($connectorClassList as $connectorDescription)
215 {
217 $connector = new $connectorDescription['CLASS_NAME'];
218 $connector->setModuleId($connectorDescription['MODULE_ID']);
219 $connectorList[] = $connector;
220 }
221
222 return $connectorList;
223 }
224
231 public static function getConnectorClassList(array $endpointList = null)
232 {
233 $resultList = array();
234 $moduleIdFilter = null;
235 $moduleConnectorFilter = null;
236
237 if($endpointList)
238 {
239 $moduleIdFilter = array();
240 foreach($endpointList as $endpoint)
241 {
242 $moduleIdFilter[] = $endpoint['MODULE_ID'];
243 $moduleConnectorFilter[$endpoint['MODULE_ID']][] = $endpoint['CODE'];
244 }
245 }
246
247 $data = array();
248 $event = new Event('sender', 'OnConnectorList', array($data), $moduleIdFilter);
249 $event->send();
250
251 foreach ($event->getResults() as $eventResult)
252 {
253 if ($eventResult->getType() == EventResult::ERROR)
254 {
255 continue;
256 }
257
258 $eventResultParameters = $eventResult->getParameters();
259
260 if($eventResultParameters && array_key_exists('CONNECTOR', $eventResultParameters))
261 {
262 $connectorClassNameList = $eventResultParameters['CONNECTOR'];
263 if (!is_array($eventResultParameters['CONNECTOR']))
264 {
265 $connectorClassNameList = array($connectorClassNameList);
266 }
267 foreach ($connectorClassNameList as $connectorClassName)
268 {
269 if(!is_subclass_of($connectorClassName, '\Bitrix\Sender\Connector'))
270 {
271 continue;
272 }
273
277 $connectorInstance = new $connectorClassName;
278
279 $connectorCode = $connectorInstance->getCode();
280 if($moduleConnectorFilter && !in_array($connectorCode, $moduleConnectorFilter[$eventResult->getModuleId()]))
281 {
282 continue;
283 }
284
285 $connectorName = $connectorInstance->getName();
286 $connectorRequireConfigure =$connectorInstance->requireConfigure();
287
288 $resultList[] = array(
289 'MODULE_ID' => $eventResult->getModuleId(),
290 'CLASS_NAME' => $connectorClassName,
291 'CODE' => $connectorCode,
292 'NAME' => $connectorName,
293 'REQUIRE_CONFIGURE' => $connectorRequireConfigure,
294 );
295 }
296 }
297 }
298
299 if(!empty($resultList))
300 usort($resultList, array(__CLASS__, 'sort'));
301
302 return $resultList;
303 }
304
312 public static function sort($a, $b)
313 {
314 if ($a['NAME'] == $b['NAME'])
315 return 0;
316
317 return ($a['NAME'] < $b['NAME']) ? -1 : 1;
318 }
319}
static onConnectorListRecipient($data)
Definition manager.php:41
static getConnector(array $endpoint)
Definition manager.php:191
static getEndpointFromFields(array $postData)
Definition manager.php:80
static getFieldsFromEndpoint(array $endpointList)
Definition manager.php:63
static onConnectorListContact($data)
Definition manager.php:29