- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockproptools.php
- Класс: CIBlockPropertyTools
- Вызов: CIBlockPropertyTools::getExistProperty
static function getExistProperty(int $iblockId, $propertyCodes, bool $indexCode = true)
{
if ($iblockId <= 0)
{
return false;
}
$propertyCodes = static::clearPropertyList($propertyCodes);
if (empty($propertyCodes))
{
return false;
}
$result = [];
$propertyIterator = IblockPropertyTable::getList([
'select' => [
'ID',
'CODE'
],
'filter' => [
'=IBLOCK_ID' => $iblockId,
'@CODE' => $propertyCodes
]
]);
if ($indexCode)
{
while ($property = $propertyIterator->fetch())
{
$property['ID'] = (int)$property['ID'];
if (!isset($result[$property['CODE']]))
{
$result[$property['CODE']] = $property['ID'];
}
else
{
if (!is_array($result[$property['CODE']]))
{
$result[$property['CODE']] = [
$result[$property['CODE']]
];
}
$result[$property['CODE']][] = $property['ID'];
}
}
unset($property, $propertyIterator);
}
else
{
while ($property = $propertyIterator->fetch())
{
$property['ID'] = (int)$property['ID'];
$result[$property['ID']] = $property['CODE'];
}
unset($property, $propertyIterator);
}
return $result;
}