Get tree data for node

@param DataObject $node
@param int $depth
@return array|string
10121
protected function getSubtree($node, $depth = 0)
    {
        // Check if this node is limited due to child count
        $numChildren = $this->getNumChildren($node);
        $limited = $this->isNodeLimited($node, $numChildren);

        // Build root rode
        $expanded = $this->isExpanded($node);
        $opened = $this->isTreeOpened($node);
        $count = ($limited && $numChildren > $this->getMaxChildNodes()) ? 0 : $numChildren;
        $output = [
            'node' => $node,
            'marked' => $this->isMarked($node),
            'expanded' => $expanded,
            'opened' => $opened,
            'depth' => $depth,
            'count' => $count, // Count of DB children
            'limited' => $limited, // Flag whether 'items' has been limited
            'children' => [], // Children to return in this request
        ];

        // Don't iterate children if past limit
        // or not expanded (requires subsequent request to get)
        if ($limited || !$expanded) {
            return $output;
        }

        // Get children
        $children = $this->getChildren($node);
        foreach ($children as $child) {
            // Recurse
            if ($this->isMarked($child)) {
                $output['children'][] = $this->getSubtree($child, $depth + 1);
            }
        }
        return $output;
    }
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;
	}
376517
protected function getBasicNodeInformation(NodeInterface $node): array
    {
        return [
            'contextPath' => $node->getContextPath(),
            'name' => $node->getName(),
            'identifier' => $node->getIdentifier(),
            'nodeType' => $node->getNodeType()->getName(),
            'label' => $node->getLabel(),
            'isAutoCreated' => $node->isAutoCreated(),
            'depth' => $node->getDepth(),
            'children' => [],
            'matchesCurrentDimensions' => ($node instanceof Node && $node->dimensionsAreMatchingTargetDimensionValues())
        ];
    }
124658
public function getAncestor($itemName, $depth = 0)
    {
        $ancestors = array();
        $parents = $this->getParents($itemName);
        if (empty($parents)) {
            $parents = $this->owner->db->createCommand()
                ->select('parent')
                ->from($this->owner->itemChildTable)
                ->where('child=:child', array(':child' => $itemName))
                ->queryColumn();
            $this->setItemParents($itemName, $parents);
        }

        foreach ($parents as $parent) {
            $ancestors[] = array(
                'name' => $parent,
                'item' => $this->owner->getAuthItem($parent),
                'parents' => $this->getAncestor($parent, $depth + 1),
                'depth' => $depth
            );
        }
        return $ancestors;
    }
85008
private function getParentTreeParams(\Coral\ContentBundle\Entity\Node $node)
    {
        $params = $this->getDoctrine()->getManager()->createQuery(
                'SELECT n.level, na.name, na.value
                FROM CoralContentBundle:NodeAttribute na
                INNER JOIN na.node n WITH (n.lft < :lft AND n.rgt > :rgt)
                INNER JOIN n.account a WITH (a.id = :account_id)
                WHERE
                    na.name LIKE \'tree_%\'
                ORDER BY n.level ASC'
            )
            ->setParameter('account_id', $this->getAccount()->getId())
            ->setParameter('lft', $node->getLft())
            ->setParameter('rgt', $node->getRgt())
            ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

        $treeParams = array();

        foreach ($params as $param)
        {
            $treeParams[$param['name']] = $param['value'];
        }

        return $treeParams;
    }
1101713
public function fetchTree($rootId=null, $depth=null)
    {
        $wrappers = $this->fetchTreeAsArray($rootId, $depth);

        return (!is_array($wrappers) || empty($wrappers)) ? null : $wrappers[0];
    }
710222
public function printObj($depth = 0)
    {
        $s = str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data . "\n";
        foreach ($this->subs as $sub) {
            $s .= $sub->printObj($depth + 1);
        }
        return $s;
    }
388124
public function getChildrenNodes(Node $node)
    {
        $result = $this->search($node->getDn(), null, false);

        $nodes = array();
        foreach ($result as $node) {
            $nodes[] = $node;
        }

        return $nodes;
    }
72602
protected function &getNode(&$node, $key)
    {
        if (is_array($node) && isset($node[$key])) {
            return $node[$key];
        }

        if (!is_object($node) || !isset($node->$key)) {
            $result = null;
            return $result;
        }

        // Special check for __isset and __get
        if (property_exists($node, $key)) {
            return $node->$key;
        }

        if (method_exists($node, '__get')) {
            $value = $node->__get($key);
            return $value;
        }

        $result = null;
        return $result;
    }
