CCrmOwnerType::PrepareEntityInfo

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmOwnerType
  4. PrepareEntityInfo
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_owner_type.php
  • Класс: \CCrmOwnerType
  • Вызов: CCrmOwnerType::PrepareEntityInfo
static function PrepareEntityInfo($typeID, $ID, &$arRes, $options = null)
{
	$enableSlider = \Bitrix\Crm\Settings\LayoutSettings::getCurrent()->isSliderEnabled();
	$enableEditUrl = is_array($options) && isset($options['ENABLE_EDIT_URL']) && $options['ENABLE_EDIT_URL'] === true;

	switch($typeID)
	{
		case self::Lead:
		{
			$treatAsContact = false;
			$treatAsCompany = false;

			if(is_array($options))
			{
				$treatAsContact = isset($options['TREAT_AS_CONTACT']) && $options['TREAT_AS_CONTACT'];
				$treatAsCompany = isset($options['TREAT_AS_COMPANY']) && $options['TREAT_AS_COMPANY'];
			}

			if($treatAsContact)
			{
				$result = array(
					'TITLE' => CCrmLead::PrepareFormattedName($arRes),
					'LEGEND' => isset($arRes['TITLE']) ? $arRes['TITLE'] : ''
				);
			}
			elseif($treatAsCompany)
			{
				$result = array(
					'TITLE' => isset($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '',
					'LEGEND' => isset($arRes['TITLE']) ? $arRes['TITLE'] : ''
				);
			}
			else
			{
				$result = array(
					'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '',
					'LEGEND' => CCrmLead::PrepareFormattedName($arRes)
				);
			}

			$result['RESPONSIBLE_ID'] = isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0;
			$result['IMAGE_FILE_ID'] = 0;
			$result['SHOW_URL'] = CComponentEngine::MakePathFromTemplate(
				COption::GetOptionString('crm', $enableSlider ? 'path_to_lead_details' : 'path_to_lead_show'),
				array('lead_id' => $ID)
			);
			$result['ENTITY_TYPE_CAPTION'] = static::GetDescription(static::Lead);

			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_lead_details' :'path_to_lead_edit'),
						array('lead_id' => $ID)
					);
			}
			return $result;
		}
		case self::Contact:
		{
			$result = array(
				'TITLE' => CCrmContact::PrepareFormattedName($arRes),
				'LEGEND' => isset($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '',
				'POST' => isset($arRes['POST']) ? $arRes['POST'] : '',
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'IMAGE_FILE_ID' => isset($arRes['PHOTO']) ? intval($arRes['PHOTO']) : 0,
				'SHOW_URL' =>
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_contact_details' : 'path_to_contact_show'),
						array('contact_id' => $ID)
					),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Contact),
			);
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_contact_details' : 'path_to_contact_edit'),
						array('contact_id' => $ID)
					);
			}
			return $result;
		}
		case self::Company:
		{
			if(self::$COMPANY_TYPE === null)
			{
				self::$COMPANY_TYPE = CCrmStatus::GetStatusList('COMPANY_TYPE');
			}
			if(self::$COMPANY_INDUSTRY === null)
			{
				self::$COMPANY_INDUSTRY = CCrmStatus::GetStatusList('INDUSTRY');
			}

			$legendParts = array();

			$typeID = isset($arRes['COMPANY_TYPE']) ? $arRes['COMPANY_TYPE'] : '';
			if($typeID !== '' && isset(self::$COMPANY_TYPE[$typeID]))
			{
				$legendParts[] = self::$COMPANY_TYPE[$typeID];
			}

			$industryID = isset($arRes['INDUSTRY']) ? $arRes['INDUSTRY'] : '';
			if($industryID !== '' && isset(self::$COMPANY_INDUSTRY[$industryID]))
			{
				$legendParts[] = self::$COMPANY_INDUSTRY[$industryID];
			}

			$result = array(
				'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '',
				'LEGEND' => !empty($legendParts) ? implode(', ', $legendParts) : '',
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'IMAGE_FILE_ID' => isset($arRes['LOGO']) ? intval($arRes['LOGO']) : 0,
				'SHOW_URL' =>
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_company_details' : 'path_to_company_show'),
						array('company_id' => $ID)
					),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Company),
				'IS_MY_COMPANY' => isset($arRes['IS_MY_COMPANY']) ? ($arRes['IS_MY_COMPANY'] === 'Y') : false,
			);
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_company_details' : 'path_to_company_edit'),
						array('company_id' => $ID)
					);
			}
			return $result;
		}
		case self::Deal:
		{
			$date = new Bitrix\Main\Type\Date($arRes['DATE_CREATE']);

			$result = [
				'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '',
				'LEGEND' => GetMessage('CRM_OWNER_TYPE_DEAL_LEGEND', [
					"#DATE_CREATE#" =>  FormatDate(
						Bitrix\Main\Context::getCurrent()->getCulture()->getLongDateFormat(),
						$date->getTimestamp()
					),
					"#SUM_WITH_CURRENCY#" => \CCrmCurrency::MoneyToString(
						$arRes['OPPORTUNITY'],
						$arRes['CURRENCY_ID']
					),
				]),
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' =>
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_deal_details' : 'path_to_deal_show'),
						['deal_id' => $ID]
					),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Deal),
			];
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', $enableSlider ? 'path_to_deal_details' : 'path_to_deal_edit'),
						array('deal_id' => $ID)
					);
			}
			return $result;
		}
		case self::Invoice:
		{
			$result = array(
				'TITLE' => isset($arRes['ORDER_TOPIC']) ? $arRes['ORDER_TOPIC'] : '',
				'LEGEND' => '',
				'RESPONSIBLE_ID' => isset($arRes['RESPONSIBLE_ID']) ? intval($arRes['RESPONSIBLE_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' =>
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', 'path_to_invoice_show'),
						array('invoice_id' => $ID)
					),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Invoice),
			);
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', 'path_to_invoice_edit'),
						array('invoice_id' => $ID)
					);
			}
			return $result;
		}
		case self::Quote:
		{
			$title = $arRes['TITLE'] ?? '';
			if (empty($title))
			{
				$title = Bitrix\Crm\Item\Quote::getTitlePlaceholderFromData($arRes);
			}
			$result = array(
				'TITLE' => $title,
				'LEGEND' => '',
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' => Container::getInstance()->getRouter()->getItemDetailUrl(
					static::Quote,
					$arRes['ID']
				),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Quote),
			);
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', 'path_to_quote_edit'),
						array('quote_id' => $ID)
					);
			}
			return $result;
		}
		case self::Order:
		{
			$title = $arRes['ORDER_TOPIC'];
			if ($title == '')
			{
				$number = $arRes['ACCOUNT_NUMBER'] ? $arRes['ACCOUNT_NUMBER'] : $arRes['ID'];
				$title = GetMessage('CRM_OWNER_TYPE_ORDER_TITLE', [
					"#ACCOUNT_NUMBER#" => $number
				]);
			}

			$culture = Bitrix\Main\Context::getCurrent()->getCulture();
			$dateInsert = '';
			if ($arRes['DATE_INSERT'] instanceof \Bitrix\Main\Type\Date && $culture)
			{
				$dateInsert = FormatDate($culture->getLongDateFormat(), $arRes['DATE_INSERT']->getTimestamp());
			}
			$result = array(
				'ID' => $arRes['ID'],
				'TITLE' => $title,
				'ACCOUNT_NUMBER' => $arRes['ACCOUNT_NUMBER'],
				'ORDER_TOPIC' => $arRes['ORDER_TOPIC'],
				'LEGEND' => GetMessage('CRM_OWNER_TYPE_ORDER_LEGEND', [
					"#SUM_WITH_CURRENCY#" => \CCrmCurrency::MoneyToString($arRes['PRICE'], $arRes['CURRENCY']),
					"#DATE_INSERT#" => $dateInsert,
				]),
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' =>
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', 'path_to_order_details'),
						array('order_id' => $ID)
					),
				'DATE' => $dateInsert,
				'SUM_WITH_CURRENCY' => \CCrmCurrency::MoneyToString($arRes['PRICE'], $arRes['CURRENCY']),
				'PRICE' => $arRes['PRICE'],
				'CURRENCY' => $arRes['CURRENCY'],
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Order),
			);
			if($enableEditUrl)
			{
				$result['EDIT_URL'] =
					CComponentEngine::MakePathFromTemplate(
						COption::GetOptionString('crm', 'path_to_order_edit'),
						array('order_id' => $ID)
					);
			}
			return $result;
		}
		case self::OrderPayment:
		{
			$handler = Bitrix\Sale\PaySystem\Manager::getById($arRes['PAY_SYSTEM_ID']);
			$logotip = null;
			if ($handler['LOGOTIP']
				&& $arFile = \CFile::GetFileArray($handler['LOGOTIP'])
			)
			{
				$logotip = $arFile['SRC'];
			}

			$dateInsert = '';
			$culture = Bitrix\Main\Context::getCurrent()->getCulture();
			if ($arRes['DATE_BILL'] instanceof \Bitrix\Main\Type\Date && $culture)
			{
				$dateInsert = FormatDate($culture->getLongDateFormat(), $arRes['DATE_BILL']->getTimestamp());
			}
			$result = array(
				'ID' => $arRes['ID'],
				'ORDER_ID' => $arRes['ORDER_ID'],
				'TITLE' => isset($arRes['ACCOUNT_NUMBER']) ?  $arRes['ACCOUNT_NUMBER'] : '',
				'ACCOUNT_NUMBER' => isset($arRes['ACCOUNT_NUMBER']) ?  $arRes['ACCOUNT_NUMBER'] : '',
				'LEGEND' => GetMessage('CRM_OWNER_TYPE_ORDER_PAYMENT_LEGEND', [
					"#SUM_WITH_CURRENCY#" => \CCrmCurrency::MoneyToString($arRes['SUM'], $arRes['CURRENCY']),
					"#DATE_BILL#" => $dateInsert
				]),
				'SUBLEGEND' => GetMessage('CRM_OWNER_TYPE_ORDER_PAYMENT_SUBLEGEND', [
					"#PAY_SYSTEM_NAME#" => $arRes['PAY_SYSTEM_NAME']
				]),
				'RESPONSIBLE_ID' => isset($arRes['RESPONSIBLE_ID']) ? intval($arRes['RESPONSIBLE_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' => Service\Sale\EntityLinkBuilder\EntityLinkBuilder::getInstance()
					->getPaymentDetailsLink($ID),
				'LOGOTIP' => $logotip,
				'DATE' => $dateInsert,
				'PAY_SYSTEM_NAME' => $arRes['PAY_SYSTEM_NAME'],
				'SUM' => \CCrmCurrency::MoneyToString($arRes['SUM'], $arRes['CURRENCY'], '#'),
				'CURRENCY' => \CCrmCurrency::GetCurrencyText($arRes['CURRENCY']),
				'RAW_SUM' => $arRes['SUM'],
				'RAW_CURRENCY' => $arRes['CURRENCY'],
				'SUM_WITH_CURRENCY' => \CCrmCurrency::MoneyToString($arRes['SUM'], $arRes['CURRENCY']),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::OrderPayment),
			);
			if ($enableEditUrl)
			{
				$result['EDIT_URL'] = Service\Sale\EntityLinkBuilder\EntityLinkBuilder::getInstance()
					->getPaymentDetailsLink($ID);
			}
			return $result;
		}
		case self::OrderShipment:
		{
			$dateInsert = '';
			$culture = Bitrix\Main\Context::getCurrent()->getCulture();
			if ($arRes['DATE_INSERT'] instanceof \Bitrix\Main\Type\Date && $culture)
			{
				$dateInsert = FormatDate($culture->getLongDateFormat(), $arRes['DATE_INSERT']->getTimestamp());
			}

			$result = [
				'ID' => $arRes['ID'],
				'DATE_INSERT' => $arRes['DATE_INSERT'],
				'DATE_INSERT_FORMATTED' => $dateInsert,
				'TITLE' => isset($arRes['ACCOUNT_NUMBER']) ? $arRes['ACCOUNT_NUMBER'] : '',
				'ACCOUNT_NUMBER' => isset($arRes['ACCOUNT_NUMBER']) ?  $arRes['ACCOUNT_NUMBER'] : '',
				'LEGEND' => GetMessage('CRM_OWNER_TYPE_ORDER_SHIPMENT_LEGEND_2', [
					"#DATE_INSERT#" => $dateInsert,
					"#PRICE_DELIVERY_WITH_CURRENCY#" => \CCrmCurrency::MoneyToString($arRes['PRICE_DELIVERY'], $arRes['CURRENCY']),
				]),
				'SUBLEGEND' => GetMessage('CRM_OWNER_TYPE_ORDER_SHIPMENT_SUBLEGEND', [
					"#DELIVERY_NAME#" => $arRes['DELIVERY_NAME']
				]),
				'PRICE_DELIVERY' => $arRes['PRICE_DELIVERY'],
				'CURRENCY' => $arRes['CURRENCY'],
				'DELIVERY_NAME' => $arRes['DELIVERY_NAME'],
				'RESPONSIBLE_ID' => isset($arRes['RESPONSIBLE_ID']) ? intval($arRes['RESPONSIBLE_ID']) : 0,
				'IMAGE_FILE_ID' => 0,
				'SHOW_URL' => Service\Sale\EntityLinkBuilder\EntityLinkBuilder::getInstance()
					->getShipmentDetailsLink($ID),
				'ENTITY_TYPE_CAPTION' => static::GetDescription(static::OrderShipment),
			];
			if ($enableEditUrl)
			{
				$result['EDIT_URL'] = Service\Sale\EntityLinkBuilder\EntityLinkBuilder::getInstance()
					->getShipmentDetailsLink($ID);
			}
			return $result;
		}
		case self::StoreDocument:
			$culture = Bitrix\Main\Context::getCurrent()->getCulture();
			$dateCreate = '';
			if ($arRes['DATE_CREATE'] instanceof \Bitrix\Main\Type\Date && $culture)
			{
				$dateCreate = FormatDate($culture->getShortDateFormat(), $arRes['DATE_CREATE']->getTimestamp());
			}
			return [
				'ID' => $arRes['ID'] ?? 0,
				'TITLE' => $arRes['TITLE'] ?? '',
				'DOC_TYPE' => $arRes['DOC_TYPE'] ?? '',
				'DATE_CREATE' => $dateCreate,
				'TOTAL' => $arRes['TOTAL'] ?? 0,
				'CURRENCY' => $arRes['CURRENCY'] ?? CCrmCurrency::GetDefaultCurrencyID(),
			];
		case self::SuspendedLead:
		case self::SuspendedContact:
		case self::SuspendedCompany:
		case self::SuspendedDeal:
		{
			return array(
				'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '',
				'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0,
				'ENTITY_TYPE_CAPTION' => static::GetDescription($typeID),
			);
		}
	}

	if (static::isUseDynamicTypeBasedApproach($typeID))
	{
		$factory = Container::getInstance()->getFactory((int)$typeID);

		return [
			'TITLE' => $arRes[\Bitrix\Crm\Item::FIELD_NAME_TITLE] ?? '',
			'RESPONSIBLE_ID' => $arRes[\Bitrix\Crm\Item::FIELD_NAME_ASSIGNED] ?? 0,
			'SHOW_URL' => Container::getInstance()->getRouter()->getItemDetailUrl(
				$typeID,
				$arRes['ID'] ?? 0
			)->getUri(),
			'ENTITY_TYPE_CAPTION' => $factory ? $factory->getEntityDescription() : '',
		];
	}

	return null;
}

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