• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/requisite/importhelper.php
  • Класс: Bitrix\Crm\Requisite\ImportHelper
  • Вызов: ImportHelper::parseRequisiteFields
protected function parseRequisiteFields($row, $presetInfo)
{
	$result = new Main\Result();

	$requisiteFields = array();
	$requisite = EntityRequisite::getSingleInstance();

	$countryId = $presetInfo['COUNTRY_ID'];
	$skipFieldsMap = array(
		$this->rqFieldPrefix.'ID' => true,
		$this->rqFieldPrefix.'PRESET_NAME' => true,
		$this->rqFieldPrefix.'PRESET_COUNTRY_ID' => true,
		$this->rqFieldPrefix.'PRESET_COUNTRY_NAME' => true
	);

	$headerIds = array();
	if (is_array($this->headerGroupCountryIdMap['requisite'][0]))
		$headerIds = array_keys($this->headerGroupCountryIdMap['requisite'][0]);
	if (is_array($this->headerGroupCountryIdMap['requisite'][$countryId]))
		$headerIds = array_merge($headerIds, array_keys($this->headerGroupCountryIdMap['requisite'][$countryId]));
	foreach ($headerIds as $headerId)
	{
		if (isset($skipFieldsMap[$headerId]))
			continue;

		$fieldName = '';
		$fieldCountryId = 0;
		$fieldType = 'string';
		$isUF = false;
		if (is_array($this->headerById[$headerId])
			&& isset($this->headerById[$headerId]['field'])
			&& isset($this->headerById[$headerId]['countryId'])
			&& $this->headerById[$headerId]['fieldType'])
		{
			$fieldName = $this->headerById[$headerId]['field'];
			$fieldCountryId = (int)$this->headerById[$headerId]['countryId'];
			$fieldType = $this->headerById[$headerId]['fieldType'];
			$isUF = $this->headerById[$headerId]['isUF'];
		}
		if (!is_string($fieldName) || $fieldName == ''
			|| ($fieldCountryId > 0 && !isset($presetInfo['FIELD_MAP'][$fieldName])))
		{
			continue;
		}

		if (isset($row[$this->headerIndex[$headerId]]))
		{
			if ($fieldName === 'PRESET_ID')
			{
				$value = $presetInfo['ID'];
			}
			else
			{
				$value = $row[$this->headerIndex[$headerId]];
			}

			if ($fieldType === 'integer')
			{
				$value = (int)$value;
			}
			else if ($fieldType === 'boolean')
			{
				$value = ToUpper($value);
				$yesStr = ToUpper(Loc::getMessage('MAIN_YES'));
				$value = ($value === 'Y' || $value === $yesStr || $value == 1) ? 'Y' : 'N';
				if ($isUF)
					$value = $value === 'Y' ? 1 : 0;
			}
			else if ($fieldType === 'Address')
			{
				$value = array();
			}
			else if ($fieldCountryId > 0 && $requisite->isRqListField($fieldName))
			{
				if (!is_array($this->rqListFieldMap[$fieldName][$fieldCountryId]))
				{
					$this->rqListFieldMap[$fieldName][$fieldCountryId] = [];
					foreach ($requisite->getRqListFieldItems($fieldName, $fieldCountryId) as $item)
					{
						if (!isset($this->rqListFieldMap[$fieldName][$fieldCountryId][$item['VALUE']]))
						{
							$this->rqListFieldMap[$fieldName][$fieldCountryId][$item['VALUE']] = $item['NAME'];
						}
					}
					unset($item);
				}

				if(isset($this->rqListFieldMap[$fieldName][$fieldCountryId][$value]))
				{
					// 1. Try to interpret value as STATUS_ID
					$value = $this->rqListFieldMap[$fieldName][$fieldCountryId][$value];
				}
				else
				{
					// 2. Try to interpret value as TITLE. If not found leave value as is
					$statusId = array_search($value, $this->rqListFieldMap[$fieldName][$fieldCountryId]);
					if ($statusId !== false)
					{
						$value = $statusId;
					}
				}
			}

			$requisiteFields[$fieldName] = $value;
		}
	}

	$result->setData($requisiteFields);

	return $result;
}