15 private const PROPERTY_PREFIX =
'PROPERTY_';
16 private const PROPERTY_MASK =
'/^' . self::PROPERTY_PREFIX .
'([0-9]+)$/';
18 private int $iblockId;
19 private bool $isShowXmlId;
20 private bool $isShowSections;
21 private array $propertyList = [];
22 private array $userTypeList;
24 public function __construct(
int $iblockId,
bool $isShowXmlId,
bool $isShowSections)
26 $this->iblockId = $iblockId;
27 $this->isShowXmlId = $isShowXmlId;
28 $this->isShowSections = $isShowSections;
53 if ($this->isShowSections)
60 $fields[
'INCLUDE_SUBSECTIONS'] = [
71 if ($this->isShowXmlId)
87 'type' =>
'entity_selector',
95 'type' =>
'entity_selector',
139 'USER_TYPE_SETTINGS_LIST',
142 '=IBLOCK_ID' => $this->iblockId,
156 $row = $this->validateProperty($row);
162 $fullType = $this->getFullPropertyType($row);
164 $fieldType = $typesMap[$fullType] ??
null;
170 $id = $this->getPropertyId($row[
'ID']);
172 'type' => $fieldType,
173 'name' => $row[
'NAME'],
176 if ($row[
'USER_TYPE'] ===
'')
178 switch ($row[
'PROPERTY_TYPE'])
183 $field[
'partial'] =
true;
189 $userType = $this->userTypeList[$row[
'USER_TYPE']];
190 if (isset($userType[
'GetUIFilterProperty']) && is_callable($userType[
'GetUIFilterProperty']))
192 call_user_func_array(
193 $userType[
'GetUIFilterProperty'],
200 if (empty($field) || !is_array($field))
204 $field[
'partial'] =
true;
208 $properties[$id] = $field;
210 $this->propertyList[$id] = $row;
220 foreach ($rawFilterValue as $fieldId => $values)
222 $field = \CIBlock::MkOperationFilter($fieldId);
223 $id = $field[
'FIELD'];
228 elseif (isset($this->propertyList[$id]))
230 $prepareResult = $this->preparePropertyValues($id, $values);
233 $result[$fieldId] = $prepareResult;
235 unset($prepareResult);
242 private function preparePropertyValues(
string $propertyId, $values): mixed
245 $row = $this->propertyList[$propertyId];
246 if ($row[
'USER_TYPE'] ===
'')
252 $userType = $this->userTypeList[$row[
'USER_TYPE']] ??
null;
255 if (isset($userType[
'ConvertToDB']) && is_callable($userType[
'ConvertToDB']))
257 if (is_array($values))
260 foreach ($values as $item)
262 $prepareItem = $this->convertPropertyValueToDb(
263 $userType[
'ConvertToDB'],
269 $prepareValues[] = $prepareItem;
273 if (!empty($prepareValues))
277 unset($prepareValues);
281 $prepareValue = $this->convertPropertyValueToDb(
282 $userType[
'ConvertToDB'],
290 unset($prepareValue);
305 private function convertPropertyValueToDb(callable $function,
array $property, $value): mixed
307 $result = call_user_func_array(
332 $result[0] = Loc::getMessage(
'IBLOCK_FILTER_DATAPROVIDER_ELEMENT_FIELDS_SECTION_TOP_LEVEL');
336 'LEFT_MARGIN' =>
'ASC',
339 'IBLOCK_ID' => $this->iblockId,
340 'CHECK_PERMISSIONS' =>
'Y',
341 'MIN_PERMISSION' =>
'R',
354 $margin = max((
int)$row[
'DEPTH_LEVEL'], 1) - 1;
368 if (!isset($this->propertyList[$fieldId]))
372 $row = $this->propertyList[$fieldId];
376 && $row[
'USER_TYPE'] ===
''
385 $propertyId = $this->propertyList[$fieldId][
'ID'] ??
null;
388 return $this->getPropertyEnumValueListItems($propertyId);
394 private function getPropertyEnumValueListItems(
int $propertyId):
array
397 $iterator = PropertyEnumerationTable::getList([
404 '=PROPERTY_ID' => $propertyId,
417 $result[$row[
'ID']] = $row[
'VALUE'];
424 private function getPropertyId(
string|
int $id): string
426 return self::PROPERTY_PREFIX . $id;
431 return (preg_match(self::PROPERTY_MASK, $id) === 1);
436 if (!isset($this->propertyList[$id]))
441 $row = $this->propertyList[$id];
444 if ($row[
'USER_TYPE'] ===
'')
446 switch ($row[
'PROPERTY_TYPE'])
450 'items' => $this->getPropertyEnumValueListItems($row[
'ID']),
460 $description = $this->getElementPropertyDescription($row);
463 $description = $this->getSectionPropertyDescription($row);
469 $userType = $this->userTypeList[$row[
'USER_TYPE']];
470 if (isset($userType[
'GetUIFilterProperty']) && is_callable($userType[
'GetUIFilterProperty']))
473 call_user_func_array(
474 $userType[
'GetUIFilterProperty'],
491 private function validateProperty(
array $row): ?
array
493 $row[
'ID'] = (int)$row[
'ID'];
494 $row[
'USER_TYPE'] = (string)$row[
'USER_TYPE'];
495 $row[
'USER_TYPE_SETTINGS'] = $row[
'USER_TYPE_SETTINGS_LIST'];
496 unset($row[
'USER_TYPE_SETTINGS_LIST']);
497 $row[
'FULL_PROPERTY_TYPE'] = $this->getFullPropertyType($row);
498 if ($row[
'USER_TYPE'] ===
'')
503 if (!isset($this->userTypeList))
505 $this->userTypeList = \CIBlockProperty::GetUserType();
507 $userTypeId = $row[
'USER_TYPE'];
508 if (!isset($this->userTypeList[$userTypeId]))
516 private function getFullPropertyType(
array $row): string
519 $row[
'USER_TYPE'] ===
''
520 ? $row[
'PROPERTY_TYPE']
521 : $row[
'PROPERTY_TYPE'] .
':' . $row[
'USER_TYPE']
525 private function getElementPropertyDescription(
array $property):
array
528 'type' =>
'entity_selector',
534 'id' => IblockPropertyElementProvider::ENTITY_ID,
535 'dynamicLoad' =>
true,
536 'dynamicSearch' =>
true,
538 'iblockId' => (int)($property[
'LINK_IBLOCK_ID'] ?? 0),
543 'allowCreateItem' =>
false,
550 private function getSectionPropertyDescription(
array $property):
array
553 'type' =>
'entity_selector',
559 'id' => IblockPropertySectionProvider::ENTITY_ID,
560 'dynamicLoad' =>
true,
561 'dynamicSearch' =>
true,
563 'iblockId' => (int)($property[
'LINK_IBLOCK_ID'] ?? 0),
568 'allowCreateItem' =>
false,
static getList(array $parameters=array())
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)