Recursive find his parents

@param $nav
@param $parents
@return mixed
439498
private function getUrlParentsRecursive($nav, $parents)
    {
        if ($urlParent = $nav->urlParent) {
            $parents = $this->getUrlParentsRecursive($urlParent, $parents);
        }

        array_push($parents, $nav);

        return $parents;
    }
891784
public function getParentsList()
    {
        /** @var static $root */
        $root  = static::root();
        $items = [
            ['id' => '1', 'title' => 'Item Root'],
        ];
        $nodes = $root->descendants();
        if ($this->exists) {
            $nodes->where('navigation_id', $this->navigation_id)->where('id', '<>', $this->id);
        }

        foreach ($nodes->get() as $node) {
            foreach ($node->getDescendantsAndSelf()->toHierarchy() as $menu) {
                $this->appendMenu($menu, $items);
            }
        }

        return array_pluck($items, 'title', 'id');
    }
812957
public function getSiblings()
    {
        return (new Query())->where(['parent_nav_id' => $this->parentNavId, 'container' => $this->container])->with($this->_with)->lang($this->lang)->all();
    }
1337960
public function findChildrenByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();
        $qb->andWhere($qb->getRootAliases()[0] . '.parent = ' . $this->addNamedParameter('parent', $parent_id, $qb))
            ->orderBy($qb->getRootAliases()[0] . '.position', 'ASC');
        return $qb->getQuery()->getResult();
    }
990168
public function getParent($id)
    {
        if ($parent = $this->qb
            ->from($this->table)
            ->where($this->parentKey, $id)
            ->get(1)) {
            if ($parent->count() == 1) {
                return $parent;
            }
        }

        return false;
    }
651216
private function getChildIds($parentIds)
    {
        $qb = $this->createQueryBuilder('roleHierarchy');

        $qb->select('roleHierarchy.childRoleId')
            ->where($qb->expr()->in( 'roleHierarchy.parentRoleId', $parentIds))
            ->indexBy('roleHierarchy', 'roleHierarchy.childRoleId');

        $childRoleIds =  $qb->getQuery()->getArrayResult();

        return array_keys($childRoleIds);
    }
1257459
private function findRootAlias($alias, $parentAlias)
    {
        $rootAlias = null;

        if (in_array($parentAlias, $this->getRootAliases(), true)) {
            $rootAlias = $parentAlias;
        } elseif (isset($this->joinRootAliases[$parentAlias])) {
            $rootAlias = $this->joinRootAliases[$parentAlias];
        } else {
            // Should never happen with correct joining order. Might be
            // thoughtful to throw exception instead.
            $rootAlias = $this->getRootAlias();
        }

        $this->joinRootAliases[$alias] = $rootAlias;

        return $rootAlias;
    }
128201
public function find($r)
	{
		if (!isset($this->parents[$r])) {
			throw new \InvalidArgumentException('Element "'.$r.'" is not defined.');
		}
		while ($r !== $this->parents[$r]) {
			$this->parents[$r] = $this->parents[$this->parents[$r]]; // Optimize nodes a little on the way to the root
			$r = $this->parents[$r];
		}
		return $r;
	}
844203
public function findParentNodesByChildId($id)
	{
        // To be returned
        $result = array();

        $rl = $this->getRelations();
        $data = $rl[RelationBuilder::TREE_PARAM_ITEMS];

        // If can't find, then return empty array
        if (!isset($data[$id])) {
            return array();
        }

        $current = $data[$id];
        $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

        while (isset($data[$parentId])) {
            $current = $data[$parentId];
            $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

            array_push($result, $current);
        }

        return $result;
    }
380921
public function getParent()
    {
        return (new Query())->where(['nav_id' => $this->parentNavId, 'container' => $this->getContainer()])->with($this->_with)->lang($this->lang)->one();
    }
1333907
public function is_parent_of(array $ids) {
        global $DB;

        list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
        $params['parentid'] = $this->get('id');

        return $DB->count_records_select(self::TABLE, "id $insql AND parentid = :parentid", $params) == count($ids);
    }
267389
public function findChildrenTreeByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();

        $qb = $this->alterQueryBuilderWithParentRoot($qb, $parent_id);

        $qb->orderBy($qb->getRootAliases()[0] . '.lft', 'ASC');

        return $this->getResultFromQueryBuilder($qb);
    }
93415
protected function getChildren($parent, array $folders)
    {
        $children = array();
        foreach ($folders as $key => $folder) {
            if (isset($folder['parent']) && $parent['_id'] == $folder['parent']['$id']) {
                unset($folders[$key]);
                $children[] = array(
                    'folder'   => $folder,
                    'children' => $this->getChildren($folder, $folders));
            }
        }

        return $children;
    }
449951
protected function MoveToFirst( $nav )
	{
		$result = $nav->MoveToFirstChild();

		if ( $result )
		{
			if ( $this->skip( $nav ) )
			{
				return $this->MoveToNext( $nav );
			}
		}

		return $result;
	}
1341888
public function getNodesTree($nodes, $parentId)
    {
        return collect($nodes)->filter(function ($value) use ($parentId) {
            if (isset($value['parent_id'])) {
                if ($value['parent_id'] == $parentId) {
                    return true;
                }

                return false;
            }

            return true;
        })->mapWithKeys(function ($value, $key) use ($nodes) {
            $data = [
                'id'    => (string) $value['id'],
                'label' => $value['label'],
            ];

            if (isset($value['parent_id'])) {
                $children = $this->getNodesTree($nodes, $value['id']);
                if ($children->isNotEmpty()) {
                    $data['children'] = $children;
                }
            }

            return [
                $key => $data,
            ];
        })->values();
    }
278817
public function parent($node = null)
	{
		if ($node)
		{
			$parents = $this->xpath('ancestor-or-self::' . $node);
		}
		else
		{
			$parents = $this->xpath('parent::*');
		}

		return $parents[0];
	}
606815
public function getParentsForBreadcrumbs(
    $entity,
        &$parents = []
    )
    {
        array_push($parents, $entity);
        if ($entity->parent !== null) {
            $this->getParentsForBreadcrumbs($entity->parent, $parents);
        }
        return array_reverse($parents);
    }