CCrmUserType::PrepareFieldsInfo

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmUserType
  4. PrepareFieldsInfo
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_usertype.php
  • Класс: \CCrmUserType
  • Вызов: CCrmUserType::PrepareFieldsInfo
public function PrepareFieldsInfo(&$fieldsInfo, array $params = [])
{
	$arUserFields = $this->GetAbstractFields($params);

	$enumFields = [];
	foreach($arUserFields as $FIELD_NAME => $arUserField)
	{
		$userTypeID = $arUserField['USER_TYPE_ID'];
		$settings = isset($arUserField['SETTINGS']) ? $arUserField['SETTINGS'] : [];
		$userType = ($arUserField['USER_TYPE'] ?? []);

		$title = $arUserField['EDIT_FORM_LABEL']
			?? $arUserField['LIST_COLUMN_LABEL']
			?? $arUserField['LIST_FILTER_LABEL']
			?? $FIELD_NAME;

		$info = [
			'TITLE' => $title,
			'TYPE' => $userTypeID,
			'ATTRIBUTES' => [CCrmFieldInfoAttr::Dynamic],
			'SETTINGS' => $settings,
			'USER_TYPE' => $userType,
			'LABELS' => [
				'LIST' => isset($arUserField['LIST_COLUMN_LABEL']) ? $arUserField['LIST_COLUMN_LABEL'] : '',
				'FORM' => isset($arUserField['EDIT_FORM_LABEL']) ? $arUserField['EDIT_FORM_LABEL'] : '',
				'FILTER' => isset($arUserField['LIST_FILTER_LABEL']) ? $arUserField['LIST_FILTER_LABEL'] : ''
			],
		];

		$isMultiple = isset($arUserField['MULTIPLE']) && $arUserField['MULTIPLE'] === 'Y';
		$isRequired = isset($arUserField['MANDATORY']) && $arUserField['MANDATORY'] === 'Y';
		if($isMultiple || $isRequired)
		{
			if($isMultiple)
			{
				$info['ATTRIBUTES'][] = CCrmFieldInfoAttr::Multiple;
			}

			if($isRequired)
			{
				$info['ATTRIBUTES'][] = CCrmFieldInfoAttr::Required;
			}
		}

		if($userTypeID === 'string')
		{
			$info['SETTINGS'] = $arUserField['SETTINGS'];
		}
		if($userTypeID === 'enumeration')
		{
			$info['SETTINGS'] = $arUserField['SETTINGS'];

			if(isset(self::$enumerationItems[$this->sEntityID][$FIELD_NAME]))
			{
				$info['ITEMS'] = self::$enumerationItems[$this->sEntityID][$FIELD_NAME];
			}
			else
			{
				$fieldID = $arUserField['ID'];
				if(isset($arUserField['USER_TYPE']) && isset($arUserField['USER_TYPE']['CLASS_NAME']))
				{
					$enumFields[$arUserField['USER_TYPE']['CLASS_NAME']][$fieldID] =
						['ID' => $fieldID, 'NAME' => $FIELD_NAME];
				}
			}
		}
		elseif($userTypeID === 'crm_status')
		{
			$info['CRM_STATUS_TYPE'] = isset($settings['ENTITY_TYPE']) ? $settings['ENTITY_TYPE'] : '';
		}

		$fieldsInfo[$FIELD_NAME] = &$info;
		unset($info);
	}

	foreach($enumFields as $fieldClassName => $fields)
	{
		$enumResult = call_user_func_array(
			[$fieldClassName, 'GetListMultiple'],
			[array_values($fields)]
		);

		$items = [];
		while($enum = $enumResult->GetNext())
		{
			$fieldID = $enum['~USER_FIELD_ID'];
			if(!isset($fields[$fieldID]))
			{
				continue;
			}

			$fieldName = $fields[$fieldID]['NAME'];

			if(!isset($fieldsInfo[$fieldName]['ITEMS']))
			{
				$fieldsInfo[$fieldName]['ITEMS'] = [];
			}

			if(!isset($items[$fieldName]))
			{
				$items[$fieldName] = [];
			}

			$fieldsInfo[$fieldName]['ITEMS'][] =
			$items[$fieldName][] =
				['ID' => $enum['~ID'], 'VALUE' => $enum['~VALUE']];
		}

		if (!isset(self::$enumerationItems[$this->sEntityID]))
		{
			self::$enumerationItems[$this->sEntityID] = [];
		}
		self::$enumerationItems[$this->sEntityID] = array_merge(self::$enumerationItems[$this->sEntityID], $items);
	}
}

Добавить комментарий