CrmContacts::prepareEntity

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CrmContacts
  4. prepareEntity
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/main/uiselector/crmcontacts.php
  • Класс: Bitrix\Crm\Integration\Main\UISelector\CrmContacts
  • Вызов: CrmContacts::prepareEntity
static function prepareEntity($data, $options = [])
{
	$prefix = static::getPrefix($options);
	$result = [
		'id' => $prefix . $data['ID'],
		'entityType' => 'contacts',
		'entityId' => $data['ID'],
		'name' => htmlspecialcharsbx(
			CCrmContact::prepareFormattedName([
					'HONORIFIC' => $data['HONORIFIC'] ?? '',
					'NAME' => isset($data['NAME']) ? Emoji::decode($data['NAME']) : '',
					'SECOND_NAME' => isset($data['SECOND_NAME']) ? Emoji::decode($data['SECOND_NAME']) : '',
					'LAST_NAME' => isset($data['LAST_NAME']) ? Emoji::decode($data['LAST_NAME']) : ''
			])
		),
		'desc' => htmlspecialcharsbx($data['COMPANY_TITLE'])
	];

	if (array_key_exists('DATE_CREATE', $data))
	{
		$result['date'] = MakeTimeStamp($data['DATE_CREATE']);
	}

	if (
		!empty($data['PHOTO'])
		&& intval($data['PHOTO']) > 0
	)
	{
		$imageFields = \CFile::resizeImageGet(
			$data['PHOTO'],
			['width' => 100, 'height' => 100],
			BX_RESIZE_IMAGE_EXACT
		);
		$result['avatar'] = $imageFields['src'];
	}

	if (
		!empty($data['HAS_EMAIL'])
		&& $data['HAS_EMAIL'] == 'Y'
	)
	{
		$multiEmailsList = [];
		$found = false;

		$res = CCrmFieldMulti::getList(
			['ID' => 'asc'],
			[
				'ENTITY_ID' => static::getOwnerTypeName(),
				'TYPE_ID' => CCrmFieldMulti::EMAIL,
				'ELEMENT_ID' => $data['ID'],
			]
		);
		while ($multiFields = $res->Fetch())
		{
			if (!empty($multiFields['VALUE']))
			{
				$multiEmailsList[] = htmlspecialcharsbx($multiFields['VALUE']);
				if (!$found)
				{
					$result['email'] = htmlspecialcharsbx($multiFields['VALUE']);
					if (
						isset($options['onlyWithEmail'])
						&& $options['onlyWithEmail'] == 'Y'
					)
					{
						$result['desc'] = $result['email'];
					}
					$found = true;
				}
			}
		}
		$result['multiEmailsList'] = $multiEmailsList;
	}

	if (
		isset($options['returnItemUrl'])
		&& $options['returnItemUrl'] == 'Y'
	)
	{
		$result['url'] = CCrmOwnerType::getEntityShowPath(static::getOwnerType(), $data['ID']);
		$result['urlUseSlider'] = (CCrmOwnerType::isSliderEnabled(static::getOwnerType()) ? 'Y' : 'N');
	}

	return $result;
}

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