CAllCrmActivity::PrepareCommunicationInfo

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmActivity
  4. PrepareCommunicationInfo
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
  • Класс: \CAllCrmActivity
  • Вызов: CAllCrmActivity::PrepareCommunicationInfo
static function PrepareCommunicationInfo(&$arComm, $arFields = null, $enabledEmptyNameStub = true)
{
	if(!isset($arComm['ENTITY_SETTINGS']))
	{
		if(!self::PrepareCommunicationSettings($arComm, $arFields))
		{
			$arComm['TITLE'] = '';
			$arComm['DESCRIPTION'] = '';
			return false;
		}
	}

	$title = '';
	$description = '';
	$entityTypeID = isset($arComm['ENTITY_TYPE_ID']) ? intval($arComm['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
	if($entityTypeID === CCrmOwnerType::Lead)
	{
		$honorific = '';
		$name = '';
		$secondName = '';
		$lastName = '';
		$leadTitle = '';

		if(is_array(($arComm['ENTITY_SETTINGS'])))
		{
			$settings = $arComm['ENTITY_SETTINGS'];

			$honorific = isset($settings['HONORIFIC']) ? $settings['HONORIFIC'] : '';
			$name = isset($settings['NAME']) ? $settings['NAME'] : '';
			$secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : '';
			$lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : '';
			$leadTitle = isset($settings['LEAD_TITLE']) ? $settings['LEAD_TITLE'] : '';
		}
		else
		{
			$arEntity = CCrmLead::GetByID($arComm['ENTITY_ID']);
			if($arEntity)
			{
				$honorific = isset($arEntity['HONORIFIC']) ? $arEntity['HONORIFIC'] : '';
				$name = isset($arEntity['NAME']) ? $arEntity['NAME'] : '';
				$secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : '';
				$lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : '';
				$leadTitle = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : '';
			}
		}

		if($name === '' && $secondName === '' && $lastName === '')
		{
			$title = $leadTitle;
		}
		else
		{
			$title = CCrmLead::PrepareFormattedName(
				array(
					'HONORIFIC' => $honorific,
					'NAME' => $name,
					'SECOND_NAME' => $secondName,
					'LAST_NAME' => $lastName
				)
			);
			$description = $leadTitle;
		}
	}
	if($entityTypeID === CCrmOwnerType::Deal)
	{
		$dealTitle = '';

		if(is_array(($arComm['ENTITY_SETTINGS'])))
		{
			$settings = $arComm['ENTITY_SETTINGS'];
			$dealTitle = isset($settings['DEAL_TITLE']) ? $settings['DEAL_TITLE'] : '';
		}
		else
		{
			$arEntity = CCrmDeal::GetByID($arComm['ENTITY_ID']);
			if($arEntity)
			{
				$dealTitle = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : '';
			}
		}
		$title = $dealTitle;
	}
	elseif($entityTypeID === CCrmOwnerType::Contact)
	{
		// Empty TYPE is person to person communiation, empty ENTITY_ID is unbound communication - no method to build title
		if (!(empty($arComm['TYPE']) && intval($arComm['ENTITY_ID']) === 0))
		{
			$honorific = '';
			$name = '';
			$secondName = '';
			$lastName = '';
			$companyTitle = '';

			if(is_array($arComm['ENTITY_SETTINGS']) && !empty($arComm['ENTITY_SETTINGS']))
			{
				$settings = $arComm['ENTITY_SETTINGS'];

				$honorific = isset($settings['HONORIFIC']) ? $settings['HONORIFIC'] : '';
				$name = isset($settings['NAME']) ? $settings['NAME'] : '';
				$secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : '';
				$lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : '';
				$companyTitle = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : '';
			}
			else
			{
				$arEntity = CCrmContact::GetByID($arComm['ENTITY_ID']);
				if($arEntity)
				{
					$honorific = isset($arEntity['HONORIFIC']) ? $arEntity['HONORIFIC'] : '';
					$name = isset($arEntity['NAME']) ? $arEntity['NAME'] : '';
					$secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : '';
					$lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : '';
					$companyTitle = isset($arEntity['COMPANY_TITLE']) ? $arEntity['COMPANY_TITLE'] : '';
				}
			}

			$title = CCrmContact::PrepareFormattedName(
				array(
					'HONORIFIC' => $honorific,
					'NAME' => $name,
					'SECOND_NAME' => $secondName,
					'LAST_NAME' => $lastName
				),
				'',
				$enabledEmptyNameStub
			);

			$description = $companyTitle;
		}
	}
	elseif($entityTypeID === CCrmOwnerType::Company)
	{
		if(is_array($arComm['ENTITY_SETTINGS']) && !empty($arComm['ENTITY_SETTINGS']))
		{
			$settings = $arComm['ENTITY_SETTINGS'];
			$title = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : '';
		}
		else
		{
			$arEntity = CCrmCompany::GetByID($arComm['ENTITY_ID']);
			if($arEntity)
			{
				$title = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : '';
			}
		}
	}

	$arComm['TITLE'] = $title;
	$arComm['DESCRIPTION'] = $description;
	return true;
}

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