//require($_SERVER["DOCUMENT_ROOT"]. "/bitrix/modules/main/include/prolog_before.php");?>
/*
echo "".$reader->nodeType." — nodeType
";
echo "".$reader->localName ." — localName
";
echo "".$reader->name." — name
";
echo "".$reader->namespaceURI." — namespaceURI
";
echo "".$reader->prefix." — prefix
";
echo "".$reader->value." — value
";
echo "".$reader->hasValue." — hasValue
";
echo "".$reader->getAttribute('id')." — getAttribute
";
die();
*/
class BuildTreeSections
{
private $arCategory = array();
private $arParentId = array();
public function __construct()
{
$this->GetCatFromXML();
$this->GetArParentId();
}
private function GetCatFromXML()
{
$reader = new XMLReader();
$reader->open('lamoda.xml');
while ($reader->read())
{
if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == 'categories')
{
while ($reader->read())
{
if ($reader->nodeType == XMLReader::ELEMENT)
{
$sectionId = $reader->getAttribute('id');
$parentId = $reader->getAttribute('parentId');
}
elseif($reader->nodeType == XMLReader::TEXT)
{
$this->arCategory[] = array(
'ID' => $sectionId,
'NAME' => $reader->value,
'PARENTID' => $parentId
);
}
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == 'categories')
{
break;
}
}
}
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == 'categories')
{
break;
}
}
$reader->close();
unset($reader);
}
public function GetArParentId()
{
$count = sizeof($this->arCategory);
if ($count > 0)
{
$this->arParentId[0] = $this->arCategory[0];
}
for ($i = 1; $i < $count; $i++)
{
$this->arParentId[$this->arCategory[$i]['PARENTID']][] = array(
$this->arCategory[$i]['ID'],
$this->arCategory[$i]['NAME']
);
}
//echo "
"; var_dump($this->arParentId); echo ""; } public function GetSubSection($parentId, $level) { //echo "
"; var_dump($this->arParentId[$parentId]); echo ""; if (isset($this->arParentId[$parentId])) { foreach ($this->arParentId[$parentId] as $arItem) { echo "