Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
property.php
1<?php
9namespace Bitrix\Iblock;
10
21
26class Property extends EO_Property
27{
29 protected $valueEntity;
30
41 public function getValueEntity($elementEntity = null)
42 {
43 if ($this->valueEntity === null)
44 {
45 if ($elementEntity === null)
46 {
47 $elementEntity = IblockTable::compileEntity(
48 IblockTable::getByPrimary($this->getIblockId(), [
49 'select' => ['ID', 'API_CODE']
50 ])->fetchObject()
51 );
52 }
53
55 $entityClassName = 'IblockProperty'.$this->getId().'Table';
56 $entityClass = '\\'.IblockTable::DATA_CLASS_NAMESPACE.'\\'.$entityClassName;
57
58 if (class_exists($entityClass, false))
59 {
60 // already compiled
61 return $this->valueEntity = $entityClass::getEntity();
62 }
63
64 $valueTableName = $this->getMultiple()
65 ? $elementEntity->getMultiValueTableName()
66 : $elementEntity->getSingleValueTableName();
67
68 if ($this->getVersion() == 1 || ($this->getVersion() == 2 && $this->getMultiple()))
69 {
70 switch ($this->getPropertyType())
71 {
76 $realValueColumnName = 'VALUE_NUM';
77 break;
78
80 $realValueColumnName = 'VALUE_ENUM';
81 break;
82
84 default:
85 $realValueColumnName = 'VALUE';
86 }
87
88 $realDescriptionColumnName = 'DESCRIPTION';
89
90 // fields for PropertyValue entity
91 $fields = [
92 (new IntegerField('ID'))
93 ->configurePrimary()
94 ->configureAutocomplete(),
95
96 (new IntegerField('IBLOCK_ELEMENT_ID')),
97 (new IntegerField('IBLOCK_PROPERTY_ID')),
98 ];
99 }
100 elseif ($this->getVersion() == 2 && !$this->getMultiple())
101 {
102 // single value
103 $realValueColumnName = 'PROPERTY_'.$this->getId();
104 $realDescriptionColumnName = 'DESCRIPTION_'.$this->getId();
105
106 // fields for PropertyValue entity
107 $fields = [
108 (new IntegerField('IBLOCK_ELEMENT_ID'))
109 ->configurePrimary()
110 ];
111 }
112 else
113 {
114 throw new SystemException('Unknown property type');
115 }
116
117 // construct PropertyValue entity
118 $this->valueEntity = Entity::compileEntity(
119 $entityClassName,
120 $fields,
121 [
123 'table_name' => $valueTableName,
124 'parent' => ValueStorageTable::class,
125 ]
126 );
127
128 // add value field
129 PropertyToField::attachField($this, $this->valueEntity);
130
131 // set real column name
132 $this->valueEntity->getField('VALUE')->configureColumnName($realValueColumnName);
133
134 // add generic value field
135 if ($realValueColumnName !== 'VALUE'
136 && (
137 $elementEntity instanceof ElementV1Entity // all v1 props
138 || $this->getMultiple() // multiple v2 props
139 )
140 )
141 {
142 $this->valueEntity->addField(
143 (new StringField(ValueStorageTable::GENERIC_VALUE_FIELD_NAME))->configureColumnName('VALUE')
144 );
145 }
146
147 // add description
148 if ($this->getWithDescription())
149 {
150 $this->valueEntity->addField(
151 (new StringField('DESCRIPTION'))
152 ->configureColumnName($realDescriptionColumnName)
153 );
154 }
155 }
156
157 return $this->valueEntity;
158 }
159}
static attachField($property, $propertyValueEntity)
static getByPrimary($primary, array $parameters=array())