• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/rest/configuration/entity/field.php
  • Класс: Bitrix\Crm\Integration\Rest\Configuration\Entity\Field
  • Вызов: Field::export
static function export($option)
{
	if(!Helper::checkAccessManifest($option, static::$accessManifest))
	{
		return null;
	}

	$step = false;
	if(array_key_exists('STEP', $option))
	{
		$step = $option['STEP'];
	}

	$return = [
		'FILE_NAME' => '',
		'CONTENT' => [],
		'NEXT' => $step
	];
	global $USER_FIELD_MANAGER;
	$entityList = array_column(CCrmFields::GetEntityTypes(), 'ID');
	if($entityList[$step])
	{
		$return['FILE_NAME'] = $entityList[$step];
		$return['CONTENT'] = [
			'TYPE' => $entityList[$step],
			'ITEMS' => (new CCrmFields($USER_FIELD_MANAGER, $entityList[$step]))->GetFields(),
			'ATTRIBUTE' => []
		];

		if(mb_strpos($entityList[$step], '_') !== false)
		{
			list($tmp, $entity) = explode('_', $entityList[$step]);
		}
		else
		{
			$entity = $entityList[$step];
		}
		if($entity !== '')
		{
			$entityTypeId = CCrmOwnerType::ResolveID($entity);
			if($entityTypeId > 0)
			{
				$attributeData = [];
				$attributeData[] = [
					'CONFIG' => FieldAttributeManager::getEntityConfigurations(
						$entityTypeId,
						FieldAttributeManager::resolveEntityScope(
							$entityTypeId,
							0
						)
					),
					'ENTITY_TYPE_NAME' => $entity,
					'OPTION' => []
				];
				if($entityTypeId === CCrmOwnerType::Deal)
				{
					$dealCategory = DealCategory::getAll(false);
					foreach ($dealCategory as $category)
					{
						$option = [
							'CATEGORY_ID' => $category['ID']
						];
						$attributeData[] = [
							'CONFIG' => FieldAttributeManager::getEntityConfigurations(
								$entityTypeId,
								FieldAttributeManager::resolveEntityScope(
									$entityTypeId,
									0,
									$option
								)
							),
							'ENTITY_TYPE_NAME' => $entity,
							'OPTION' => $option
						];
					}
				}
				$return['CONTENT']['ATTRIBUTE'] = $attributeData;
			}
		}

		foreach ($return['CONTENT']['ITEMS'] as $key => $field)
		{
			if($field['USER_TYPE_ID'] == 'enumeration')
			{
				$return['CONTENT']['ITEMS'][$key]['LIST'] = [];
				$res = CUserFieldEnum::GetList([], ['USER_FIELD_ID' =>$field['ID']]);
				$i = 0;
				while($value = $res->fetch())
				{
					$i++;
					$return['CONTENT']['ITEMS'][$key]['LIST']['n'.$i] = $value;
				}
			}
		}
	}
	else
	{
		$return['NEXT'] = false;
	}

	return $return;
}