Creates a flat list node items.

@param MW_Tree_Node_Interface $node Root node
@return Associated list of ID / node object pairs
320723
protected function _getNodeMap( MW_Tree_Node_Interface $node )
	{
		$map = array();

		$map[ (string) $node->getId() ] = $node;

		foreach( $node->getChildren() as $child ) {
			$map += $this->_getNodeMap( $child );
		}

		return $map;
	}
672741
public function saveNode( MW_Tree_Node_Interface $node )
	{
		if( $node->getId() === null ) {
			throw new MW_Tree_Exception( sprintf( 'Unable to save newly created nodes, use insert method instead' ) );
		}

		if( $node->isModified() === false ) {
			return;
		}

		$conn = $this->_dbm->acquire( $this->_dbname );

		try
		{
			$stmt = $conn->create( $this->_config['update'] );
			$stmt->bind( 1, $node->getLabel() );
			$stmt->bind( 2, $node->getCode() );
			$stmt->bind( 3, $node->getStatus() );
			$stmt->bind( 4, $node->getId() );
			$stmt->execute()->finish();

			$this->_dbm->release( $conn, $this->_dbname );
		}
		catch( Exception $e )
		{
			$this->_dbm->release( $conn, $this->_dbname );
			throw $e;
		}
	}
208312
private static function _nodeToArray($node)
    {
        $type = null;
        if ($node instanceof DOMElement) {
            $type = $node->getAttribute('type');
        }

        switch($type) {
        case 'array':
            $array = [];
            foreach ($node->childNodes as $child) {
                $value = self::_nodeToValue($child);
                if ($value !== null) {
                    $array[] = $value;
                }
            }
            return $array;
        case 'collection':
            $collection = [];
            foreach ($node->childNodes as $child) {
                $value = self::_nodetoValue($child);
                if ($value !== null) {
                    if (!isset($collection[$child->nodeName])) {
                        $collection[$child->nodeName] = [];
                    }
                    $collection[$child->nodeName][] = self::_nodeToValue($child);
                }
            }
            return $collection;
        default:
            $values = [];
            if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof DOMText) {
                return $node->childNodes->item(0)->nodeValue;
            } else {
                foreach ($node->childNodes as $child) {
                    if (!$child instanceof DOMText) {
                        $values[$child->nodeName] = self::_nodeToValue($child);
                    }
                }
                return $values;
            }
        }
    }
833540
public function addNode(NodeInterface $node)
    {
        if ($this->checkChildNode($node)) {
            $this->nodes->add($node);

            $node->setPosition(count($this->getNodes()));
            $node->setParent($this);
        }

        return $this;
    }
872138
public function getPropertiesArray(NodeInterface $node)
    {
        $properties = [];
        foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
            if ($propertyName[0] === '_' && $propertyName[1] === '_') {
                // skip fully-private properties
                continue;
            }

            $properties[$propertyName] = $this->getProperty($node, $propertyName);
        }

        return $properties;
    }
1339425
protected function traverseNode(Node $node) : Node
    {
        foreach ($node->getSubNodeNames() as $name) {
            $subNode =& $node->$name;

            if (\is_array($subNode)) {
                $subNode = $this->traverseArray($subNode);
                if ($this->stopTraversal) {
                    break;
                }
            } elseif ($subNode instanceof Node) {
                $traverseChildren = true;
                foreach ($this->visitors as $visitor) {
                    $return = $visitor->enterNode($subNode, $traverseChildren);
                    if (null !== $return) {
                        if ($return instanceof Node) {
                            $subNode = $return;
                        } elseif (self::DONT_TRAVERSE_CHILDREN === $return) {
                            $traverseChildren = false;
                        } elseif (self::STOP_TRAVERSAL === $return) {
                            $this->stopTraversal = true;
                            break 2;
                        } else {
                            throw new \LogicException(
                                'enterNode() returned invalid value of type ' . gettype($return)
                            );
                        }
                    }
                }

                if ($traverseChildren) {
                    $subNode = $this->traverseNode($subNode);
                    if ($this->stopTraversal) {
                        break;
                    }
                }

                foreach ($this->visitors as $visitor) {
                    $return = $visitor->leaveNode($subNode);
                    if (null !== $return) {
                        if ($return instanceof Node) {
                            $subNode = $return;
                        } elseif (self::STOP_TRAVERSAL === $return) {
                            $this->stopTraversal = true;
                            break 2;
                        } elseif (\is_array($return)) {
                            throw new \LogicException(
                                'leaveNode() may only return an array ' .
                                'if the parent structure is an array'
                            );
                        } else {
                            throw new \LogicException(
                                'leaveNode() returned invalid value of type ' . gettype($return)
                            );
                        }
                    }
                }
            }
        }

        return $node;
    }
