Finds all parents from top one to nearest.
@param  Category $category
@return Category[]|null
190747
public function getParents ($category)
		{
			if ($category instanceof $this->_modelClass)
			{
				$parents = [];
				foreach ($this->_data as $item)
					if ($category->lft > $item->lft and $category->rgt < $item->rgt)
						$parents[] = $item;

				return $parents;
			}

			return null;
		}
555036
private function getCategoryBreadcrumb(\Magento\Catalog\Model\Category $category)
    {
        $path    = $category->getPath();
        $rawPath = explode('/', $path);

        // First occurence is root category (1), second is root category of store.
        $rawPath = array_slice($rawPath, 2);

        // Last occurence is the category displayed.
        array_pop($rawPath);

        $breadcrumb = [];
        foreach ($rawPath as $categoryId) {
            $breadcrumb[] = html_entity_decode($this->getCategoryNameById($categoryId, $category->getStoreId()));
        }

        return $breadcrumb;
    }
625215
public function findNextSubcategory($subcategory)
    {
        $qb = $this->getQueryBuilder()
            ->select('c')
            ->where('c.id > :id')
            ->andWhere('c.parentCategory = :parentCategory')
            ->orderBy('c.id', 'asc')
            ->setMaxResults(1)
            ->setParameter('id', $subcategory->getId())
            ->setParameter('parentCategory', $subcategory->getParentCategory());

        // get the first subcategory when there is no next
        if (0 == count($qb->getQuery()->getResult())) {
            $qb->where('c.id < :id')
                ->andWhere('c.parentCategory = :parentCategory')
                ->setParameter('id', $subcategory->getId())
                ->setParameter('parentCategory', $subcategory->getParentCategory());

            if (0 == count($qb->getQuery()->getResult())) {
                return null;
            }
        }

        return $qb->getQuery()
            ->getSingleResult();
    }
556652
public function getChildrenCategories(
        CategoryInterface $parentCategory,
        $recursively = false
    ) {
        $categories = $this
            ->createQueryBuilder('c')
            ->where('c.parent = :parent_category')
            ->setParameters([
                'parent_category' => $parentCategory,
            ])
            ->getQuery()
            ->getResult();

        if ($recursively && !empty($categories)) {
            foreach ($categories as $category) {
                $categories = array_merge(
                    $categories,
                    $this->getChildrenCategories($category, true)
                );
            }
        }

        return $categories;
    }
1323253
public function findManyByCategory(ICategory $category, $limit = null)
    {
        $related = $this->modelClassInstance->active()->where('category_id', $category->getId())->paginate($limit);

        return $related;
    }
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;
    }
1237070
public function getSubCategories($category)
    {
        $ds = DIRECTORY_SEPARATOR;
        $categoryPath = str_replace('/', $ds, $category);

        $basePath = app_path().$ds.'lablog'.$ds;

        $path = $basePath.$categoryPath;

        if (!$this->exists($category)) {
            return array();
        }

        $categories = $this->fs->directories($path);

        $allCategories = array();

        foreach ($categories as $category) {
            $cat = str_replace($basePath, '', $category);
            $allCategories[] = $this->getCategory($cat);
        }

        return $allCategories;
    }
429732
private function _searchChildren(array $categories, $parentCategoryId = null)
    {
        //iteracja po kategoriach
        foreach ($categories as $id => $category) {
            if ($id == $parentCategoryId) {
                return $category['children'];
            }
            if ([] !== $child = $this->_searchChildren($category['children'], $parentCategoryId)) {
                return $child;
            }
        }
        return [];
    }
1111963
public function getBranchByCategory(Category $category, $lang = null)
    {
        $this->initNodeVersions();

        $lang = $lang ?: $this->currentLocale->getCurrentLocale();

        $matches = function (Branch $branch) use ($category, $lang) {
            return $category->getNodeId() === $branch->getNodeId() && $lang === $branch->getLang();
        };

        return array_reduce($this->branches, function (Branch $result = null, Branch $branch) use ($matches) {
            return  $matches($branch) ? $branch : $result;
        });
    }
1359886
public function getPostsByCategory($category)
    {
        if (false === array_key_exists($category, $this->categoryIndex)) {
            return [];
        }

        $postNames = $this->categoryIndex[$category];

        return $this->getPostsByName($postNames);
    }
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;
    }
687910
protected function find_categories_after($category) {
        $return = array();
        $categoryarray = $this->categories;
        foreach ($categoryarray as $categoryelement) {
            if ($categoryelement->after == $category->name) {
                // Find all categories that comes after this category as well.
                $categoryelement->sort_nodes();
                $return = array_merge($return, array($categoryelement->name => $categoryelement),
                        $this->find_categories_after($categoryelement));
            }
        }
        return $return;
    }
341501
public function getTree($categories = [])
    {
        /** @var $category Category */
        foreach ($this as $category) {
            $categories[] = $category;
            $categories = $category->getChildren()->notDeleted()->findAll()->getTree($categories);
        }

        return $categories;
    }
407166
public function all(array $categories = array())
	{
		$handlers = array();

		foreach ($this->handlers as $handler)
		{
			$handlerCategories = $this->handlers->getInfo();
			if (array() === $categories || array() !== array_intersect($handlerCategories, $categories))
			{
				$handlers[] = $handler;
			}
		}

		return $handlers;
	}
163367
protected function initParentCategory()
    {
        if (!array_key_exists('parent_id', $this->arImportData)) {
            return;
        }

        $iParentID = array_get($this->arImportData, 'parent_id');
        array_forget($this->arImportData, 'parent_id');
        if (empty($iParentID)) {
            $this->obParentCategory = false;

            return;
        }

        //Find parent category
        $this->obParentCategory = Category::getByExternalID($iParentID)->first();
    }
794614
def root_parent(self, category=None):
        
        return next(filter(lambda c: c.is_root, self.hierarchy()))
956091
public static function getRootCategories()
    {
        $app = App::getInstance();

        $sql = $app['safesql']->query(
            "SELECT
				`id`
			FROM `category`
			WHERE hidden = 0
			AND id > 0
			AND parent IS NULL
			AND deleted = 0
			ORDER BY `order` ASC",
            array());
        $results = $app['db']->get_results($sql);
        $cats = array();

        if (!is_null($results)) {
            foreach ($results as $cat) {
                $cats[] = new Category($cat->id);
            }
        }
        return $cats;
    }