Gets the parents of the node.
@param integer|null $depth the depth
@return \yii\db\ActiveQuery
495220
public function parents($depth = null) {
        $condition = [
            'and',
            [$this->leftAttribute => ['$lt' => $this->owner->getAttribute($this->leftAttribute)]],
            [$this->rightAttribute => ['$gt' => $this->owner->getAttribute($this->rightAttribute)]],
        ];

        if ($depth !== null) {
            $condition[] = [$this->depthAttribute => ['$gte' => $this->owner->getAttribute($this->depthAttribute) - $depth]];
        }

        $this->applyTreeAttributeCondition($condition);

        return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
    }
441369
public function getDepthToOriginalContainer() {
		$depth = 0;
		$ancestry = $this->getAncestry();
		foreach ($ancestry as $a) {
			$ancestor = get_entity($a);
			if ($ancestor instanceof self) {
				$depth++;
			}
		}
		return $depth;
	}
204055
protected function getHierarchicalChoices($nodes, $depth = 0)
    {
        $choices = array();
        foreach ($nodes as $node) {
            $choices[$node['node']['nodeId']] = $node['node']['name'];
            if (array_key_exists('child', $node)) {
                $choices = array_merge($choices, $this->getHierarchicalChoices($node['child'], $depth + 1));
            }
        }

        return $choices;

    }
754553
public function getParent()
    {
        $parentID = $this->getField("ParentID");
        if ($parentID) {
            return SiteTree::get_by_id(self::class, $parentID);
        }
        return null;
    }
1336516
public function getParents($withSelf = TRUE) {
    $node = $this;
    $parents = array();
    while ($node->getParent() != NULL) {
      $parents[] = $node->getParent();
      $node = $node->getParent();
    }
    if ($withSelf) array_unshift($parents,$this);
    return $parents;
  }
588787
function getChildren() {
        return $this->guild->channels->filter(function ($channel) {
            return ($channel->parentID === $this->id);
        });
    }
859952
public function ChildrenOf($parentRef)
    {
        $parent = SiteTree::get_by_link($parentRef);

        if (!$parent && is_numeric($parentRef)) {
            $parent = DataObject::get_by_id(SiteTree::class, $parentRef);
        }

        if ($parent) {
            return $parent->Children();
        }
        return null;
    }
504920
public function getSubDirs($depth = 0)
	{
		$dirs = [];

		$contents = $this->hasAdapterOrFail()->adapter->listContents($this->getPath(), false);
		foreach ($contents as $item)
		{
			if ($item->isDir())
			{
				$thisDir = new stdClass();
				$thisDir->depth = $depth;
				$thisDir->subdirs = $item->getSubDirs($depth+1);
				$thisDir->name = $item->getDisplayName();
				$thisDir->path = $item->getPath();
				$dirs[] = $thisDir;
			}
		}
		return $dirs;
	}
1150990
public function getById($id, $depth=0, $withParents=false)
    {

        foreach($this->fs as $file){
            if($file->getId() == $id){
                return $file;
            }
        }

    }
295177
public function getChildren()
    {
        return (new Query())->where(['parent_nav_id' => $this->navId, 'container' => $this->getContainer()])->with($this->_with)->lang($this->lang)->all();
    }
1316952
public function getDescendants($parentCategories = null)
    {
        if(empty($parentCategories)) {
            $childCategories = $this->getChildren();
        }
        else {
            $childCategories = Category::find()
                ->where(['in', 'parent_id', ArrayHelper::map($parentCategories, 'id', 'id')])
                ->with('translation')
                ->all();
        }
        if(!empty($childCategories)) {
            return array_merge($childCategories, $this->getDescendants($childCategories));
        }
        return $childCategories;
    }
248496
public function getParent($id)
    {
        /** @var Statement $statement */
        $dataItem     = $this->get($id);
        $queryBuilder = $this->driver->getSelectQueryBuilder();
        $queryBuilder->andWhere($this->driver->getUniqueId() . " = " . $dataItem->getAttribute($this->getParentField()));
        $statement  = $queryBuilder->execute();
        $rows       = array($statement->fetch());
        $hasResults = count($rows) > 0;
        $parent     = null;

        if ($hasResults) {
            $this->driver->prepareResults($rows);
            $parent = $rows[0];
        }

        return $parent;
    }
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');
    }
696899
public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
    {
        if ($parentNodeCategory === null) {
            if ($this->getCurrentCategoryId()) {
                $this->getRootByIds([$this->getCurrentCategoryId()]);
            }
        }

        return parent::getRoot($parentNodeCategory, $recursionLevel);
    }
390246
function child($depth=null){
        if($depth==null)
            return self::where('parent',$this->attributes['id'])->get();
        else
            return self::where('parent',$this->attributes['id'])->where('depth',$depth)->get();
    }
571798
public function populateTree($depth = null, $with = null)
    {
        /** @var ActiveRecord[]|static[] $nodes */
        $query = $this->getDescendants($depth);
        if ($with) {
            $query->with($with);
        }
        $nodes = $query->all();

        $relates = [];
        foreach ($nodes as $node) {
            $path = $node->getParentPath(true);
            $key = array_pop($path);
            if (!isset($relates[$key])) {
                $relates[$key] = [];
            }
            $relates[$key][] = $node;
        }

        $ownerDepth = $this->owner->getAttribute($this->depthAttribute);
        $nodes[] = $this->owner;
        foreach ($nodes as $node) {
            $key = $node->getAttribute($this->itemAttribute);
            if (isset($relates[$key])) {
                $node->populateRelation('children', $relates[$key]);
            } elseif ($depth === null || $ownerDepth + $depth > $node->getAttribute($this->depthAttribute)) {
                $node->populateRelation('children', []);
            }
        }

        return $this->owner;
    }
161041
public function getListParent()
    {
        $parent = session()->get($this->getSessionKey(static::TYPE_PARENT));

        if (null === $parent) {
            return null;
        }

        if (static::PARENT_DISABLE === $parent) {
            return false;
        }

        list($relation, $key) = explode(':', $parent, 2);

        return compact('relation', 'key');
    }