CCrmEMail::TryImportVCard

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmEMail
  4. TryImportVCard
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_email.php
  • Класс: \CCrmEMail
  • Вызов: CCrmEMail::TryImportVCard
static function TryImportVCard(&$fileData, $responsible = null)
{
	$CCrmVCard = new CCrmVCard();
	$arContact = $CCrmVCard->ReadCard(false, $fileData);

	if (empty($arContact['NAME']) && empty($arContact['LAST_NAME']))
	{
		return false;
	}

	$arFilter = array();
	if (!empty($arContact['NAME']))
	{
		$arFilter['NAME'] = $arContact['NAME'];
	}
	if (!empty($arContact['LAST_NAME']))
	{
		$arFilter['LAST_NAME'] = $arContact['LAST_NAME'];
	}
	if (!empty($arContact['SECOND_NAME']))
	{
		$arFilter['SECOND_NAME'] = $arContact['SECOND_NAME'];
	}

	$arFilter['CHECK_PERMISSIONS'] = 'N';

	$dbContact = CCrmContact::GetListEx(array(), $arFilter, false, false, array('ID'));
	if ($dbContact->Fetch())
	{
		return false;
	}

	$arContact['SOURCE_ID'] = 'EMAIL';
	if (!empty($arContact['COMPANY_TITLE']))
	{
		$dbCompany = CCrmCompany::GetListEx(
			array(),
			array(
				'TITLE' => $arContact['COMPANY_TITLE'],
				'CHECK_PERMISSIONS' => 'N'
			),
			false,
			false,
			array('ID')
		);

		if (($arCompany = $dbCompany->Fetch()) !== false)
		{
			$arContact['COMPANY_ID'] = $arCompany['ID'];
		}
		else
		{
			if(!empty($arContact['COMMENTS']))
			{
				$arContact['COMMENTS'] .= PHP_EOL;
			}
			$arContact['COMMENTS'] .=
				GetMessage('CRM_MAIL_COMPANY_NAME', array('%TITLE%' => $arContact['COMPANY_TITLE']));
		}
	}

	if ($responsible <= 0)
	{
		$responsible = self::getDefaultResponsibleId(CCrmOwnerType::Contact);
		if ($responsible <= 0)
			$responsible = self::getDefaultResponsibleId(CCrmOwnerType::Lead);
	}

	if ($responsible > 0)
		$arContact['CREATED_BY_ID'] = $arContact['MODIFY_BY_ID'] = $arContact['ASSIGNED_BY_ID'] = $responsible;

	$CCrmContact = new CCrmContact(false);
	$CCrmContact->Add(
		$arContact,
		true,
		array('DISABLE_USER_FIELD_CHECK' => true)
	);

	return true;
}

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