/** * @param Eshop $eshop * @param Category $category * @return Category[] */ public function findCategories(Eshop $eshop, Category $category = null) { $query = ['$and' => [[CategoryMeta::ESHOP_ID => $eshop->getId()]]]; if ($category === null) { $query['$and'][] = [CategoryMeta::PATH => ['$size' => 0]]; } else { $query['$and'][] = [CategoryMeta::PATH => $category->getId()]; $query['$and'][] = [CategoryMeta::PATH => ['$size' => count($category->getPath()) + 1]]; } return $this->find($query, [], ["sort" => [CategoryMeta::NAME => 1]]); }