RangeAggregation
$aggregation,
QueryBuilder
$query,
EntityDefinition
$definition,
Context
$context ): void
{ $accessor =
$this->queryHelper->
getFieldAccessor($aggregation->
getField(),
$definition,
$definition->
getEntityName(),
$context);
$field =
$this->queryHelper->
getField($aggregation->
getField(),
$definition,
$definition->
getEntityName());
if (!
$field instanceof PriceField && !
$field instanceof FloatField && !
$field instanceof IntField
) { throw new \
RuntimeException(sprintf('Provided field "%s" is not supported in RangeAggregation (supports : PriceField, FloatField, IntField)',
$aggregation->
getField()));
} // build SUM() with range criteria for each range and add it to select
foreach ($aggregation->
getRanges() as $range) { $id =
$range['key'
] ?? (($range['from'
] ?? '*'
) . '-' .
($range['to'
] ?? '*'
));
$sum = '1';
if (isset($range['from'
])) { $sum .=
sprintf(' AND %s >= %f',
$accessor,
$range['from'
]);
} if (isset($range['to'
])) { $sum .=
sprintf(' AND %s < %f',
$accessor,
$range['to'
]);
} $query->
addSelect(sprintf('SUM(%s) as `%s.%s`',
$sum,
$aggregation->
getName(),
$id));
} }