• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockelement.php
  • Класс: CAllIBlockElement
  • Вызов: CAllIBlockElement::getSearchableContent
protected function getSearchableContent(int $id, array $fields, array $iblock): ?string
{
	if ($id <= 0 || empty($fields))
	{
		return null;
	}

	$result = $fields['NAME'];

	$properties = array();
	$list = $this->getIndexedProperties($iblock['ID']);
	if (!empty($list))
	{
		$properties = $list;
	}
	$list = $this->getOfferProperties($iblock['ID']);
	if (!empty($list))
	{
		foreach (array_keys($list) as $index)
		{
			$properties[$index] = $list[$index];
		}
	}

	if (!empty($properties))
	{
		$connection = MainApplication::getConnection();
		if ($iblock["VERSION"] == IblockIblockTable::PROPERTY_STORAGE_COMMON)
		{
			$iterator = $connection->query("
				select *
				from b_iblock_element_property
				where IBLOCK_ELEMENT_ID=".$id."
				and IBLOCK_PROPERTY_ID in (".implode(", ", array_keys($properties)).")
			");
		}
		else
		{
			$iterator = $connection->query("
				select *
				from b_iblock_element_prop_m".$iblock['ID']."
				where IBLOCK_ELEMENT_ID=".$id."
				and IBLOCK_PROPERTY_ID in (".implode(", ", array_keys($properties)).")
			");
		}
		while ($row = $iterator->fetch())
		{
			$result .= "rn";
			$property = $properties[$row["IBLOCK_PROPERTY_ID"]];
			if (isset($property["GetSearchContent"]))
			{
				$result .= HTMLToTxt(
					call_user_func_array($property["GetSearchContent"],
						array(
							$property,
							array("VALUE" => $row["VALUE"]),
							array(),
						)
					)
				);
			}
			elseif ($property["PROPERTY_TYPE"] == IblockPropertyTable::TYPE_LIST)
			{
				$arEnum = CIBlockPropertyEnum::GetByID($row["VALUE"]);
				if ($arEnum !== false)
					$result .= $arEnum["VALUE"];
			}
			elseif($property["PROPERTY_TYPE"] == IblockPropertyTable::TYPE_FILE)
			{
				$arFile = CIBlockElement::__GetFileContent($row["VALUE"]);
				if(is_array($arFile))
				{
					$result .= $arFile["CONTENT"];
				}
			}
			else
			{
				$result .= $row["VALUE"];
			}
		}
		if ($iblock["VERSION"] == IblockIblockTable::PROPERTY_STORAGE_SEPARATE)
		{
			$iterator = $connection->query("
					select *
					from b_iblock_element_prop_s".$iblock['ID']."
					where IBLOCK_ELEMENT_ID=".$id."
				");
			if ($row = $iterator->fetch())
			{
				foreach($properties as $propertyId => $item)
				{
					$fieldId = 'PROPERTY_'.$propertyId;
					if (isset($row[$fieldId])
						&& $item["MULTIPLE"] == "N"
						&& $row[$fieldId] != '')
					{
						$result .= "rn";
						if (isset($item["GetSearchContent"]))
						{
							$result .= HTMLToTxt(
								call_user_func_array($item["GetSearchContent"],
									array(
										$item,
										array("VALUE" => $row[$fieldId]),
										array(),
									)
								)
							);
						}
						elseif ($item["PROPERTY_TYPE"] == IblockPropertyTable::TYPE_LIST)
						{
							$arEnum = CIBlockPropertyEnum::GetByID($row[$fieldId]);
							if($arEnum!==false)
								$result .= $arEnum["VALUE"];
						}
						elseif($item["PROPERTY_TYPE"] == IblockPropertyTable::TYPE_FILE)
						{
							$arFile = CIBlockElement::__GetFileContent($row[$fieldId]);
							if(is_array($arFile))
							{
								$result .= $arFile["CONTENT"];
							}
						}
						else
						{
							$result .= $row[$fieldId];
						}
					}
				}
			}
		}
	}
	if (isset($fields["PREVIEW_TEXT"]))
	{
		if (isset($fields["PREVIEW_TEXT_TYPE"]) && $fields["PREVIEW_TEXT_TYPE"] == "html")
			$result .= "rn".HTMLToTxt($fields["PREVIEW_TEXT"]);
		else
			$result .= "rn".$fields["PREVIEW_TEXT"];
	}
	if (isset($fields["DETAIL_TEXT"]))
	{
		if (isset($fields["DETAIL_TEXT_TYPE"]) && $fields["DETAIL_TEXT_TYPE"] == "html")
			$result .= "rn".HTMLToTxt($fields["DETAIL_TEXT"]);
		else
			$result .= "rn".$fields["DETAIL_TEXT"];
	}

	return $result;
}