• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/filter/requisitedataprovider.php
  • Класс: Bitrix\Crm\Filter\RequisiteDataProvider
  • Вызов: RequisiteDataProvider::prepareFields
public function prepareFields()
{
	$requisite = $this->getEntityRequisite();

	$fieldList = EntityPreset::getSingleInstance()->getSettingsFieldsOfPresets(
		EntityPreset::Requisite,
		'active',
		array('FILTER_BY_COUNTRY_IDS' => $requisite->getAllowedRqFieldCountries())
	);

	if(empty($fieldList))
	{
		return array();
	}

	$activeCountryMap = array();
	$activeFieldMap = array();

	foreach($fieldList as $countryId => $fields)
	{
		foreach($fields as $fieldName)
		{
			$activeFieldMap[$countryId][$fieldName] = true;
			$activeCountryMap[$countryId] = true;
		}
	}

	if(empty($activeCountryMap))
	{
		return array();
	}

	$result = array();

	$currentCountryId = EntityPreset::getCurrentCountryId();
	$hideCountry = count($activeCountryMap) === 1 && isset($activeCountryMap[$currentCountryId]);
	$countrySort = array();
	if(isset($activeCountryMap[$currentCountryId]))
	{
		$countrySort[] = $currentCountryId;
	}

	foreach(array_keys($activeCountryMap) as $countryId)
	{
		if($countryId !== $currentCountryId)
		{
			$countrySort[] = $countryId;
		}
	}

	$fieldTitles = $requisite->getRqFieldTitleMap();
	$fieldTypes = $requisite->getFormFieldsTypes();
	$effectiveFields = array();
	foreach($requisite->getRqFiltrableFields() as $fieldName)
	{
		$effectiveFields[$fieldName] = true;
	}

	$countries = EntityPreset::getCountryList();
	$fieldNamePrefix = Loc::getMessage('CRM_REQUISITE_FILTER_PREFIX');
	foreach($countrySort as $countryId)
	{
		if(!isset($countries[$countryId]))
		{
			continue;
		}

		foreach($requisite->getRqFields() as $fieldName)
		{
			if(isset($effectiveFields[$fieldName])
				&& isset($activeFieldMap[$countryId][$fieldName])
				&& isset($fieldTitles[$fieldName][$countryId])
				&& !empty($fieldTitles[$fieldName][$countryId])
			)
			{
				if($fieldName !== EntityRequisite::ADDRESS)
				{
					$isPartial = false;
					$fieldId = $fieldName.'|'.$countryId;
					if ($requisite->isRqListField($fieldName))
					{
						$fieldType = 'list';
						$isPartial = true;
					}
					else
					{
						$fieldType = $fieldTypes[$fieldName] ?? 'text';
					}
					$fieldParams = [
						'type' => $fieldType,
						'name' => $fieldNamePrefix.
							($hideCountry ? '' : ' ('.$countries[$countryId].')').': '.
							$fieldTitles[$fieldName][$countryId],
					];
					if ($isPartial)
					{
						$fieldParams['partial'] = true;
					}
					$result[$fieldId] = $this->createField($fieldId, $fieldParams);
				}
				else
				{
					$addressTypeId = RequisiteAddress::Undefined;
					$addressTypeName = $fieldTitles[$fieldName][$countryId];
					$addressLabels = RequisiteAddress::getShortLabels(RequisiteAddress::Primary);
					foreach(array_keys($requisite->getAddressFieldMap(RequisiteAddress::Primary)) as $fieldKey)
					{
						if($fieldKey === 'ADDRESS_2'
							|| $fieldKey === 'COUNTRY_CODE'
							|| $fieldKey === 'LOC_ADDR_ID')
						{
							continue;
						}

						$fieldId = $fieldName.'|'.$countryId.'|'.$addressTypeId.'|'.$fieldKey;
						$result[$fieldId] = $this->createField(
							$fieldId,
							[
								'type' => 'text',
								'name' => $fieldNamePrefix.
									($hideCountry ? '' : ' ('.$countries[$countryId].')').': '.
									$addressTypeName.' - '.ToLower($addressLabels[$fieldKey]),
							]
						);
					}
				}
			}
		}
	}
	return $result;
}