Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
propertytable.php
1<?php
2
3namespace Bitrix\Iblock;
4
7
60{
61 public const CHECKBOX = 'C';
62 public const LISTBOX = 'L';
63
64 public const TYPE_STRING = 'S';
65 public const TYPE_NUMBER = 'N';
66 public const TYPE_FILE = 'F';
67 public const TYPE_ELEMENT = 'E';
68 public const TYPE_SECTION = 'G';
69 public const TYPE_LIST = 'L';
70
71 public const DEFAULT_MULTIPLE_CNT = 5;
72
73 // iblock module
74 public const USER_TYPE_DATE = 'Date';
75 public const USER_TYPE_DATETIME = 'DateTime';
76 public const USER_TYPE_XML_ID = 'ElementXmlID';
77 public const USER_TYPE_FILE_MAN = 'FileMan';
78 public const USER_TYPE_HTML = 'HTML';
79 public const USER_TYPE_ELEMENT_LIST = 'EList';
80 public const USER_TYPE_SEQUENCE = 'Sequence';
81 public const USER_TYPE_ELEMENT_AUTOCOMPLETE = 'EAutocomplete';
82 public const USER_TYPE_SKU = 'SKU';
83 public const USER_TYPE_SECTION_AUTOCOMPLETE = 'SectionAuto';
84
85 // highload module
86
87 public const USER_TYPE_CRM = 'ECrm'; // \Bitrix\Crm\Integration\IBlockElementProperty::USER_TYPE
88 public const USER_TYPE_MONEY = 'Money'; // \Bitrix\Currency\Integration\IblockMoneyProperty::USER_TYPE
89
90 public const USER_TYPE_DISK = 'DiskFile'; // \Bitrix\Disk\Integration\FileDiskProperty
91 public const USER_TYPE_GOOGLE_MAP = 'map_google'; // \CIBlockPropertyMapGoogle
92 public const USER_TYPE_YANDEX_MAP = 'map_yandex'; // \CIBlockPropertyMapYandex
93 public const USER_TYPE_FORUM_TOPIC = 'TopicID'; // \CIBlockPropertyTopicID
94 public const USER_TYPE_DIRECTORY = 'directory'; // \CIBlockPropertyDirectory::USER_TYPE
95 public const USER_TYPE_EMPLOYEE = 'employee'; // \CIBlockPropertyEmployee
96 public const USER_TYPE_USER = 'UserID'; // \CIBlockPropertyUserID::USER_TYPE
97
103 public static function getTableName(): string
104 {
105 return 'b_iblock_property';
106 }
107
108 public static function getObjectClass(): string
109 {
110 return Property::class;
111 }
112
118 public static function getMap(): array
119 {
120 return [
121 'ID' => (new ORM\Fields\IntegerField('ID'))
122 ->configurePrimary(true)
123 ->configureAutocomplete(true)
124 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_ID_FIELD'))
125 ,
126 'TIMESTAMP_X' => (new ORM\Fields\DatetimeField('TIMESTAMP_X'))
127 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_TIMESTAMP_X_FIELD'))
128 ,
129 'IBLOCK_ID' => (new ORM\Fields\IntegerField('IBLOCK_ID'))
130 ->configureRequired(true)
131 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_IBLOCK_ID_FIELD'))
132 ,
133 'NAME' => (new ORM\Fields\StringField('NAME'))
134 ->configureRequired(true)
135 ->configureSize(255)
136 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 255))
137 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_NAME_FIELD'))
138 ,
139 'ACTIVE' => (new ORM\Fields\BooleanField('ACTIVE'))
140 ->configureValues('N', 'Y')
141 ->configureDefaultValue('Y')
142 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_ACTIVE_FIELD'))
143 ,
144 'SORT' => (new ORM\Fields\IntegerField('SORT'))
145 ->configureDefaultValue(100)
146 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_SORT_FIELD'))
147 ,
148 'CODE' => (new ORM\Fields\StringField('CODE'))
149 ->configureNullable(true)
150 ->configureSize(50)
151 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 50))
152 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_CODE_FIELD'))
153 ,
154 'DEFAULT_VALUE' => (new ORM\Fields\TextField('DEFAULT_VALUE'))
155 ->configureNullable(true)
156 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_DEFAULT_VALUE_FIELD'))
157 ,
158 'PROPERTY_TYPE' => (new ORM\Fields\EnumField('PROPERTY_TYPE'))
159 ->configureRequired(true)
160 ->configureValues([
161 self::TYPE_STRING,
162 self::TYPE_NUMBER,
163 self::TYPE_FILE,
164 self::TYPE_ELEMENT,
165 self::TYPE_SECTION,
166 self::TYPE_LIST,
167 ])
168 ->configureDefaultValue(self::TYPE_STRING)
169 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_PROPERTY_TYPE_FIELD'))
170 ,
171 'ROW_COUNT' => (new ORM\Fields\IntegerField('ROW_COUNT'))
172 ->configureDefaultValue(1)
173 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_ROW_COUNT_FIELD'))
174 ,
175 'COL_COUNT' => (new ORM\Fields\IntegerField('COL_COUNT'))
176 ->configureDefaultValue(30)
177 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_COL_COUNT_FIELD'))
178 ,
179 'LIST_TYPE' => (new ORM\Fields\EnumField('LIST_TYPE'))
180 ->configureValues([
181 self::LISTBOX,
182 self::CHECKBOX,
183 ])
184 ->configureDefaultValue(self::LISTBOX)
185 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_LIST_TYPE_FIELD'))
186 ,
187 'MULTIPLE' => (new ORM\Fields\BooleanField('MULTIPLE'))
188 ->configureValues('N', 'Y')
189 ->configureDefaultValue('N')
190 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_MULTIPLE_FIELD'))
191 ,
192 'XML_ID' => (new ORM\Fields\StringField('XML_ID'))
193 ->configureNullable(true)
194 ->configureSize(100)
195 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 100))
196 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_XML_ID_FIELD'))
197 ,
198 'FILE_TYPE' => (new ORM\Fields\StringField('FILE_TYPE'))
199 ->configureNullable(true)
200 ->configureSize(200)
201 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 200))
202 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_FILE_TYPE_FIELD'))
203 ,
204 'MULTIPLE_CNT' => (new ORM\Fields\IntegerField('MULTIPLE_CNT'))
205 ->configureNullable(true)
206 ->configureDefaultValue(self::DEFAULT_MULTIPLE_CNT)
207 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_MULTIPLE_CNT_FIELD'))
208 ,
209 'TMP_ID' => (new ORM\Fields\StringField('TMP_ID'))
210 ->configureNullable(true)
211 ->configureSize(40)
212 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 40))
213 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_TMP_ID_FIELD'))
214 ,
215 'LINK_IBLOCK_ID' => (new ORM\Fields\IntegerField('LINK_IBLOCK_ID'))
216 ->configureNullable(true)
217 ->configureDefaultValue(0)
218 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_LINK_IBLOCK_ID_FIELD'))
219 ,
220 'WITH_DESCRIPTION' => (new ORM\Fields\BooleanField('WITH_DESCRIPTION'))
221 ->configureValues('N', 'Y')
222 ->configureDefaultValue('N')
223 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_WITH_DESCRIPTION_FIELD'))
224 ,
225 'SEARCHABLE' => (new ORM\Fields\BooleanField('SEARCHABLE'))
226 ->configureValues('N', 'Y')
227 ->configureDefaultValue('N')
228 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_SEARCHABLE_FIELD'))
229 ,
230 'FILTRABLE' => (new ORM\Fields\BooleanField('FILTRABLE'))
231 ->configureValues('N', 'Y')
232 ->configureDefaultValue('N')
233 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_FILTRABLE_FIELD'))
234 ,
235 'IS_REQUIRED' => (new ORM\Fields\BooleanField('IS_REQUIRED'))
236 ->configureValues('N', 'Y')
237 ->configureDefaultValue('N')
238 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_IS_REQUIRED_FIELD'))
239 ,
240 'VERSION' => (new ORM\Fields\EnumField('VERSION'))
241 ->configureValues([1, 2])
242 ->configureDefaultValue(1)
243 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_VERSION_FIELD'))
244 ,
245 'USER_TYPE' => (new ORM\Fields\StringField('USER_TYPE'))
246 ->configureNullable(true)
247 ->configureSize(255)
248 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 255))
249 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_USER_TYPE_FIELD'))
250 ,
251 'USER_TYPE_SETTINGS_LIST' => (new ORM\Fields\ArrayField('USER_TYPE_SETTINGS_LIST'))
252 ->configureNullable(true)
253 ->configureSerializationPhp()
254 ->configureColumnName('USER_TYPE_SETTINGS')
255 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_USER_TYPE_SETTINGS_FIELD'))
256 ,
257 'USER_TYPE_SETTINGS' => (new ORM\Fields\TextField('USER_TYPE_SETTINGS'))
258 ->configureNullable(true)
259 ,
260 'HINT' => (new ORM\Fields\StringField('HINT'))
261 ->configureNullable(true)
262 ->configureSize(255)
263 ->addValidator(new ORM\Fields\Validators\LengthValidator(null, 255))
264 ->configureTitle(Loc::getMessage('IBLOCK_PROPERTY_ENTITY_HINT_FIELD'))
265 ,
266 'LINK_IBLOCK' => new ORM\Fields\Relations\Reference(
267 'LINK_IBLOCK',
268 IblockTable::class,
269 ORM\Query\Join::on('this.LINK_IBLOCK_ID', 'ref.ID')
270 ),
271 'IBLOCK' => new ORM\Fields\Relations\Reference(
272 'IBLOCK',
273 IblockTable::class,
274 ORM\Query\Join::on('this.IBLOCK_ID', 'ref.ID')
275 ),
276 ];
277 }
278
285 public static function onBeforeAdd(ORM\Event $event): ORM\EventResult
286 {
287 $result = new ORM\EventResult;
288 $fields = $event->getParameter('fields');
289
290 $modifyFieldList = [];
291 self::copyOldFields($modifyFieldList, $fields);
292 $result->unsetField('USER_TYPE_SETTINGS');
293
294 if (!empty($modifyFieldList))
295 $result->modifyFields($modifyFieldList);
296 unset($modifyFieldList);
297 unset($fields);
298
299 return $result;
300 }
301
308 public static function onBeforeUpdate(ORM\Event $event): ORM\EventResult
309 {
310 $result = new ORM\EventResult;
311 $fields = $event->getParameter('fields');
312
313 $modifyFieldList = [];
314 self::copyOldFields($modifyFieldList, $fields);
315 $result->unsetField('USER_TYPE_SETTINGS');
316
317 if (!empty($modifyFieldList))
318 $result->modifyFields($modifyFieldList);
319 unset($modifyFieldList);
320 unset($fields);
321
322 return $result;
323 }
324
332 private static function copyOldFields(array &$result, array $data): void
333 {
334 if (!isset($data['USER_TYPE_SETTINGS_LIST']) && isset($data['USER_TYPE_SETTINGS']))
335 {
336 $settings = $data['USER_TYPE_SETTINGS'];
337 if (
338 is_string($settings)
339 && $settings !== ''
340 )
341 {
342 $settings = unserialize($settings, ['allowed_classes' => false]);
343 }
344 if (is_array($settings))
345 {
346 $result['USER_TYPE_SETTINGS_LIST'] = $settings;
347 }
348 unset($settings);
349 }
350 }
351}
static onBeforeAdd(ORM\Event $event)
static onBeforeUpdate(ORM\Event $event)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29