AvgResult example

return $aggregations;
    }

    private function hydrateAggregation(Aggregation $aggregation, array $result, Context $context): ?AggregationResult
    {
        switch (true) {
            case $aggregation instanceof StatsAggregation:
                return new StatsResult($aggregation->getName()$result['min']$result['max']$result['avg']$result['sum']);

            case $aggregation instanceof AvgAggregation:
                return new AvgResult($aggregation->getName()$result['value']);

            case $aggregation instanceof CountAggregation:
                return new CountResult($aggregation->getName()$result['value']);

            case $aggregation instanceof EntityAggregation:
                return $this->hydrateEntityAggregation($aggregation$result$context);

            case $aggregation instanceof MaxAggregation:
                return new MaxResult($aggregation->getName()$result['value']);

            case $aggregation instanceof MinAggregation:
                
return $this->hydrateTermsAggregation($aggregation$definition$rows$context);

            case $aggregation instanceof FilterAggregation:
                $aggregationStruct = $aggregation->getAggregation();
                \assert($aggregationStruct !== null, 'FilterAggregation always have an aggregation');

                return $this->hydrateResult($aggregationStruct$definition$rows$context);

            case $aggregation instanceof AvgAggregation:
                $value = isset($rows[0]) ? $rows[0][$name] : 0;

                return new AvgResult($aggregation->getName()(float) $value);

            case $aggregation instanceof SumAggregation:
                $value = isset($rows[0]) ? $rows[0][$name] : 0;

                return new SumResult($aggregation->getName()(float) $value);

            case $aggregation instanceof MaxAggregation:
                $value = isset($rows[0]) ? $rows[0][$name] : 0;

                return new MaxResult($aggregation->getName()$value);

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