• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/property.php
  • Класс: BitrixIblockProperty
  • Вызов: Property::getValueEntity
public function getValueEntity($elementEntity = null)
{
	if ($this->valueEntity === null)
	{
		if ($elementEntity === null)
		{
			$elementEntity = IblockTable::compileEntity(
				IblockTable::getByPrimary($this->getIblockId(), [
					'select' => ['ID', 'API_CODE']
				])->fetchObject()
			);
		}

		/** @var DataManager $entityClassName */
		$entityClassName = 'IblockProperty'.$this->getId().'Table';
		$entityClass = '\'.IblockTable::DATA_CLASS_NAMESPACE.'\'.$entityClassName;

		if (class_exists($entityClass, false))
		{
			// already compiled
			return $this->valueEntity = $entityClass::getEntity();
		}

		$valueTableName = $this->getMultiple()
			? $elementEntity->getMultiValueTableName()
			: $elementEntity->getSingleValueTableName();

		if ($this->getVersion() == 1 || ($this->getVersion() == 2 && $this->getMultiple()))
		{
			switch ($this->getPropertyType())
			{
				case PropertyTable::TYPE_NUMBER:
				case PropertyTable::TYPE_SECTION:
				case PropertyTable::TYPE_ELEMENT:
				case PropertyTable::TYPE_FILE:
					$realValueColumnName = 'VALUE_NUM';
					break;

				case PropertyTable::TYPE_LIST:
					$realValueColumnName = 'VALUE_ENUM';
					break;

				case PropertyTable::TYPE_STRING:
				default:
					$realValueColumnName = 'VALUE';
			}

			$realDescriptionColumnName = 'DESCRIPTION';

			// fields for PropertyValue entity
			$fields = [
				(new IntegerField('ID'))
					->configurePrimary()
					->configureAutocomplete(),

				(new IntegerField('IBLOCK_ELEMENT_ID')),
				(new IntegerField('IBLOCK_PROPERTY_ID')),
			];
		}
		elseif ($this->getVersion() == 2 && !$this->getMultiple())
		{
			// single value
			$realValueColumnName = 'PROPERTY_'.$this->getId();
			$realDescriptionColumnName = 'DESCRIPTION_'.$this->getId();

			// fields for PropertyValue entity
			$fields = [
				(new IntegerField('IBLOCK_ELEMENT_ID'))
					->configurePrimary()
			];
		}
		else
		{
			throw new SystemException('Unknown property type');
		}

		// construct PropertyValue entity
		$this->valueEntity = Entity::compileEntity(
			$entityClassName,
			$fields,
			[
				'namespace' => IblockTable::DATA_CLASS_NAMESPACE,
				'table_name' => $valueTableName,
				'parent' => ValueStorageTable::class,
			]
		);

		// add value field
		PropertyToField::attachField($this, $this->valueEntity);

		// set real column name
		$this->valueEntity->getField('VALUE')->configureColumnName($realValueColumnName);

		// add generic value field
		if ($realValueColumnName !== 'VALUE'
			&& (
				$elementEntity instanceof ElementV1Entity // all v1 props
				|| $this->getMultiple() // multiple v2 props
			)
		)
		{
			$this->valueEntity->addField(
				(new StringField(ValueStorageTable::GENERIC_VALUE_FIELD_NAME))->configureColumnName('VALUE')
			);
		}

		// add description
		if ($this->getWithDescription())
		{
			$this->valueEntity->addField(
				(new StringField('DESCRIPTION'))
					->configureColumnName($realDescriptionColumnName)
			);
		}
	}

	return $this->valueEntity;
}