786071
protected function navigation_node(navigation_node $node, $attrs=array(), $depth = 1) {
        $items = $node->children;

        // exit if empty, we don't want an empty ul element
        if ($items->count()==0) {
            return '';
        }

        // array of nested li elements
        $lis = array();
        $number = 0;
        foreach ($items as $item) {
            $number++;
            if (!$item->display) {
                continue;
            }

            $isbranch = ($item->children->count()>0  || $item->nodetype==navigation_node::NODETYPE_BRANCH);

            if ($isbranch) {
                $item->hideicon = true;
            }

            $content = $this->output->render($item);
            $id = $item->id ? $item->id : html_writer::random_id();
            $ulattr = ['id' => $id . '_group', 'role' => 'group'];
            $liattr = ['class' => [$item->get_css_type(), 'depth_'.$depth], 'tabindex' => '-1'];
            $pattr = ['class' => ['tree_item'], 'role' => 'treeitem'];
            $pattr += !empty($item->id) ? ['id' => $item->id] : [];
            $hasicon = (!$isbranch && $item->icon instanceof renderable);

            if ($isbranch) {
                $liattr['class'][] = 'contains_branch';
                if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count() == 0
                        && $item->nodetype == navigation_node::NODETYPE_BRANCH)) {
                    $pattr += ['aria-expanded' => 'false'];
                } else {
                    $pattr += ['aria-expanded' => 'true'];
                }
                if ($item->requiresajaxloading) {
                    $pattr['data-requires-ajax'] = 'true';
                    $pattr['data-loaded'] = 'false';
                } else {
                    $pattr += ['aria-owns' => $id . '_group'];
                }
            } else if ($hasicon) {
                $liattr['class'][] = 'item_with_icon';
                $pattr['class'][] = 'hasicon';
            }
            if ($item->isactive === true) {
                $liattr['class'][] = 'current_branch';
            }
            if (!empty($item->classes) && count($item->classes) > 0) {
                $pattr['class'] = array_merge($pattr['class'], $item->classes);
            }
            $nodetextid = 'label_' . $depth . '_' . $number;

            // class attribute on the div item which only contains the item content
            $pattr['class'][] = 'tree_item';
            if ($isbranch) {
                $pattr['class'][] = 'branch';
            } else {
                $pattr['class'][] = 'leaf';
            }

            $liattr['class'] = join(' ', $liattr['class']);
            $pattr['class'] = join(' ', $pattr['class']);

            if (isset($pattr['aria-expanded']) && $pattr['aria-expanded'] === 'false') {
                $ulattr += ['aria-hidden' => 'true'];
            }

            $content = html_writer::tag('p', $content, $pattr) . $this->navigation_node($item, $ulattr, $depth + 1);
            if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
                $content = html_writer::empty_tag('hr') . $content;
            }
            $liattr['aria-labelledby'] = $nodetextid;
            $content = html_writer::tag('li', $content, $liattr);
            $lis[] = $content;
        }

        if (count($lis)) {
            if (empty($attrs['role'])) {
                $attrs['role'] = 'group';
            }
            return html_writer::tag('ul', implode("\n", $lis), $attrs);
        } else {
            return '';
        }
    }
419310
private function _getTreeNodesIds($nodes)
    {
        $result = [];

        foreach ($nodes as $node) {
            $result[] = $node->id;
        }

        return $result;
    }
1338977
protected function getChildren(NodeBuilder $node)
    {
        return $node
            ->arrayNode('stages')
                ->info("Adding entries to this array will split the remote folder in stages\nExample: /var/www/yourapp/staging and /var/www/yourapp/production")
                ->example(['staging', 'production'])
                ->prototype('scalar')->end()
            ->end()
            ->arrayNode('default')
                ->info("The default stage to execute tasks on when --stage is not provided.\nFalsey means all of them")
                ->prototype('scalar')->end()
                ->beforeNormalization()
                    ->ifString()
                    ->then(function ($default) {
                        return $default ? [$default] : null;
                    })
                ->end()
            ->end();
    }
