@param Branch $tree
@param int    $nodeId

@return Branch|null
352548
public function findBranchByNodeId(Branch $tree, $nodeId)
    {
        foreach ($tree->getChildren() as $branch) {
            if ($branch->getNodeId() == $nodeId) {
                return $branch;
            }

            // recursive search:
            $branch = $this->findBranchByNodeId($branch, $nodeId);
            if ($branch) {
                return $branch;
            }
        }

        return null;
    }
243788
public static Node copyTreeToNode(Node tree, Node node)
    {
        DOMResult result = new DOMResult(node);
        if (Utility.copyTreeToResult(tree, result))
            return node.getLastChild();
        else
            return null;    // Failure
    }
1022003
public function deleteNode($nodeId)
    {
        $node = $this->getNode($nodeId);

        $operation = new Operations\Delete($node, $this->config, $this);
        $operation->run();
    }
29461
protected function getNode($nodeId)
    {
        $language = $this->siteManager->getSiteLanguage();
        $siteId = $this->siteManager->getSiteId();
        $node = $this->nodeRepository->findOnePublished($nodeId, $language, $siteId);

        if (!$node instanceof ReadNodeInterface) {
            throw new NodeNotFoundException();
        }

        return $node;
    }
1023699
public function getNodeIndex($nodeId)
    {
        return isset($this->nodeMap[$nodeId]) ? $this->nodeMap[$nodeId]['index'] : null;
    }
364020
private function getBlockModule(Tree $tree, int $block_id): ModuleBlockInterface
    {
        $active_blocks = $this->module_service->findByComponent(ModuleBlockInterface::class, $tree, Auth::user());

        $module_name = DB::table('block')
            ->where('block_id', '=', $block_id)
            ->value('module_name');

        $block = $active_blocks->first(static function (ModuleInterface $module) use ($module_name): bool {
            return $module->name() === $module_name;
        });

        if ($block === null) {
            throw new NotFoundHttpException('Block not found');
        }

        return $block;
    }
1195371
static function getParentNodeId( $nodeID )
    {
        if ( !isset( $nodeID ) )
            return null;
        $db = eZDB::instance();
        $nodeID =(int) $nodeID;
        $parentArr = $db->arrayQuery( "SELECT
                                              parent_node_id
                                       FROM
                                              ezcontentobject_tree
                                       WHERE
                                              node_id = $nodeID");
        return $parentArr[0]['parent_node_id'];
    }
772201
public function getMenu(Tree $tree): ?Menu
    {
        $request    = app(ServerRequestInterface::class);
        $xref       = $request->getQueryParams()['xref'] ?? '';
        $individual = Individual::getInstance($xref, $tree) ?? $tree->significantIndividual(Auth::user());
        $submenus   = $this->module_service->findByComponent(ModuleReportInterface::class, $tree, Auth::user())
            ->map(static function (ModuleReportInterface $module) use ($individual): Menu {
                return $module->getReportMenu($individual);
            });

        if ($submenus->isEmpty()) {
            return null;
        }

        return new Menu(I18N::translate('Reports'), '#', 'menu-report', ['rel' => 'nofollow'], $submenus->all());
    }
928107
public function tree($rootId = NULL){
        if($rootId === NULL){
            $rootId = '__root';
        }

        if(!isset($this->_rootNodeCache[$rootId])){

            $result = $this->getHierarchyByRootIdQuery($rootId)
                           ->get($this->getSelectColumns());

            $this->fillNodeCache($result);

            Helper::toHierarchy($result);

        }

        return $this->_rootNodeCache[$rootId];
    }
127209
public function getNodeById($id, $recursively = false) {
        $found = null;
        if (true === array_key_exists($id, $this->index)) {
            $found = $this->getNodeAt($this->index[$id]);
        }
        if (null === $found && true === $recursively) {
            foreach ($this->nodes as $current) {
                $found = $current->getNodeById($id, $recursively);
                if (null !== $found) {
                    break;
                }
            }
        }
        return $found;
    }
327901
public static function tree_extra_branches($contextid, $element) {

        $params = external_api::validate_parameters(self::tree_extra_branches_parameters(), [
            'contextid' => $contextid,
            'element' => $element,
        ]);

        $context = context_helper::instance_by_id($params['contextid']);

        self::validate_context($context);
        api::check_can_manage_data_registry($context->id);

        switch ($params['element']) {
            case 'course':
                $branches = data_registry_page::get_courses_branch($context);
                break;
            case 'module':
                $branches = data_registry_page::get_modules_branch($context);
                break;
            case 'block':
                $branches = data_registry_page::get_blocks_branch($context);
                break;
            default:
                throw new \moodle_exception('Unsupported element provided.');
        }

        return [
            'branches' => $branches,
            'warnings' => [],
        ];
    }
60567
private function cloneTreeRecursion(int $menuId, TreeBase $item, $parentId = null)
    {
        if ($item->hasChildren()) {

            $previous = null;
            foreach ($item->getChildren() as $child) {

                if ($previous) {
                    $previous = $this->itemStorage->insertAfter($previous, $child->getNodeId(), $child->getTitle(), $child->getDescription());
                } else if ($parentId) {
                    $previous = $this->itemStorage->insertAsChild($parentId, $child->getNodeId(), $child->getTitle(), $child->getDescription());
                } else {
                    $previous = $this->itemStorage->insert($menuId, $child->getNodeId(), $child->getTitle(), $child->getDescription());
                }

                $this->cloneTreeRecursion($menuId, $child, $previous);
            }
        }
    }
108229
function addNode( $nodeID, $isSubtree = true )
    {
        $this->RootNodeIDArray[] = $nodeID;
        $this->NodeIDArray[] = $nodeID;

        if ( $isSubtree )
        {
            $nodeArray = eZContentObjectTreeNode::subTreeByNodeID( array( 'AsObject' => false ), $nodeID );
            foreach( $nodeArray as $node )
            {
                $this->NodeIDArray[] = $node['node_id'];
            }
        }
    }
959874
public static function node($id)
    {
        $id = intval($id);
        if (empty($id)) return null;
        
        if (!static::$caching || empty(static::$_nodes[$id])) {
            $result = static::findOne($id);
            if (static::$caching) {
                static::$_nodes[$id] = $result;
            } else {
                return $result;
            }
        }
        return static::$_nodes[$id];
    }
1238352
public static function getRoot(NodeInterface $parent): ?PhpFileModelInterface
    {
        while ($parent !== null) {
            if ($parent instanceof PhpFileModelInterface) {
                return $parent;
            }
            $parent = $parent->getParentNode();
        }
        return null;
    }
1113163
public function removeNode($nodeId)
    {
        if (isset($this->nodeSet[$nodeId]))
            unset($this->nodeSet[$nodeId]);
        return true;
    }
629976
protected function &getNode(&$node, $key)
    {
        if (is_object($node) && isset($node->$key)) {
            return $node->$key;
        }

        if (is_array($node) && isset($node[$key])) {
            return $node[$key];
        }

        // Special handling of eloquent relations
        if (!$this->isEloquentModel($node)) {
            $result = null;

            return $result;
        }

        if (!method_exists($node, $key)) {
            $result = null;

            return $result;
        }

        $relation = $node->{$key}();

        if (!$this->isEloquentRelation($relation)) {
            $result = null;

            return $result;
        }

        return $relation->getResults();
    }