• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_crm_helper.php
  • Класс: CVoxImplantCrmHelper
  • Вызов: CVoxImplantCrmHelper::convertEntityFields
static function convertEntityFields($entityType, $entityData)
{
	if(!CModule::IncludeModule('crm'))
		return false;

	$result = array(
		'FOUND' => 'N',
		'CONTACT' => array(),
		'COMPANY' => array(),
		'ACTIVITIES' => array(),
		'DEALS' => array(),
		'LEAD' => null,
		'RESPONSIBILITY' => array(),
		'STATUS_TEXT' => null,
		'STATUS_COLOR' => null,
	);

	switch ($entityType)
	{
		case CCrmOwnerType::ContactName:
			$result['FOUND'] = 'Y';
			$result['CONTACT'] = array(
				'NAME' => $entityData['FORMATTED_NAME'],
				'POST' => $entityData['POST'],
				'PHOTO' => '',
			);
			if (intval($entityData['PHOTO']) > 0)
			{
				$photo = CFile::ResizeImageGet(
					$entityData['PHOTO'],
					array('width' => 370, 'height' => 370),
					BX_RESIZE_IMAGE_EXACT,
					false,
					false,
					true
				);
				$result['CONTACT']['PHOTO'] = $photo['src'];
			}

			$result['COMPANY'] = $entityData['COMPANY_TITLE'];

			$result['CONTACT_DATA'] = array(
				'ID' => $entityData['ID'],
			);
			break;
		case CCrmOwnerType::LeadName:
			$result['FOUND'] = 'Y';
			$result['CONTACT'] = array(
				'ID' => 0,
				'NAME' => !empty($entityData['FORMATTED_NAME'])? $entityData['FORMATTED_NAME']: $entityData['TITLE'],
				'POST' => $entityData['POST'],
				'PHOTO' => '',
			);

			$result['COMPANY'] = $entityData['COMPANY_TITLE'];

			$result['LEAD_DATA'] = array(
				'ID' => $entityData['ID'],
				'ASSIGNED_BY_ID' => $entityData['ASSIGNED_BY_ID']
			);
			break;
		case CCrmOwnerType::CompanyName:
			$result['FOUND'] = 'Y';
			$result['COMPANY'] = $entityData['TITLE'];
			$result['COMPANY_DATA'] = array(
				'ID' => $entityData['ID'],
			);
			break;
	}

	if ($entityData['ASSIGNED_BY_ID'] > 0)
	{
		if ($user = BitrixMainUserTable::getById($entityData['ASSIGNED_BY_ID'])->fetch())
		{
			$userPhoto = CFile::ResizeImageGet(
				$user['PERSONAL_PHOTO'],
				array('width' => 37, 'height' => 37),
				BX_RESIZE_IMAGE_EXACT,
				false,
				false,
				true
			);

			$result['RESPONSIBILITY'] = array(
				'ID' => $user['ID'],
				'NAME' => CUser::FormatName(CSite::GetNameFormat(false), $user, true, false),
				'PHOTO' => $userPhoto ? $userPhoto['src']: '',
				'POST' => $user['WORK_POSITION'],
			);
		}
	}

	if (isset($entityData['LEAD']))
	{
		$result['LEAD'] = $entityData['LEAD'];
	}

	if (isset($entityData['STATUS_TEXT']))
	{
		$result['STATUS_TEXT'] = $entityData['STATUS_TEXT'];
	}

	if (isset($entityData['STATUS_COLOR']))
	{
		$result['STATUS_COLOR'] = $entityData['STATUS_COLOR'];
	}

	if (isset($entityData['SHOW_URL']))
	{
		$result['SHOW_URL'] = $entityData['SHOW_URL'];
	}

	if (isset($entityData['ACTIVITY_LIST_URL']))
	{
		$result['ACTIVITY_URL'] = $entityData['ACTIVITY_LIST_URL'];
	}

	if (isset($entityData['INVOICE_LIST_URL']))
	{
		$result['INVOICE_URL'] = $entityData['INVOICE_LIST_URL'];
	}

	if (isset($entityData['DEAL_LIST_URL']))
	{
		$result['DEAL_URL'] = $entityData['DEAL_LIST_URL'];
	}

	return $result;
}