• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_entity_selector_helper.php
  • Класс: \CCrmEntitySelectorHelper
  • Вызов: CCrmEntitySelectorHelper::PrepareBankDetailsData
static function PrepareBankDetailsData($entityTypeId, $entityId, $options = array())
{
	$entityTypeId = (int)$entityTypeId;
	$entityId = (int)$entityId;
	$copyMode = (isset($options['COPY_MODE'])
		&& ($options['COPY_MODE'] === true || $options['COPY_MODE'] === 'Y'));
	$viewDataOnly = (isset($options['VIEW_DATA_ONLY'])
		&& ($options['VIEW_DATA_ONLY'] === true || $options['VIEW_DATA_ONLY'] === 'Y'));
	$skipCheckPermission = (isset($options['SKIP_CHECK_PERMISSION'])
		&& ($options['SKIP_CHECK_PERMISSION'] === true || $options['SKIP_CHECK_PERMISSION'] === 'Y'));

	$countryId = isset($options['COUNTRY_ID']) ? (int)$options['COUNTRY_ID'] : 0;
	$currentCountryId = \Bitrix\Crm\EntityPreset::getCurrentCountryId();

	$bankDetailIdSelected = 0;
	if (isset($options['BANK_DETAIL_ID_SELECTED']))
	{
		$bankDetailIdSelected = (int)$options['BANK_DETAIL_ID_SELECTED'];
		if ($bankDetailIdSelected < 0)
			$bankDetailIdSelected = 0;
	}

	$result = array();
	if (!$viewDataOnly)
		$result['bankDetailFieldsList'] = array();
	$result['bankDetailViewDataList'] = array();
	$result['bankDetailIdSelected'] = $bankDetailIdSelected;

	$bankDetail = new \Bitrix\Crm\EntityBankDetail();
	if ($skipCheckPermission || $bankDetail->validateEntityReadPermission($entityTypeId, $entityId))
	{
		$select = array_merge(
			array('ID', 'ENTITY_TYPE_ID', 'ENTITY_ID', 'COUNTRY_ID', 'NAME'),
			$bankDetail->getRqFields(),
			array('COMMENTS')
		);
		$res = $bankDetail->getList(
			array(
				'order' => array('SORT', 'ID'),
				'filter' => array('=ENTITY_TYPE_ID' => \CCrmOwnerType::Requisite, '=ENTITY_ID' => $entityId),
				'select' => $select
			)
		);
		$curDateTime = new \Bitrix\Main\Type\DateTime();
		$curUserId = CCrmSecurityHelper::GetCurrentUserID();
		$n = 0;
		$index = 0;
		$selectedIndex = -1;
		while ($row = $res->fetch())
		{
			if ($copyMode)
			{
				$row['ID'] = 0;
				$row['DATE_CREATE'] = $curDateTime;
				$row['DATE_MODIFY'] = $curDateTime;
				$row['CREATED_BY_ID'] = $curUserId;
				$row['MODIFY_BY_ID'] = $curUserId;
			}

			foreach ($row as $fName => $fValue)
			{
				if ($fValue instanceof \Bitrix\Main\Type\DateTime)
					$row[$fName] = $fValue->toString();
			}

			$pseudoId = ($row['ID'] > 0) ? $row['ID'] : 'n'.$n++;
			if (!$viewDataOnly)
				$result['bankDetailFieldsList'][$pseudoId] = $row;
			if ($countryId <= 0)
				$countryId = isset($row['COUNTRY_ID']) ? (int)$row['COUNTRY_ID'] : $currentCountryId;
			if ($selectedIndex < 0 && $bankDetailIdSelected === intval($row['ID']))
				$selectedIndex = $index;
			$result['bankDetailViewDataList'][] = array(
				'pseudoId' => $pseudoId,
				'viewData' => $bankDetail->prepareViewData(
					$row, array_keys($bankDetail->getFormFieldsInfoByCountry($countryId))
				),
				'selected' => false
			);

			$index++;
		}
		unset($select, $res, $row);

		if (!empty($result['bankDetailViewDataList']))
		{
			if ($selectedIndex < 0)
			{
				$selectedIndex = 0;
				$result['bankDetailIdSelected'] = 0;
			}
			$result['bankDetailViewDataList'][$selectedIndex]['selected'] = true;
		}
	}

	return $result;
}