• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockproperty.php
  • Класс: CAllIBlockProperty
  • Вызов: CAllIBlockProperty::GetPropertyArray
static function GetPropertyArray($ID, $IBLOCK_ID, $bCached=true)
{
	if (!is_int($ID) && !is_string($ID))
	{
		return false;
	}

	$iblockIdList = [];
	$iblockCodeList = [];

	if (is_array($IBLOCK_ID))
	{
		foreach ($IBLOCK_ID as $value)
		{
			if (is_numeric($value))
			{
				$value = (int)$value;
				if ($value > 0)
				{
					$iblockIdList[$value] = $value;
				}
			}
			elseif (is_string($value))
			{
				$value = trim($value);
				if ($value !== '')
				{
					$iblockCodeList[$value] = $value;
				}
			}
		}
	}
	elseif (is_numeric($IBLOCK_ID))
	{
		$iblockId = (int)$IBLOCK_ID;
		if ($iblockId > 0)
		{
			$iblockIdList[$iblockId] = $iblockId;
		}
		unset($iblockId);
	}
	elseif (is_string($IBLOCK_ID))
	{
		$iblockCode = trim($IBLOCK_ID);
		if ($iblockCode !== '')
		{
			$iblockCodeList[$iblockCode] = $iblockCode;
		}
		unset($iblockCode);
	}

	$cacheId = $ID . '|' . implode(', ', $iblockIdList) . '|' . implode(', ', $iblockCodeList);

	global $IBLOCK_CACHE_PROPERTY;
	if ($bCached && isset($IBLOCK_CACHE_PROPERTY[$cacheId]))
	{
		return $IBLOCK_CACHE_PROPERTY[$cacheId];
	}

	$runtime = [];
	$filter = [];
	if (!empty($iblockIdList) && !empty($iblockCode))
	{
		$filter[] = [
			'LOGIC' => 'OR',
			'@IBLOCK.ID' => $iblockIdList,
			'@IBLOCK.CODE' => $iblockCodeList
		];
	}
	elseif (!empty($iblockIdList))
	{
		$filter['@IBLOCK.ID'] = $iblockIdList;
	}
	elseif (!empty($iblockCodeList))
	{
		$filter['@IBLOCK.CODE'] = $iblockCodeList;
	}

	$propertyId = null;
	$propertyCode = null;
	$propertyFullCode = null;
	$existsValuePostfix = false;
	if (is_int($ID))
	{
		$propertyId = $ID;
	}
	else
	{
		$upperId = mb_strtoupper($ID);
		$preparedId = [];
		if (preg_match('/^([A-Za-z0-9_]+)(_VALUE)$/', $upperId, $preparedId))
		{
			$existsValuePostfix = true;
			$value = (int)$preparedId[1];
			if ($value > 0)
			{
				$propertyId = $value;
			}
			else
			{
				$propertyCode = $preparedId[1];
				$propertyFullCode = $preparedId[0];
			}
		}
		else
		{
			$value = (int)$upperId;
			if ($value > 0)
			{
				$propertyId = $value;
			}
			else
			{
				$propertyCode = $upperId;
			}
		}
		unset($value);
		unset($preparedId);
		unset($upperId);
	}

	if ($propertyId !== null)
	{
		$filter['=ID'] = $propertyId;
	}
	else
	{
		$runtime[] = new MainORMFieldsExpressionField(
			'UPPER_PROPERTY_CODE',
			'UPPER(%s)',
			'CODE'
		);
		if ($existsValuePostfix)
		{
			$filter[] = [
				'LOGIC' => 'OR',
				[
					'=UPPER_PROPERTY_CODE' => $propertyFullCode,
					'!=PROPERTY_TYPE' => IblockPropertyTable::TYPE_LIST,
				],
				[
					'=UPPER_PROPERTY_CODE' => $propertyCode,
					'=PROPERTY_TYPE' => IblockPropertyTable::TYPE_LIST,
				]
			];
		}
		else
		{
			$filter['=UPPER_PROPERTY_CODE'] = $propertyCode;
		}
	}

	$params = [
		'select' => ['*'],
		'filter' => $filter,
		'cache' => [
			'ttl' => 86400,
		],
	];
	if (!empty($runtime))
	{
		$params['runtime'] = $runtime;
	}

	$iterator = IblockPropertyTable::getList($params);
	$propertyRow = $iterator->fetch();
	if (!empty($propertyRow))
	{
		unset($propertyRow['USER_TYPE_SETTINGS_LIST']);
		if ($propertyRow['TIMESTAMP_X'] instanceof MainTypeDateTime)
		{
			$propertyRow['TIMESTAMP_X'] = $propertyRow['TIMESTAMP_X']->format('Y-m-d H:i:s');
		}
		$propertyRow['ORIG_ID'] = $propertyRow['ID']; //it saves original (digital) id
		$propertyRow['IS_CODE_UNIQUE'] = true; //boolean check for global code uniquess
		$propertyRow['IS_VERSION_MIXED'] = false; //boolean check if varios versions of ibformation block properties

		while ($row = $iterator->fetch())
		{
			$propertyRow['IS_CODE_UNIQUE'] = false;
			if ($propertyRow['VERSION'] !== $row['VERSION'])
			{
				$propertyRow['IS_VERSION_MIXED'] = true;
			}
		}
		unset($row);

		if (
			$existsValuePostfix
			&& $propertyRow['PROPERTY_TYPE'] === IblockPropertyTable::TYPE_LIST
			&& mb_strtoupper((string)$propertyRow['CODE']) === $propertyCode
		)
		{
			$propertyRow['ID'] = mb_substr($ID, 0, -6);
		}
		else
		{
			$propertyRow['ID'] = $ID;
		}
	}
	unset($iterator);

	$IBLOCK_CACHE_PROPERTY[$cacheId] = $propertyRow;

	return $propertyRow;
}