1334202
public function populateTree($depth = null, $with = null)
    {
        /** @var ActiveRecord[]|static[] $nodes */
        $depths = [$this->owner->getPrimaryKey() => 0];
        $data = $this->getDescendantsIds($depth);
        foreach ($data as $i => $ids) {
            foreach ($ids as $id) {
                $depths[$id] = $i + 1;
            }
        }
        $query = $this->getDescendants($depth);
        if ($with) {
            $query->with($with);
        }
        $nodes = $query
            ->orderBy($this->sortable !== false ? [$this->behavior->sortAttribute => SORT_ASC] : null)
            ->all();

        $relates = [];
        foreach ($nodes as $node) {
            $key = $node->getAttribute($this->parentAttribute);
            if (!isset($relates[$key])) {
                $relates[$key] = [];
            }
            $relates[$key][] = $node;
        }

        $nodes[] = $this->owner;
        foreach ($nodes as $node) {
            $key = $node->getPrimaryKey();
            if (isset($relates[$key])) {
                $node->populateRelation('children', $relates[$key]);
            } elseif ($depth === null || (isset($depths[$node->getPrimaryKey()]) && $depths[$node->getPrimaryKey()] < $depth)) {
                $node->populateRelation('children', []);
            }
        }

        return $this->owner;
    }
591420
public function depthFirst($tree = [], \Closure $callback = null)
    {
        if (!$tree) {
            $tree = $this->tree;
        }
        foreach ($tree as $node) {
            if ($callback) {
                call_user_func_array($callback, ['node' => $node]);
            }
            $children = $node['children'];
            if ($children) {
                $this->depthFirst($children, $callback);
            }
        }
    }
201188
public function sort(TreeNodeInterface $node)
    {
        if (!$node->getTree()->hasChildren($node)) {
            return array();
        }

        $parentId = $node->getId();
        $sortMode = $node->getSortMode();
        $sortDir = $node->getSortDir();

        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder
            ->select('t.id')
            ->from('tree', 't')
            ->where($queryBuilder->expr()->eq('t.parent_id', $parentId));

        switch ($sortMode) {
            case TreeInterface::SORT_MODE_TITLE:
                $queryBuilder
                    ->addSelect('evmf.backend AS sorter')
                    ->leftJoin('t', 'element', 'e', 't.type_id = e.eid')
                    ->leftJoin('e', 'element_version', 'ev', 'e.eid = ev.eid AND e.latest_version = ev.version')
                    ->leftJoin('ev', 'element_version_mapped_field', 'evmf', 'ev.id = evmf.element_version_id AND evmf.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('evmf.backend', $sortDir);
                break;

            case TreeInterface::SORT_MODE_CREATEDATE:
                $queryBuilder
                    ->addSelect('t.modify_time AS sorter')
                    ->orderBy('t.modify_time', $sortDir);
                break;

            case TreeInterface::SORT_MODE_PUBLISHDATE:
                $queryBuilder
                    ->addSelect('to.publish_time AS sorter')
                    ->leftJoin('t', 'tree_online', 'to', 'eto.tree_id = et.id AND eto.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('to.publish_time', $sortDir);
                break;

            case TreeInterface::SORT_MODE_CUSTOMDATE:
                $queryBuilder
                    ->addSelect('evmf.date AS sorter')
                    ->leftJoin('t', 'element', 'e', 't.type_id = e.eid')
                    ->leftJoin('e', 'element_version', 'ev', 'e.eid = ev.eid AND e.latest_version = ev.version')
                    ->leftJoin('ev', 'element_version_mapped_field', 'evmf', 'ev.id = evmf.element_version_id AND evmf.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('evmf.date', $sortDir);
                break;

            default:
                $queryBuilder
                    ->addSelect('t.sort AS sorter')
                    ->orderBy('t.sort', 'ASC');
                break;
        }

        $result = $this->connection->fetchAll($queryBuilder->getSQL());
        $result = array_column($result, 'id');

        return $result;
    }
940788
protected function getStyle(DOMElement $node, $deep = false)
	{
		$style = '';
		if (ElementInspector::preservesWhitespace($node))
		{
			$style .= 'white-space:pre;';
		}
		$style .= $node->getAttribute('style');

		// Add the content of any descendant/child xsl:attribute named "style"
		$query = (($deep) ? './/' : './') . 'xsl:attribute[@name="style"]';
		foreach ($this->xpath->query($query, $node) as $attribute)
		{
			$style .= ';' . $attribute->textContent;
		}

		return $style;
	}
835154
protected function getRelevantNodeText($node)
    {
        if (!$node->hasChildNodes()) {
            return $node->innertext();
        }

        $output = '';
        foreach ($node->nodes as $child) {
            /* @var $child \simple_html_dom_node */
            if (!$child->hasChildNodes()) {
                $output .= $child->outertext();
            } elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
                $output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
            }
        }

        return $output;
    }