EntityResult example

if (\array_key_exists($aggregation->getName()$result)) {
            $result = $result[$aggregation->getName()];
        }

        $ids = array_column($result['buckets'], 'key');

        if (empty($ids)) {
            $definition = $this->registry->getByEntityName($aggregation->getEntity());
            /** @var EntityCollection<Entity> $class */
            $class = $definition->getCollectionClass();

            return new EntityResult($aggregation->getName()new $class());
        }
        $repository = $this->registry->getRepository($aggregation->getEntity());

        $entities = $repository->search(new Criteria($ids)$context);

        return new EntityResult($aggregation->getName()$entities->getEntities());
    }

    private function hydrateDateHistogram(DateHistogramAggregation $aggregation, array $result, Context $context): ?DateHistogramResult
    {
        if (isset($result[$aggregation->getName()])) {
            
        $grouped = $mergedOptions->groupByPropertyGroups();
        $grouped->sortByPositions();
        $grouped->sortByConfig();

        $aggregations = $result->getAggregations();

        // remove id results to prevent wrong usages         $aggregations->remove('properties');
        $aggregations->remove('configurators');
        $aggregations->remove('options');

        $aggregations->add(new EntityResult('properties', $grouped));
    }

    /** * @param array<string>|null $groupIds */
    private function getPropertyFilter(Request $request, ?array $groupIds = null): Filter
    {
        $ids = $this->getPropertyIds($request);

        $propertyAggregation = new TermsAggregation('properties', 'product.properties.id');

        
/** * @param array<array<string, mixed>> $rows */
    private function hydrateEntityAggregation(
        EntityAggregation $aggregation,
        array $rows,
        Context $context
    ): EntityResult {
        $ids = array_filter(array_column($rows$aggregation->getName()));

        if (empty($ids)) {
            return new EntityResult($aggregation->getName()new EntityCollection());
        }

        $repository = $this->registry->getRepository($aggregation->getEntity());

        $criteria = new Criteria($ids);
        $criteria->setTitle($aggregation->getName() . '-aggregation');

        $entities = $repository->search($criteria$context);

        return new EntityResult($aggregation->getName()$entities->getEntities());
    }

    
Home | Imprint | This part of the site doesn't use cookies.