Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree categories added #18

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/Form/Builder/QueryFilterFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function buildChannelsChoices(): array
protected function buildCategoriesChoices(): array
{
$choices = [];
$categories = $this->taxonRepository->findChildren('category');
$categories = $this->taxonRepository->findAll();

/** @var TaxonInterface $category */
foreach ($categories as $category) {
Expand All @@ -192,13 +192,25 @@ protected function buildCategoriesChoices(): array

protected function addCategoryToChoices(array $choices, TaxonInterface $category): array
{
$choices[$category->getName()] = $category->getId();
$name = $category->getName() ?? '';

/** @var TaxonInterface $subcategory */
foreach ($category->getChildren() as $subcategory) {
$choices = $this->addCategoryToChoices($choices, $subcategory);
}
$name = $this->createTaxonName($category, $name);

$choices[$name] = $category->getId();

return $choices;
}

private function createTaxonName(TaxonInterface $category, string $name): string
{
if (null !== $category->getParent()) {
/** @var TaxonInterface $parentCategory */
$parentCategory = $category->getParent();
$parentName = $parentCategory->getName() ?? '';
$name = $parentName . '/' . $name;
$name = $this->createTaxonName($parentCategory, $name);
}

return $name;
}
}