• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/cml2.php
  • Класс: CIBlockCMLExport
  • Вызов: CIBlockCMLExport::ExportSections
function ExportSections(&$SECTION_MAP, $start_time, $INTERVAL, $FILTER = "", $PROPERTY_MAP = array())
{
	/** @var CUserTypeManager $USER_FIELD_MANAGER */
	global $USER_FIELD_MANAGER;

	$counter = 0;
	if(!array_key_exists("CURRENT_DEPTH", $this->next_step))
		$this->next_step["CURRENT_DEPTH"]=0;
	else // this makes second "step"
		return $counter;

	$arUserFields = $USER_FIELD_MANAGER->GetUserFields("IBLOCK_".$this->arIBlock["ID"]."_SECTION");
	foreach($arUserFields as $FIELD_ID => $arField)
		if($arField["XML_ID"] == '')
			$arUserFields[$FIELD_ID]["XML_ID"] = $FIELD_ID;

	if($this->bExtended)
		$this->ExportSectionsProperties($arUserFields);

	$SECTION_MAP = array();

	if($FILTER === "none")
		return 0;
	$arFilter = array(
		"IBLOCK_ID" => $this->arIBlock["ID"],
		"GLOBAL_ACTIVE" => "Y",
		"CHECK_PERMISSIONS" => "N",
	);
	if($FILTER === "all")
		unset($arFilter["GLOBAL_ACTIVE"]);

	$rsSections = CIBlockSection::GetList(array("left_margin"=>"asc"), $arFilter, false, array("UF_*"));
	fwrite($this->fp, "tt<".GetMessage("IBLOCK_XML2_GROUPS").">n");
	while($arSection = $rsSections->Fetch())
	{
		$white_space = str_repeat("tt", $arSection["DEPTH_LEVEL"]);
		$level = ($arSection["DEPTH_LEVEL"]+1)*2;

		while($this->next_step["CURRENT_DEPTH"] >= $arSection["DEPTH_LEVEL"])
		{
			fwrite($this->fp, str_repeat("tt", $this->next_step["CURRENT_DEPTH"])."ttn");
			fwrite($this->fp, str_repeat("tt", $this->next_step["CURRENT_DEPTH"]-1)."tttn");
			$this->next_step["CURRENT_DEPTH"]--;
		}

		$xml_id = $this->GetSectionXML_ID($this->arIBlock["ID"], $arSection["ID"], $arSection["XML_ID"]);
		$SECTION_MAP[$arSection["ID"]] = $xml_id;

		fwrite($this->fp,
			$white_space."t<".GetMessage("IBLOCK_XML2_GROUP").">n"
			.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_ID"), $xml_id)
			.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_NAME"), $arSection["NAME"])
		);
		if($arSection["DESCRIPTION"] <> '')
			fwrite($this->fp, $white_space."tt<".GetMessage("IBLOCK_XML2_DESCRIPTION").">".htmlspecialcharsbx(FormatText($arSection["DESCRIPTION"], $arSection["DESCRIPTION_TYPE"]))."n");
		if($this->bExtended)
		{
			fwrite($this->fp,
				$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_BX_ACTIVE"), ($arSection["ACTIVE"]=="Y"? "true": "false"))
				.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_BX_SORT"), intval($arSection["SORT"]))
				.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_BX_CODE"), $arSection["CODE"])
				.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_BX_PICTURE"), $this->ExportFile($arSection["PICTURE"]))
				.$this->formatXMLNode($level, GetMessage("IBLOCK_XML2_BX_DETAIL_PICTURE"), $this->ExportFile($arSection["DETAIL_PICTURE"]))
			);

			if(!empty($arUserFields))
			{
				fwrite($this->fp, $white_space."tt<".GetMessage("IBLOCK_XML2_PROPERTIES_VALUES").">n");
				foreach($arUserFields as $FIELD_ID => $arField)
				{
					fwrite($this->fp, $white_space."ttt<".GetMessage("IBLOCK_XML2_PROPERTY_VALUES").">n");
					fwrite($this->fp, $this->formatXMLNode($level+2, GetMessage("IBLOCK_XML2_ID"), $arField["XML_ID"]));

					$values = array();
					if(!is_array($arSection[$FIELD_ID]))
					{
						if($arField["USER_TYPE"]["BASE_TYPE"] === "file")
							$values[] = $this->ExportFile($arSection[$FIELD_ID]);
						elseif($arField["USER_TYPE"]["BASE_TYPE"] === "enum")
							$values[] = $this->ExportEnum($arField, $arSection[$FIELD_ID]);
						else
							$values[] = $arSection[$FIELD_ID];
					}
					elseif(empty($arSection[$FIELD_ID]))
					{
						$values[] = "";
					}
					else
					{
						foreach($arSection[$FIELD_ID] as $value)
						{
							if($arField["USER_TYPE"]["BASE_TYPE"] === "file")
								$values[] = $this->ExportFile($value);
							elseif($arField["USER_TYPE"]["BASE_TYPE"] === "enum")
								$values[] = $this->ExportEnum($arField, $value);
							else
								$values[] = $value;
						}
					}

					foreach($values as $value)
					{
						fwrite($this->fp, $this->formatXMLNode($level+2, GetMessage("IBLOCK_XML2_VALUE"), $value));
					}

					fwrite($this->fp, $white_space."tttn");
				}
				fwrite($this->fp, $white_space."ttn");
			}

			$this->ExportSmartFilter($level, $this->arIBlock["ID"], $arSection["ID"], $PROPERTY_MAP);

			$sectionTemplates = new BitrixIblockInheritedPropertySectionTemplates($this->arIBlock["ID"], $arSection["ID"]);
			$this->exportInheritedTemplates($arSection["DEPTH_LEVEL"]*2 + 2, $sectionTemplates);
		}

		fwrite($this->fp, $white_space."tt<".GetMessage("IBLOCK_XML2_GROUPS").">n");

		$this->next_step["CURRENT_DEPTH"] = $arSection["DEPTH_LEVEL"];
		$counter++;
	}

	while($this->next_step["CURRENT_DEPTH"] > 0)
	{
		fwrite($this->fp, str_repeat("tt", $this->next_step["CURRENT_DEPTH"])."ttn");
		fwrite($this->fp, str_repeat("tt", $this->next_step["CURRENT_DEPTH"]-1)."tttn");
		$this->next_step["CURRENT_DEPTH"]--;
	}
	fwrite($this->fp, "ttn");

	return $counter;
}