54 return Integration\EventHandler::onConnectorList($data);
66 foreach($endpointList as $endpoint)
68 $arResult[$endpoint[
'MODULE_ID']][$endpoint[
'CODE']][] = $endpoint[
'FIELDS'];
85 foreach($postData as $moduleId => $settings)
87 if (is_numeric($moduleId))
92 foreach($settings as $code => $items)
94 foreach($items as $num => $field)
96 if (isset($fieldsTmp[$moduleId][$code][$num]) && is_array($field))
98 foreach($field as $fieldName => $fieldValue)
100 if(!isset($fieldsTmp[$moduleId][$code][$num][$fieldName]))
102 $fieldsTmp[$moduleId][$code][$num][$fieldName] = $fieldValue;
106 if(!is_array($fieldsTmp[$moduleId][$code][$num][$fieldName]))
108 $fieldsTmp[$moduleId][$code][$num][$fieldName] = array(
109 $fieldsTmp[$moduleId][$code][$num][$fieldName]
113 if(is_array($fieldValue))
115 $fieldsTmp[$moduleId][$code][$num][$fieldName] = array_merge(
116 $fieldsTmp[$moduleId][$code][$num][$fieldName],
122 $fieldsTmp[$moduleId][$code][$num][$fieldName][] = $fieldValue;
130 if ($field && is_string($field))
134 $field = Json::decode($field);
140 else if ($field && is_array($field))
142 $fieldsTmp[$moduleId][$code][$num] = $field;
149 $fieldsTmp[$moduleId][$code][$num] = $field;
156 foreach($fieldsTmp as $moduleId => $settings)
158 if(is_numeric($moduleId))
163 foreach($settings as $code => $items)
165 foreach($items as $filter => $fields)
167 if (!is_array($result))
173 'MODULE_ID' => $moduleId,
176 'FILTER_ID' => $moduleId .
"_" . $code .
"_" . $filter,
194 $connectors = static::getConnectorList(array($endpoint));
209 public static function getConnectorList(array $endpointList =
null)
211 $connectorList = array();
213 $connectorClassList = static::getConnectorClassList($endpointList);
214 foreach($connectorClassList as $connectorDescription)
217 $connector =
new $connectorDescription[
'CLASS_NAME'];
218 $connector->setModuleId($connectorDescription[
'MODULE_ID']);
222 return $connectorList;
231 public static function getConnectorClassList(array $endpointList =
null)
233 $resultList = array();
234 $moduleIdFilter =
null;
235 $moduleConnectorFilter =
null;
239 $moduleIdFilter = array();
240 foreach($endpointList as $endpoint)
242 $moduleIdFilter[] = $endpoint[
'MODULE_ID'];
243 $moduleConnectorFilter[$endpoint[
'MODULE_ID']][] = $endpoint[
'CODE'];
248 $event =
new Event(
'sender',
'OnConnectorList', array($data), $moduleIdFilter);
251 foreach ($event->getResults() as $eventResult)
253 if ($eventResult->getType() == EventResult::ERROR)
258 $eventResultParameters = $eventResult->getParameters();
260 if($eventResultParameters && array_key_exists(
'CONNECTOR', $eventResultParameters))
262 $connectorClassNameList = $eventResultParameters[
'CONNECTOR'];
263 if (!is_array($eventResultParameters[
'CONNECTOR']))
265 $connectorClassNameList = array($connectorClassNameList);
267 foreach ($connectorClassNameList as $connectorClassName)
269 if(!is_subclass_of($connectorClassName,
'\Bitrix\Sender\Connector'))
277 $connectorInstance =
new $connectorClassName;
279 $connectorCode = $connectorInstance->getCode();
280 if($moduleConnectorFilter && !in_array($connectorCode, $moduleConnectorFilter[$eventResult->getModuleId()]))
285 $connectorName = $connectorInstance->getName();
286 $connectorRequireConfigure =$connectorInstance->requireConfigure();
288 $resultList[] = array(
289 'MODULE_ID' => $eventResult->getModuleId(),
290 'CLASS_NAME' => $connectorClassName,
291 'CODE' => $connectorCode,
292 'NAME' => $connectorName,
293 'REQUIRE_CONFIGURE' => $connectorRequireConfigure,
299 if(!empty($resultList))
300 usort($resultList, array(__CLASS__,
'sort'));
312 public static function sort($a, $b)
314 if ($a[
'NAME'] == $b[
'NAME'])
317 return ($a[
'NAME'] < $b[
'NAME']) ? -1 : 1;