• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/communication/manager.php
  • Класс: Bitrix\Crm\Communication\Manager
  • Вызов: Manager::getCommunicationData
static function getCommunicationData(
	$entityTypeID,
	array $entityIDs,
	array $communicationTypeIDs = null,
	array $options = null
)
{
	if(!is_array($options))
	{
		$options = array();
	}

	$typeIDs = array();
	if(is_array($communicationTypeIDs))
	{
		foreach($communicationTypeIDs as $communicationTypeID)
		{
			if($communicationTypeID === Crm\Communication\Type::PHONE)
			{
				$typeIDs[] = \CCrmFieldMulti::PHONE;
			}
			elseif($communicationTypeID === Crm\Communication\Type::EMAIL)
			{
				$typeIDs[] = \CCrmFieldMulti::EMAIL;
			}
		}
	}

	$entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
	$filter = array('=ENTITY_ID' => $entityTypeName, '@ELEMENT_ID' => $entityIDs);

	if(!empty($typeIDs))
	{
		$filter['@TYPE_ID'] = $typeIDs;
	}

	$dbResult = \CCrmFieldMulti::GetListEx(
		array(),
		$filter,
		false,
		false,
		array('ELEMENT_ID', 'TYPE_ID', 'VALUE', 'VALUE_TYPE')
	);

	$deduplicate = isset($options['deduplicate']) && $options['deduplicate'] === true;

	$results = array();
	while($fields = $dbResult->Fetch())
	{
		$elementID = $fields['ELEMENT_ID'];
		$typeID = $fields['TYPE_ID'];
		$value = isset($fields['VALUE']) ? $fields['VALUE'] : '';

		$key = $elementID.':'.$typeID.':'.md5(mb_strtoupper(trim($value)));
		if($deduplicate && isset($results[$key]))
		{
			continue;
		}

		$results[$key] = array(
			'ENTITY_ID' => $elementID,
			'ENTITY_TYPE_ID' => $entityTypeID,
			'ENTITY_TYPE' => $entityTypeName,
			'TYPE' => $typeID,
			'VALUE' => $value,
			'VALUE_TYPE' => isset($fields['VALUE_TYPE']) ? $fields['VALUE_TYPE'] : ''
		);
	}
	return array_values($results);
}