/** * Возвращает список категорий в XML * @param \DOMNode $node * @param bool|null $visible * @param int|null $selected * @return bool */ public static function getCategoriesListXML($node, $visible = null, $selected = null) { $list = \Difra\Plugins\Catalog\Category::getList($visible); if (empty($list)) { return false; } $selectedList = []; $cont = true; while ($selected and $cont) { $cont = false; foreach ($list as $cat) { if ($cat->getId() == $selected) { $selectedList[] = $selected; $selected = $cat->getParent(); $cont = true; break; } } } foreach ($list as $cat) { /** @var \DOMElement $catNode */ $catNode = $node->appendChild($node->ownerDocument->createElement('category')); $cat->getXML($catNode); if (!empty($selectedList) and in_array($cat->getId(), $selectedList)) { $catNode->setAttribute('selected', '1'); } } return true; }