get root categories => parent=0
@return Collection
182001
public function getRootCategories ()
    {
        return self::where('parent' , 0)
            ->where('slug' , '<>' , config('Categories::category.default_category.slug'))
            ->orderby('id' , 'desc')
            ->where('model_type' , $this->modelType)
            ->get();
    }
1214916
public function getAllCategoryTreesAsArray()
    {
        $rootIds = $this->getAllRootIds();

        $trees = array();
        foreach ($rootIds as $rootId) {
            $trees[$rootId] = $this->getCategoryTreeAsArray($rootId);
        }

        return $trees;
    }
341501
public function getTree($categories = [])
    {
        /** @var $category Category */
        foreach ($this as $category) {
            $categories[] = $category;
            $categories = $category->getChildren()->notDeleted()->findAll()->getTree($categories);
        }

        return $categories;
    }
609981
public function getRoot($categoryId)
    {
        $category = CategoryQuery::create()->findPk($categoryId);

        if (0 !== $category->getParent()) {
            $parentCategory = CategoryQuery::create()->findPk($category->getParent());

            if (null !== $parentCategory) {
                $categoryId = $this->getRoot($parentCategory->getId());
            }
        }

        return $categoryId;
    }
671039
public function getRootNodes()
    {
        $root = [];

        foreach ($this->nodes as $appName => $nodes) {
            foreach ($nodes as $name => $migration) {
                // get the nodes  parent
                $parents = $this->getNodeFamilyTree($appName, $name)->parent;

                // if no parent exist this must be the first migration aka
                // adam/eve which ever tickles your fancy
                if (empty($parents)) {
                    $root[$appName] = $name;
                }
            }
        }

        return $root;
    }
283411
public function getAllChildren() {
    // Define as array.
    $options = [];

    // Fetch main categories.
    foreach (array_keys($this->getCategories()) as $category) {
      $options = array_merge($options, $this->getChildren($category));
    }
    // Return array.
    return $options;
  }
1244688
public function getTree()
    {
        $nodes = [];
        foreach ($this->nodes[$this->_config['rootid']]->getDescendants() as $subnode) {
            $nodes[] = $subnode;
        }
        return $nodes;
    }
794614
def root_parent(self, category=None):
        
        return next(filter(lambda c: c.is_root, self.hierarchy()))
546869
public function getRootCategoriesSplitByContexts($loadChildren = true)
    {
        $rootCategories = $this->getAllRootCategories($loadChildren);

        $splitCategories = [];

        foreach ($rootCategories as $category) {
            $splitCategories[$category->getContext()->getId()][] = $category;
        }

        return $splitCategories;
    }
393063
public function rootNodes()
    {
        $query = $this->model->newQuery()->whereNull($this->parentIdKey);

        $this->callBeforeListeners('rootNodes', [$query]);

        $nodes = $query->get()->all();

        $this->callAfterListeners('rootNodes', [$nodes]);

        return $nodes;
    }
1206806
protected function getListCategory()
    {
        $id = $this->getParam(0);

        if (!isset($id)) {
            return $this->category->getList(array('limit' => $this->getLimit()));
        }

        if (!is_numeric($id)) {
            $this->errorAndExit($this->text('Invalid argument'));
        }

        if ($this->getParam('group')) {
            return $this->category->getList(array('category_group_id' => $id, 'limit' => $this->getLimit()));
        }

        if ($this->getParam('parent')) {
            return $this->category->getList(array('parent_id' => $id, 'limit' => $this->getLimit()));
        }

        $result = $this->category->get($id);

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        return array($result);
    }
1213025
protected function getRootDirectory()
    {
        if ($this->addon) {
            $directories = $this->addon->config('addon.directories');

            if (! $directories) {
                $directories = ['classes'];
            }

            return $this->addon->path($directories[0]);
        }
        else {
            return parent::getRootDirectory();
        }
    }
652501
public function getParentsList()
    {
        /** @var static $root */
        $root  = static::root();
        $items = [
            ['id' => '1', 'title' => 'Item Root'],
        ];

        if ($this->exists) {
            $parents = $this->ancestors()
                            ->withoutRoot()
                            ->orWhere(function ($query) {
                                $query->where('depth', $this->depth)->where('id', '<>', $this->id);
                            })
                            ->get();
            foreach ($parents as $parent) {
                $items[] = [
                    'title' => $parent->present()->indentedTitle(),
                    'id'    => $parent->id,
                ];
            }
        } else {
            foreach ($root->getDescendants() as $parent) {
                $items[] = [
                    'title' => $parent->present()->indentedTitle(),
                    'id'    => $parent->id,
                ];
            }
        }

        return array_pluck($items, 'title', 'id');
    }
1062735
public function get_parent_category() {
        if ($this->is_category_item() or $this->is_course_item()) {
            return $this->get_item_category();

        } else {
            return grade_category::fetch(array('id'=>$this->categoryid));
        }
    }
94904
private function getRootNodes()
    {
        $output = array();
        foreach( $this->nodes as $node )
            if (! $node->parentCount() )
                $output[] = $node;
        return $output;
    }
627069
public function parentStack() {
        $p=$this->owner;
        
        while($p) {
            $stack[]=$p;
            if($p->FolderID && $p->FolderID>0) {
                $folder=$p->Folder();
                if(!empty($folder) && $folder!==false && $folder->ID!=0) {
                    $p=$folder;
                }
            }else {
                $p=$p->LanguageID ? $p->Language() : null;
            }
        }
        
        return $stack;
    }
705135
public function getPlantCategories()
    {
        if (!$this->plant_categories && $this->getSpecies()) {
            return $this->getSpecies()->getPlantCategories();
        }

        return $this->plant_categories;
    }