Features: [export] Show also SocialIssue in the By Social Action aggregator

This commit is contained in:
Julien Fastré 2022-11-10 21:17:48 +01:00
parent 61f44396c5
commit 91e3588e76
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -14,8 +14,11 @@ namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
@ -25,12 +28,20 @@ final class ActionTypeAggregator implements AggregatorInterface
private SocialActionRepository $socialActionRepository;
private SocialIssueRender $socialIssueRender;
private SocialIssueRepository $socialIssueRepository;
public function __construct(
SocialActionRepository $socialActionRepository,
SocialActionRender $actionRender
SocialActionRender $actionRender,
SocialIssueRender $socialIssueRender,
SocialIssueRepository $socialIssueRepository
) {
$this->socialActionRepository = $socialActionRepository;
$this->actionRender = $actionRender;
$this->socialIssueRender = $socialIssueRender;
$this->socialIssueRepository = $socialIssueRepository;
}
public function addRole(): ?string
@ -44,8 +55,15 @@ final class ActionTypeAggregator implements AggregatorInterface
$qb->leftJoin('acpw.socialAction', 'acpwsocialaction');
}
$qb->addSelect('acpwsocialaction.id as action_type_aggregator');
$qb->addGroupBy('action_type_aggregator');
if (!in_array('acpwsocialissue', $qb->getAllAliases(), true)) {
$qb->leftJoin('acpwsocialaction.issue', 'acpwsocialissue');
}
$qb
->addSelect('acpwsocialissue.id as social_action_type_aggregator')
->addSelect('acpwsocialaction.id as action_type_aggregator')
->addGroupBy('action_type_aggregator')
->addGroupBy('social_action_type_aggregator');
}
public function applyOn()
@ -60,24 +78,41 @@ final class ActionTypeAggregator implements AggregatorInterface
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'Social Action Type';
}
switch ($key) {
case 'action_type_aggregator':
return function ($value): string {
if ('_header' === $value) {
return 'Social Action Type';
}
if (null === $value) {
return '';
}
if (null === $value || null === $sa = $this->socialActionRepository->find($value)) {
return '';
}
$sa = $this->socialActionRepository->find($value);
return $this->actionRender->renderString($sa, []);
};
return $this->actionRender->renderString($sa, []);
};
case 'social_action_type_aggregator':
return function ($value): string {
if ('_header' === $value) {
return 'Social Issue';
}
if (null === $value || null === $si = $this->socialIssueRepository->find($value)) {
return '';
}
return $this->socialIssueRender->renderString($si, []);
};
default:
throw new LogicException('this key is not supported: ' . $key);
}
}
public function getQueryKeys($data)
{
return ['action_type_aggregator'];
return ['social_action_type_aggregator', 'action_type_aggregator'];
}
public function getTitle()