• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/im/messages/crm.php
  • Класс: BitrixImOpenLinesImMessagesCrm
  • Вызов: Crm::getEntityCard
protected function getEntityCard(string $entityType, array $entityIds): ?CIMMessageParamAttach
{
	if (
		Loader::includeModule('im')
		&& in_array($entityType, [ImOpenLinesCrm::ENTITY_LEAD, ImOpenLinesCrm::ENTITY_CONTACT, ImOpenLinesCrm::ENTITY_COMPANY, ImOpenLinesCrm::ENTITY_DEAL])
	)
	{
		$attach = new CIMMessageParamAttach();

		foreach ($entityIds as $entityId)
		{
			$entityData = ImOpenLinesCrmCommon::get($entityType, $entityId, true);
			if (!$entityData)
			{
				continue;
			}

			$entityGrid = [];
			if ($entityType == ImOpenLinesCrm::ENTITY_LEAD)
			{
				if (isset($entityData['TITLE']))
				{
					$attach->addLink([
						'NAME' => $entityData['TITLE'],
						'LINK' => ImOpenLinesCrmCommon::getLink($entityType, $entityData['ID']),
					]);
				}

				if (
					!empty($entityData['FULL_NAME'])
					&& mb_strpos($entityData['TITLE'], $entityData['FULL_NAME']) === false
				)
				{
					$entityGrid[] = [
						'DISPLAY' => 'COLUMN',
						'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_FULL_NAME'),
						'VALUE' => $entityData['FULL_NAME']
					];
				}
				if (!empty($entityData['COMPANY_TITLE']))
				{
					$entityGrid[] = [
						'DISPLAY' => 'COLUMN',
						'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_COMPANY_TITLE'),
						'VALUE' => $entityData['COMPANY_TITLE']
					];
				}
				if (!empty($entityData['POST']))
				{
					$entityGrid[] = [
						'DISPLAY' => 'COLUMN',
						'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_POST'),
						'VALUE' => $entityData['POST']
					];
				}
			}
			elseif ($entityType == ImOpenLinesCrm::ENTITY_CONTACT)
			{
				if (isset($entityData['FULL_NAME']))
				{
					$attach->addLink([
						'NAME' => $entityData['FULL_NAME'],
						'LINK' => ImOpenLinesCrmCommon::getLink($entityType, $entityData['ID']),
					]);
				}

				if (!empty($entityData['POST']))
				{
					$entityGrid[] = [
						'DISPLAY' => 'COLUMN',
						'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_POST'),
						'VALUE' => $entityData['POST']
					];
				}
			}
			elseif ($entityType == ImOpenLinesCrm::ENTITY_COMPANY || $entityType == ImOpenLinesCrm::ENTITY_DEAL)
			{
				if (isset($entityData['TITLE']))
				{
					$attach->addLink([
						'NAME' => $entityData['TITLE'],
						'LINK' => ImOpenLinesCrmCommon::getLink($entityType, $entityData['ID']),
					]);
				}
			}

			if (
				isset($entityData['HAS_PHONE'])
				&& $entityData['HAS_PHONE'] == 'Y'
				&& isset($entityData['FM']['PHONE'])
			)
			{
				$fields = [];
				foreach ($entityData['FM']['PHONE'] as $phones)
				{
					foreach ($phones as $phone)
					{
						$fields[] = $phone;
					}
				}
				$entityGrid[] = [
					'DISPLAY' => 'LINE',
					'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_PHONE'),
					'VALUE' => implode('[br]', $fields),
					'HEIGHT' => '20'
				];
			}
			if ($entityData['HAS_EMAIL'] == 'Y' && $entityData['FM']['EMAIL'])
			{
				$fields = [];
				foreach ($entityData['FM']['EMAIL'] as $emails)
				{
					foreach ($emails as $email)
					{
						$fields[] = $email;
					}
				}
				$entityGrid[] = [
					'DISPLAY' => 'LINE',
					'NAME' => Loc::getMessage('IMOL_MESSAGE_CRM_CARD_EMAIL'),
					'VALUE' => implode('[br]', $fields),
					'HEIGHT' => '20'
				];
			}

			$attach->addGrid($entityGrid);
		}

		if (!$attach->isEmpty())
		{
			return $attach;
		}
	}

	return null;
}