- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/volatile/fieldinfo.php
- Класс: Bitrix\Crm\Integrity\Volatile\FieldInfo
- Вызов: FieldInfo::getFieldMap
protected function getFieldMap(array $entityTypeIds = [], array $countryIds = []): array
{
static $map = null;
static $usedCountries = [];
$result = [];
if ($map === null)
{
// Statndard fields
$map = [
CCrmOwnerType::Lead => [
'TITLE',
'ADDRESS',
'SOURCE_DESCRIPTION',
'STATUS_DESCRIPTION',
'COMMENTS',
],
CCrmOwnerType::Company => [
'TITLE',
'ADDRESS',
'COMMENTS',
],
CCrmOwnerType::Contact => [
'FULL_NAME',
'ADDRESS',
'SOURCE_DESCRIPTION',
'COMMENTS',
],
];
// User fields
foreach (array_keys($map) as $entityTypeId)
{
/** @noinspection PhpUndefinedMethodInspection */
$userFieldsInfo = $this->getClassByEntityType($entityTypeId)::GetUserFields();
foreach ($userFieldsInfo as $fieldName => $fieldInfo)
{
if (
isset($fieldInfo['USER_TYPE_ID'])
&& (
$fieldInfo['USER_TYPE_ID'] === 'string'
|| $fieldInfo['USER_TYPE_ID'] === 'integer'
|| $fieldInfo['USER_TYPE_ID'] === 'double'
|| $fieldInfo['USER_TYPE_ID'] === 'address'
)
)
{
$map[$entityTypeId][] = $fieldName;
}
}
}
// Multifields
$fm = array_fill_keys(array_keys(CCrmFieldMulti::GetEntityTypes()), true);
unset($fm['PHONE'], $fm['EMAIL'], $fm['LINK']);
$fm = array_keys($fm);
foreach (array_keys($map) as $entityTypeId)
{
foreach($fm as $fmType)
{
$map[$entityTypeId][] = "FM.$fmType";
}
}
// Requisites and bank details
$requisite = EntityRequisite::getSingleInstance();
$usedCountries = $this->prepareCountries($this->sortCountries($requisite->getUsedCountries()));
if (!empty($usedCountries))
{
$rqFieldCountryMap = [];
foreach ($requisite->getRqFieldsCountryMap() as $fieldName => $countries)
{
$rqFieldCountryMap[$fieldName] = array_fill_keys($countries, true);
}
$userFieldsMap = array_fill_keys($requisite->getUserFields(), true);
$preset = EntityPreset::getSingleInstance();
$fieldsInPresetsByCountry = $preset->getSettingsFieldsOfPresets(
CCrmOwnerType::Requisite,
'active',
['ARRANGE_BY_COUNTRY' => true]
);
$bankDetail = EntityBankDetail::getSingleInstance();
$bdFieldsByCountry = $bankDetail->getRqFieldByCountry();
foreach (array_keys($map) as $entityTypeId)
{
if ($entityTypeId !== CCrmOwnerType::Lead)
{
foreach ($usedCountries as $countryId)
{
$rqFieldsInfo = $requisite->getFormFieldsInfo($countryId);
$countryCode = EntityPreset::getCountryCodeById($countryId);
$map[$entityTypeId][] = "RQ.$countryCode.NAME";
foreach ($fieldsInPresetsByCountry[$countryId] as $fieldName)
{
if (
isset($rqFieldsInfo[$fieldName])
&& isset($rqFieldsInfo[$fieldName]['type'])
&& (
$rqFieldsInfo[$fieldName]['type'] === 'string'
|| $rqFieldsInfo[$fieldName]['type'] === 'integer'
)
&& (
isset($rqFieldCountryMap[$fieldName][$countryId])
|| isset($userFieldsMap[$fieldName])
)
)
{
$map[$entityTypeId][] = "RQ.$countryCode.$fieldName";
}
}
$map[$entityTypeId][] = "RQ.$countryCode.BD.NAME";
if (isset($bdFieldsByCountry[$countryId]))
{
$bdFieldsInfo = $bankDetail->getFormFieldsInfo($countryId);
foreach ($bdFieldsByCountry[$countryId] as $fieldName)
{
if (
isset($bdFieldsInfo[$fieldName])
&& isset($bdFieldsInfo[$fieldName]['type'])
&& (
$bdFieldsInfo[$fieldName]['type'] === 'string'
|| $bdFieldsInfo[$fieldName]['type'] === 'integer'
)
)
{
$map[$entityTypeId][] = "RQ.$countryCode.BD.$fieldName";
}
}
}
$map[$entityTypeId][] = "RQ.$countryCode.BD.COMMENTS";
}
}
}
}
}
if (empty($entityTypeIds))
{
$entityTypeIds = array_keys($map);
}
if (empty($countryIds))
{
$countryIds = $usedCountries;
}
$countryCodeMap = [];
foreach (array_intersect($countryIds, $usedCountries) as $countryId)
{
$countryCodeMap[EntityPreset::getCountryCodeById($countryId)] = true;
}
$prefixLength =
mb_strlen(static::RQ_FIELD_PREFIX)
+ mb_strlen(EntityPreset::getCountryCodeById(1))
+ mb_strlen(static::PATH_SEPARATOR) * 2
;
foreach ($entityTypeIds as $entityTypeId)
{
if (isset($map[$entityTypeId]))
{
foreach ($map[$entityTypeId] as $fieldPathName)
{
if (
mb_strlen($fieldPathName) > $prefixLength
&& mb_substr($fieldPathName, 0, 3) === (static::RQ_FIELD_PREFIX . static::PATH_SEPARATOR)
&& mb_substr($fieldPathName, 5, 1) === static::PATH_SEPARATOR
)
{
if (isset($countryCodeMap[mb_substr($fieldPathName, 3, 2)]))
{
$result[$entityTypeId][] = $fieldPathName;
}
}
else
{
$result[$entityTypeId][] = $fieldPathName;
}
}
}
}
return $result;
}