Return all root nodes for the current database table appropiately sorted.

@return Collection
354887
public function roots()
	{
		return $this->model->newQuery()->whereNull( $this->model->getQualifiedParentColumnName() )->orderBy( $this->model->getQualifiedLeftColumnName() )->orderBy( $this->model->getQualifiedRightColumnName() )->orderBy( $this->model->getQualifiedKeyName() )->get();
	}
528429
public function getAncestors()
    {
        if($this->isRoot())
        {
            return array();
        }

        if($this->ancestors === null)
        {
            $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder();
            $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias();

            $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1")
                ->setParameter('lft1', $this->getLeftValue())
                ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1")
                ->setParameter('rgt1', $this->getRightValue())
                ->orderBy("$alias.".$this->getLeftFieldName(), "ASC");
            if($this->hasManyRoots())
            {
                $qb->andWhere("$alias.".$this->getRootFieldName()." = :root")
                    ->setParameter('root', $this->getRootValue());
            }

			$q = $qb->getQuery();
			if ($this->getManager()->getConfiguration()->isQueryHintSet()){
				$q = $this->getManager()->addHintToQuery($q);
			}
			$results = $q->getResult();

            $this->ancestors = array();
            foreach($results as $result)
            {
                $this->ancestors[] = $this->getManager()->wrapNode($result);
            }
        }

        return $this->ancestors;
    }
449820
public function getRootParagraph()
    {
        if ( $this->proxyBase->rootId && (
                null === $this->rootParagraph ||
                $this->rootParagraph->id != $this->proxyBase->rootId
            ) )
        {
            $this->rootParagraph = $this->getMapper()
                                        ->find( $this->proxyBase->rootId );
        }

        return $this->rootParagraph;
    }
484884
public function getDescendants()
    {
        $descendants = $this->children;

        foreach ($this->children as $child) {
            $descendants = $descendants->merge($child->getDescendants());
        }

        return $descendants;
    }
1357894
public function getLevel()
    {
        if ($this->_level !== null) {
            return $this->_level;
        }

        if ($this->isRoot()) {
            $this->_level = -1;
            return $this->_level;
        }

        $parents = array($this);
        $node = $this;

        while ($parent = $node->getParent()){
            if (!$parent->isRoot()) {
                $parents[] = $parent;
            }
            $node = $parent;
        }

        $this->_level = count($parents);

        return $this->_level;
    }
1286433
public function getSiblings() {
        $parent = $this->getParent();
        if (is_null($parent)) {
            // This is the root node.
            return [];
        }

        $children = $parent->getChildren();
        $index = array_search($this, $children);
        unset($children[$index]);
        return $children;
    }
979957
public function findRootNodes()
    {
        $possibleRoots = new SplObjectStorage();
        foreach ($this->nodes as $node) {
            $possibleRoots[$node] = true;
        }

        // Detect all nodes which couldn't be root
        foreach ($this->dependencies as $node) {
            $nodeDependencies = $this->dependencies[$node];
            foreach ($nodeDependencies as $dependency) {
                $possibleRoots[$dependency] = false;
            }
        }

        // Create array which contains all roots
        $rootNodes = array();
        foreach ($possibleRoots as $node) {
            if ($possibleRoots[$node]) {
                $rootNodes[] = $node;
            }
        }

        return $rootNodes;
    }
1157102
public function getTreeNodeStates()
    {
        if (!isset($this->nodeStates)) {
            $environment      = $this->getEnvironment();
            $sessionStorage   = $environment->getSessionStorage();
            $this->nodeStates = new TreeNodeStates(
                $sessionStorage->get($this->getToggleId()),
                $this->determineParentsOfValues()
            );

            // Maybe it is not the best location to do this here.
            if ('all' === $environment->getInputProvider()->getParameter('ptg')) {
                // Save in session and reload.
                $sessionStorage->set(
                    $this->getToggleId(),
                    $this->nodeStates->setAllOpen($this->nodeStates->isAllOpen())->getStates()
                );

                $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
            }
        }

        return $this->nodeStates;
    }
769056
public function getRoot()
    {
        if (!$this->root) {
            $this->root = $this->active->getContext()->getCurrentSiteNode();
        }

        return $this->root;
    }
47933
protected function getCollection(): Collection
    {
        $conn = $this->connPool->getConnection();
        $database = $conn->defaultDatabase;
        $collection = $this->schema->collection;

        return $conn->getRawConnection()->$database->$collection;
    }
479589
public function getRoot()
    {
        if ( $this->owner->{$this->parentIdField} ) {
            return Yii::$app->db->cache(function(){
                return call_user_func("$this->ownerClassName::findOne", current($this->getParentsId()));
            }, null, $this->getTagDependency());
        } else {
            return $this->owner;
        }
    }
643212
public function get_ancestors() {
        global $DB;
        $ancestors = array();
        $ancestorsids = explode('/', trim($this->get('path'), '/'));
        // Drop the root item from the array /0/.
        array_shift($ancestorsids);
        if (!empty($ancestorsids)) {
            list($insql, $params) = $DB->get_in_or_equal($ancestorsids, SQL_PARAMS_NAMED);
            $ancestors = self::get_records_select("id $insql", $params);
        }
        return $ancestors;
    }
1351018
public function allNodes()
    {
        $orderColumn = DB::getQueryGrammar()->wrap($this->orderColumn);
        $byOrder = $orderColumn.' = 0,'.$orderColumn;

        $self = new static();

        if ($this->queryCallback instanceof \Closure) {
            $self = call_user_func($this->queryCallback, $self);
        }

        return $self->orderByRaw($byOrder)->get()->toArray();
    }
23935
public function getRootSteps()
    {
        $roots = [];

        if (!empty($this->steps)) {
            foreach ($this->steps as $step) {
                if (null === $step->getParent()) {
                    // Root step found
                    $roots[] = $step;
                }
            }
        }

        return $roots;
    }
588097
public function root()
    {
        $category = $this->createModel();

        $category = $category->whereExists(function($query)
        {
            $query->select(\DB::raw(1))
                  ->from('category_hierarchy')
                  ->whereRaw(DB::getTablePrefix().'categories.id = '.DB::getTablePrefix().'category_hierarchy.category_id')
                  ->where('category_hierarchy.category_parent_id', 0);
        });

        return $category;
    }
28659
public function getCategoryCollection()
    {
        $collection = parent::getCategoryCollection();

        // Previous call to $this->getRootByIds() will exclude all other category trees but keep their root.
        // Now we exclude all root categories except root associated to the current one.
        if ($this->getCurrentCategory()) {
            $rootPath      = array_slice($this->getCurrentCategory()->getPathIds(), 0, 2);
            $pathCondition = implode('/', $rootPath) . '%';
            $collection->addFieldToFilter('path', ['like' => $pathCondition]);

            // We also exclude current category, to prevent inception.
            $collection->addFieldToFilter('entity_id', ['neq' => $this->getCurrentCategory()->getId()]);

            // Overwrite collection already set in parent call.
            $this->setData('category_collection', $collection);
        }

        return $collection;
    }
910682
public function getRoot()
    {
        $path = $this->owner->getPath();
        $path = array_shift($path);
        $query = $this->owner->find();
        /** @var \yii\db\ActiveQuery $query */
        $query
            ->andWhere([$this->keyColumn => $path])
            ->limit(1);
        $query->multiple = false;
        return $query;
    }