50266
protected function _createTree( MW_DB_Result_Interface $result, MW_Tree_Node_Interface $node )
	{
		while( ( $record = $result->fetch() ) !== false )
		{
			$newNode = $this->_createNode( $record );

			while( $this->_isChild( $newNode, $node ) )
			{
				$node->addChild( $newNode );

				if( ( $newNode = $this->_createTree( $result, $newNode ) ) === false ) {
					return false;
				}
			}

			return $newNode;
		}

		return false;
	}
429803
protected function _createNodeArray( MShop_Locale_Item_Site_Interface $item )
	{
		$result = $item->toArray();

		if( method_exists( $item, 'getChildren' ) )
		{
			foreach( $item->getChildren() as $child ) {
				$result['children'][] = $this->_createNodeArray( $child );
			}
		}

		return (object) $result;
	}
200647
public function dumpNode(BaseNode $node)
    {
        return '<?php'.PHP_EOL.PHP_EOL.'return ['.parent::dumpNode($node).PHP_EOL.'];'.PHP_EOL;
    }
363512
public function node2Scope(SiteTreeNodeInterface $node){

        $scope = new TreeScope();
        $urlSegment = trim($node->getUrlSegment(),'/');

        $name = $urlSegment ? $urlSegment : TreeScope::DEFAULT_NAME;

        $scope->setPathPrefix($node->getUrlSegment());
        $scope->setName($name);
        $scope->setTitle($node->getMenuTitle());
        $scope->setModelRootId($node->{$this->treeModel->rootCol()});

        return $scope;

    }
169340
public function generateTree($nodes)
    {
        $superRoot = count(array_filter($nodes, function (ReadNodeInterface $node) {
            return '-' == $node->getParentId();
        }))? '-': 'root';

        $list = array();
        $list[$superRoot] = array();
        foreach ($nodes as $node) {
            if ($superRoot !== $node->getParentId() && $this->parentInList($node->getParentId(), $nodes)) {
                $list[$node->getParentId()][] = $node;
                continue;
            }
            $list[$superRoot][] = $node;
        }

        $tree = $this->createTree($list[$superRoot], $list);

        return $tree;
    }
1017940
protected function nodeToDictionary( Node $node )
    {
        $result = $node->attributes;

        $containerKeys = [];

        foreach ($node->children as $child) {
            $arrayChild = $this->nodeToDictionary($child);

            $childName = $child->name;
            $childValue = $arrayChild;

            if (sizeof($child->children) == 0) {
                $childValue = $child->text;
            }

            if (isset( $result[ $childName ] )) {
                if (!in_array($childName, $containerKeys)) {
                    $result[ $childName ] = [$result[ $childName ]];
                    $containerKeys[] = $childName;
                }

                $result[ $childName ][] = $childValue;
            } else {
                $result[ $childName ] = $childValue;
            }
        }

        return $result;
    }
1268553
public function addNode(Node $node)
    {
        $node->setNavigation($this);
        $this->nodes[] = $node;

        return $this;
    }
599549
public function find(AbstractNode $node): Collection
    {
        $results = new Collection;
        foreach ($this->selectors as $selector) {
            $nodes = [$node];
            if (count($selector) == 0) {
                continue;
            }

            $options = [];
            foreach ($selector as $rule) {
                if ($rule['alterNext']) {
                    $options[] = $this->alterNext($rule);
                    continue;
                }
                $nodes = $this->seek($nodes, $rule, $options);
                // clear the options
                $options = [];
            }

            // this is the final set of nodes
            foreach ($nodes as $result) {
                $results[] = $result;
            }
        }

        return $results;
    }
1066590
private static function extract(NodeInterface $node)
    {
        $attributes = [];
        $nodes = [];

        foreach (self::extractProperties($node) as $name => $value) {
            if (is_array($value)) {
                foreach ($value as $item) {
                    if ($item instanceof NodeInterface) {
                        $nodes[$name][] = $item;
                    } else {
                        $attributes[$name][] = $item;
                    }
                }
            } else {
                if ($value instanceof NodeInterface) {
                    $nodes[$name] = $value;
                } else {
                    $attributes[$name] = $value;
                }
            }
        }

        return [$attributes, $nodes];
    }
320438
public function buildOptionsArray($node, $nodesArray)
    {
        $item           = [];
        $item['ref']    = $node['ref'];
        $item['label']  = $node['label'];
        $item['link']   = $node['link'];
        $item['target'] = $node['target'];
        $item['pos']    = $node['pos'];
        $item['parent'] = $node['parent'];

        $nodesArray[]   = $item;
        if (array_key_exists('children', $node)) {
            foreach ($node['children'] as $child) {
                $nodesArray = $this->buildOptionsArray($child, $nodesArray);
            }
        }
        return $nodesArray;
    }
445662
public function getTreeSelectList(array $list, $root = 0)
    {
        $list = ArrayHelper::listToTree($list, $this->pkField, $this->parentField, '_child', $root);
        $list = $this->_toFormatTree($list, 0);
        
        return $this->buildTreeOptionsToArray($list);
    }