mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
82 lines
1.8 KiB
PHP
82 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Export\Aggregator;
|
|
|
|
use Chill\MainBundle\Export\AggregatorInterface;
|
|
use Chill\PersonBundle\Export\Declarations;
|
|
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
|
|
final class GoalAggregator implements AggregatorInterface
|
|
{
|
|
private GoalRepository $goalRepository;
|
|
|
|
public function __construct(GoalRepository $goalRepository)
|
|
{
|
|
$this->goalRepository = $goalRepository;
|
|
}
|
|
|
|
public function addRole()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function alterQuery(QueryBuilder $qb, $data)
|
|
{
|
|
$qb->join('acpw.goals', 'g');
|
|
$qb->addSelect('g.id as goal_aggregator');
|
|
|
|
$groupBy = $qb->getDQLPart('groupBy');
|
|
|
|
if (!empty($groupBy)) {
|
|
$qb->addGroupBy('goal_aggregator');
|
|
} else {
|
|
$qb->groupBy('goal_aggregator');
|
|
}
|
|
|
|
}
|
|
|
|
public function applyOn()
|
|
{
|
|
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
// no form
|
|
}
|
|
|
|
public function getLabels($key, array $values, $data)
|
|
{
|
|
return function ($value): string {
|
|
if ('_header' === $value) {
|
|
return 'Goal Type';
|
|
}
|
|
|
|
$g = $this->goalRepository->find($value);
|
|
|
|
return $g->getTitle()['fr'];
|
|
};
|
|
}
|
|
|
|
public function getQueryKeys($data)
|
|
{
|
|
return ['goal_aggregator'];
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return 'Group social work actions by goal';
|
|
}
|
|
}
|