• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/comp_pricetools.php
  • Класс: CIBlockPriceTools
  • Вызов: CIBlockPriceTools::getLabel
static function getLabel(&$item, $propertyCode)
{
	static $propertyEnum = array();

	if (!empty($item) && is_array($item))
	{
		$item['LABEL'] = false;
		$item['LABEL_VALUE'] = '';
		$item['LABEL_ARRAY_VALUE'] = array();

		if (!is_array($propertyCode))
		{
			$propertyCode = array($propertyCode);
		}

		if (!empty($propertyCode))
		{
			foreach ($propertyCode as $index => $code)
			{
				$code = (string)$code;

				if ($code !== '' && isset($item['PROPERTIES'][$code]))
				{
					$prop = $item['PROPERTIES'][$code];

					if (!empty($prop['VALUE']))
					{
						$useName = false;

						if ($prop['PROPERTY_TYPE'] == 'L' && $prop['MULTIPLE'] == 'N')
						{
							if (!isset($propertyEnum[$prop['ID']]))
							{
								$count = 0;
								$enumList = CIBlockPropertyEnum::GetList(
									array(),
									array('PROPERTY_ID' => $prop['ID'])
								);
								while ($enum = $enumList->Fetch())
								{
									$count++;
								}

								$propertyEnum[$prop['ID']] = $count;
								unset($enum, $enumList, $count);
							}

							$useName = ($propertyEnum[$prop['ID']] == 1);
						}

						if ($useName)
						{
							$item['LABEL_ARRAY_VALUE'][$code] = $prop['NAME'];
						}
						else
						{
							$item['LABEL_ARRAY_VALUE'][$code] = (is_array($prop['VALUE'])
								? implode(' / ', $prop['VALUE'])
								: $prop['VALUE']
							);
						}

						unset($useName);
						$item['LABEL'] = true;

						if ($item['LABEL_VALUE'] === '')
						{
							$item['LABEL_VALUE'] = $item['LABEL_ARRAY_VALUE'][$code];
						}

						if (isset($item['DISPLAY_PROPERTIES'][$code]))
						{
							unset($item['DISPLAY_PROPERTIES'][$code]);
						}
					}
					unset($prop);
				}
			}
		}
	}
}