Gets the leaf nodes.
@return \yii\db\ActiveQuery
187525
public function leaves()
    {
        /** @var \yii\db\ActiveQuery $this */
        $class = $this->modelClass;
        $model = new $class;
        if ($model->hasProperty('leftAttribute')) {	///for nested sets
	        $db = $model->getDb();
	        return $this->andWhere([$model->rightAttribute => new Expression($db->quoteColumnName($model->leftAttribute) . '+ 1')]);
        } elseif ($model->hasProperty('parentAttribute')) {	///for adjacency list
        	///@see https://github.com/paulzi/yii2-adjacency-list/blob/master/AdjacencyListBehavior.php#L240
        	return $this->joinWith(['children' => function ($query) {
                /** @var \yii\db\ActiveQuery $query */
                $modelClass = $query->modelClass;
                $query->from($modelClass::tableName() . ' children');
            }])->andWhere(["children.[[{$model->parentAttribute}]]" => null]);
        } else {
        	throw new InvalidConfigException('The "model" property `leftAttribute` or `parentAttribute` must be set.');
        }
    }
338202
public static function getAll(): array
    {
        if (empty(self::$trees)) {
            self::$trees = self::all()->all();
        }

        return self::$trees;
    }
712642
public function getChildEdges()
    {
        $edges        = [];
        $hasChildren = false;

        foreach ($this->fields as $v) {
            if ($v instanceof GraphEdge) {
                $hasChildren = true;

                $children = $v->getChildEdges();
                foreach ($children as $childEdges) {
                    $edges[] = array_merge([$this->name], $childEdges);
                }
            }
        }

        // Means this is the final node (no further sub edges)
        if (!$hasChildren) {
            $edges[] = [$this->name];
        }

        return $edges;
    }
93594
public function getNodes()
    {
        $nodes = [];
        foreach ($this->applications as $application) {
            foreach ($application->getNodes() as $node) {
                $nodes[$node->getName()] = $node;
            }
        }

        return $nodes;
    }
1244688
public function getTree()
    {
        $nodes = [];
        foreach ($this->nodes[$this->_config['rootid']]->getDescendants() as $subnode) {
            $nodes[] = $subnode;
        }
        return $nodes;
    }
1099089
public function leaves() {
        $condition = [
            'and',
            [$this->leftAttribute => ['$gt' => $this->owner->getAttribute($this->leftAttribute)]],
            [$this->rightAttribute => ['$lt' => $this->owner->getAttribute($this->rightAttribute)]],
            ['$where' => "this.{$this->rightAttribute} = this.{$this->leftAttribute} + 1"]
        ];

        $this->applyTreeAttributeCondition($condition);

        return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
    }
1094750
public function tree()
    {
        $this->tree = true;

        $this->unsignedInteger('parentId')->nullable()->fillable();
        $this->integer('index')->fillable()->required();

        //$this->string('text', 200)->fillable()->required();

        $this->boolean('leaf')->fillable()->required();

        //Composite Unique Key ParentId-Index
        //$this->unique(array('parentId', 'index'));

        $this->foreign('parentId')
            ->references('id')
            ->on($this->table)
            ->onDelete('cascade');

        return $this;
    }
561086
public function roots()
    {
        $model = new $this->owner->modelClass();

        $this->owner
            ->andWhere([$model->leftAttribute => 1])
            ->addOrderBy([$model->primaryKey()[0] => SORT_ASC]);

        return $this->owner;
    }
356163
protected function getRootTreeData()
    {
        return [
            'id' => '0',
            'parent' => '#',
            'text' => $this->treeLabels['top_level_tags'],
            'children' => true,
            'state' => [
                'opened' => true,
            ],
            'a_attr' => [
                'href' => $this->treeLinks['top_level_tags'],
                'rel' => '0',
            ],
            'data' => [
                'context_menu' => [
                    [
                        'name' => 'add_child',
                        'url' => str_replace(':parentId', 0, $this->treeLinks['add_child']),
                        'text' => $this->treeLabels['add_child'],
                    ],
                ],
            ],
        ];
    }
