StatsResult example

$value = isset($rows[0]) ? $rows[0][$name] : 0;

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

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

                return new CountResult($aggregation->getName()(int) $value);

            case $aggregation instanceof StatsAggregation:
                if (empty($rows)) {
                    return new StatsResult($aggregation->getName(), 0, 0, 0.0, 0.0);
                }

                $min = $rows[0][$name . '.min'] ?? null;
                $max = $rows[0][$name . '.max'] ?? null;
                $avg = isset($rows[0][$name . '.avg']) ? (float) $rows[0][$name . '.avg'] : null;
                $sum = isset($rows[0][$name . '.sum']) ? (float) $rows[0][$name . '.sum'] : null;

                return new StatsResult($aggregation->getName()$min$max$avg$sum);

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

            }
        }

        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:
                
Home | Imprint | This part of the site doesn't use cookies.