mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-20 21:54:59 +00:00
66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Chill\CalendarBundle\Export\Aggregator;
|
|
|
|
use Chill\CalendarBundle\Export\Declarations;
|
|
use Chill\MainBundle\Export\AggregatorInterface;
|
|
use Closure;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\Security\Core\Role\Role;
|
|
|
|
class MonthYearAggregator implements AggregatorInterface
|
|
{
|
|
|
|
public function getQueryKeys($data): array
|
|
{
|
|
return ['month_year_aggregator'];
|
|
}
|
|
|
|
public function getLabels($key, array $values, $data): Closure
|
|
{
|
|
return function($value): string {
|
|
if ($value === '_header') {
|
|
return 'by month and year';
|
|
}
|
|
|
|
$month = substr($value,0, 2);
|
|
$year = substr($value, 3, 4);
|
|
|
|
return strftime('%B %G', mktime(0, 0, 0, $month, '1', $year));
|
|
};
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
// No form needed
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Group by month and year';
|
|
}
|
|
|
|
public function addRole(): ?Role
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function alterQuery(QueryBuilder $qb, $data)
|
|
{
|
|
$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)) {
|
|
$qb->addGroupBy('month_year_aggregator');
|
|
} else {
|
|
$qb->groupBy('month_year_aggregator');
|
|
}
|
|
}
|
|
|
|
public function applyOn(): string
|
|
{
|
|
return Declarations::CALENDAR_TYPE;
|
|
}
|
|
} |