358077
protected function getQuery()
    {
        $query = new Query();

        if ($this->valid()) {
            $query->setQuery(new GtNode($this->dataStore->getIdentifier(), $this->key()));
        }

        $query->setLimit(new LimitNode($this->limit));
        $query->setSort(new SortNode([$this->dataStore->getIdentifier() => SortNode::SORT_ASC]));

        return $query;
    }
952500
public function getNodeType()
    {
        $bag = hierarchy_bag('nodetype');

        if ($this->relationLoaded('nodeType'))
        {
            $nodeType = $this->getRelation('nodeType');
        } elseif ($nodeType = $bag->getNodeType($this->getNodeTypeKey()))
        {
            $this->setRelation('nodeType', $nodeType);
        } else
        {
            $nodeType = $this->load('nodeType')->getRelation('nodeType');
        }

        if ($nodeType)
        {
            $bag->addNodeType($nodeType);

            return $nodeType;
        }

        return null;
    }
856523
public function getTreeNodeParentArray()
    {
        $db = Database::connection();
        $nodeArray = [];
        $currentNodeParentID = $this->getTreeNodeParentID();
        if ($currentNodeParentID > 0) {
            while (is_numeric($currentNodeParentID) && $currentNodeParentID > 0 && $currentNodeParentID) {
                $row = $db->fetchAssoc('select treeNodeID, treeNodeParentID from TreeNodes where treeNodeID = ?', [$currentNodeParentID]);
                if ($row && $row['treeNodeID']) {
                    $nodeArray[] = self::getByID($row['treeNodeID']);
                }

                $currentNodeParentID = $row['treeNodeParentID']; // moving up the tree until we hit 1
            }
        }

        return $nodeArray;
    }
626484
public function getActiveList()
    {
        return $this->find()
            ->select(['id', 'first_name', 'last_name'])
            ->where([sprintf('%s.active', $this->getAlias()) => true])
            ->order(['username' => 'ASC'])
            ->formatResults(function (ResultSet $results) {
                return $results->indexBy('id')->map(function (User $user) {
                    return $user->first_name . ' ' . $user->last_name;
                });
            })
            ->cache(sprintf('active_%s_list', $this->getTable()), $this->getCacheName());
    }
481351
public function getFullTree()
    {
        $select = $this->getSql()->select();
        $select->from(['child' => $this->getTable()])
            ->columns([
                Select::SQL_STAR,
                'depth' => new Expression('(COUNT(parent.' . $this->getPrimaryKey() . ') - 1)')
            ])
            ->join(
                ['parent' => $this->getTable()],
                'child.' . self::COLUMN_LEFT . ' BETWEEN parent.' . self::COLUMN_LEFT . ' AND parent.' . self::COLUMN_RIGHT,
                [],
                Select::JOIN_INNER
            )
            ->group('child.' . $this->getPrimaryKey())
            ->order('child.' . self::COLUMN_LEFT);

        return $select;
    }
736745
public function actionTree()
    {
        $tree = DpAdminMenu::getAccessTreeByParentId($this->identity->is_super, $this->menuIdList, null, [
            'is_hide' => 0,
        ]);

        return [
            'children' => $tree,
        ];
    }
1356576
public function getCurrentRoot()
    {
        if (null !== $this->getCurrentPage()) {
            return $this->getCurrentPage()->getRoot();
        } elseif (null === $this->getCurrentSite()) {
            return;
        } else {
            return $this->application->getEntityManager()
                ->getRepository('BackBee\NestedNode\Page')
                ->getRoot($this->getCurrentSite())
            ;
        }
    }
911673
public function getRoot() : Node {
        $node = $this;
        while ($node->parent !== null) {
            $node = $node->parent;
        }
        return $node;
    }