-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80bdbda
commit b03f674
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusElasticsearchPlugin\Form\Resolver; | ||
|
||
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface; | ||
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder\SiteWideFacetsQueryBuilderInterface; | ||
use FOS\ElasticaBundle\Finder\PaginatedFinderInterface; | ||
use Pagerfanta\Pagerfanta; | ||
use Symfony\Component\Form\FormEvent; | ||
|
||
final class FacetsResolver implements ProductsFilterFacetResolverInterface | ||
{ | ||
public function __construct( | ||
private SiteWideFacetsQueryBuilderInterface $queryBuilder, | ||
private RegistryInterface $facetRegistry, | ||
private PaginatedFinderInterface $finder | ||
) { | ||
} | ||
|
||
public function resolveFacets(FormEvent $event, string $namePropertyPrefix): Pagerfanta | ||
{ | ||
$query = $this->queryBuilder->getQuery($event); | ||
|
||
foreach ($this->facetRegistry->getFacets() as $facetId => $facet) { | ||
$query->addAggregation($facet->getAggregation()->setName($facetId)); | ||
} | ||
|
||
$query->setSize(0); | ||
|
||
return $this->finder->findPaginated($query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace BitBag\SyliusElasticsearchPlugin\Form\Resolver; | ||
|
||
use Pagerfanta\Pagerfanta; | ||
use Symfony\Component\Form\FormEvent; | ||
|
||
interface FacetsResolverInterface | ||
{ | ||
public function resolveFacets(FormEvent $event): Pagerfanta; | ||
|
||
} |