month year aggregator working

This commit is contained in:
2022-08-25 13:08:24 +02:00
parent f3ceee7485
commit cf642d2783
3 changed files with 12 additions and 12 deletions

View File

@@ -19,15 +19,16 @@ class MonthYearAggregator implements AggregatorInterface
public function getLabels($key, array $values, $data): Closure
{
return function($value): string {
if ($value === '_header') {
return 'by month and year';
}
dump($values);
$month = substr($value,0, 2);
$year = substr($value, 3, 4);
$labels = [];
return static function (string $value) use ($labels): string {
return $labels[$value];
return strftime('%B %G', mktime(0, 0, 0, $month, '1', $year));
};
}
public function buildForm(FormBuilderInterface $builder)
@@ -47,10 +48,8 @@ class MonthYearAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('MONTH(:startDate), YEAR(:startDate) as month_year_aggregator');
// $qb->addSelect('YEAR(cal.startDate) as year_aggregator');
$qb->setParameter('startDate', 'cal.startDate');
$qb->addSelect("to_char(cal.startDate, 'MM-YYYY') AS month_year_aggregator");
// $qb->addSelect("extract(month from age(cal.startDate, cal.endDate)) AS month_aggregator");
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {