CCrmSipHelper::findByPhoneNumber

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmSipHelper
  4. findByPhoneNumber
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/sip_helper.php
  • Класс: \CCrmSipHelper
  • Вызов: CCrmSipHelper::findByPhoneNumber
static function findByPhoneNumber($number, $params = array())
{
	if (!is_string($number))
	{
		throw new \Bitrix\Main\ArgumentTypeException('number', 'string');
	}

	if ($number === '')
	{
		throw new \Bitrix\Main\ArgumentException('Is empty', 'number');
	}

	if (!is_array($params))
	{
		$params = array();
	}

	$dups = array();
	$criterion = new \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion('PHONE', $number);
	$entityTypes = array(CCrmOwnerType::Contact, CCrmOwnerType::Company, CCrmOwnerType::Lead);
	foreach ($entityTypes as $entityType)
	{
		$duplicate = $criterion->find($entityType, 1);
		if ($duplicate !== null)
		{
			$dups[] = $duplicate;
		}
	}

	$entityByType = array();
	foreach ($dups as &$dup)
	{
		/** @var \Bitrix\Crm\Integrity\Duplicate $dup */
		$entities = $dup->getEntities();
		if (!(is_array($entities) && !empty($entities)))
		{
			continue;
		}

		//Each entity type limited by 50 items
		foreach ($entities as &$entity)
		{
			/** @var \Bitrix\Crm\Integrity\DuplicateEntity $entity */
			$entityTypeID = $entity->getEntityTypeID();
			$entityID = $entity->getEntityID();

			$fields = self::getEntityFields($entityTypeID, $entityID, $params);
			if(!is_array($fields))
				continue;

			$entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
			if (!isset($entityByType[$entityTypeName]))
			{
				$entityByType[$entityTypeName] = array($fields);
			}
			elseif (!in_array($entityID, $entityByType[$entityTypeName], true))
			{
				$entityByType[$entityTypeName][] = $fields;
			}
		}
	}
	unset($dup);
	return $entityByType;
}

Добавить комментарий