[export] add a filter and aggregator on accompanying period work: group/filter by handling third party

This commit is contained in:
2023-10-18 13:32:26 +02:00
parent f799fe0649
commit a4edb34668
9 changed files with 397 additions and 125 deletions

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Tests\Export\Aggregator\SocialWorkAggregators\HandlingThirdPartyAggregatorTest;
use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @see HandlingThirdPartyAggregatorTest
*/
final readonly class HandlingThirdPartyAggregator implements AggregatorInterface
{
private const PREFIX = 'acpw_handling3party_agg';
public function __construct(private LabelThirdPartyHelper $labelThirdPartyHelper) {}
public function buildForm(FormBuilderInterface $builder)
{
// no form needed here
}
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, mixed $data)
{
return $this->labelThirdPartyHelper->getLabel($key, $values, 'export.aggregator.course_work.by_handling_third_party.header');
}
public function getQueryKeys($data)
{
return [self::PREFIX.'_h3party'];
}
public function getTitle()
{
return 'export.aggregator.course_work.by_handling_third_party.title';
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$p = self::PREFIX;
$qb
->addSelect("IDENTITY(acpw.handlingThierParty) AS {$p}_h3party")
->addGroupBy("{$p}_h3party");
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final readonly class HandlingThirdPartyFilter implements FilterInterface
{
private const PREFIX = 'acpw_handling_3party_filter';
public function __construct(
private ThirdPartyRender $thirdPartyRender,
) {}
public function getTitle()
{
return 'export.filter.work.by_handling3party.title';
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('handling_3parties', PickThirdpartyDynamicType::class, [
'label' => 'export.filter.work.by_handling3party.pick_3parties',
'multiple' => true,
]);
}
public function getFormDefaultData(): array
{
return ['handling_3parties' => []];
}
public function describeAction($data, $format = 'string')
{
return [
'export.filter.work.by_handling3party.Only 3 parties %3parties%',
[
'%3parties%' => implode(
', ',
array_map(fn (ThirdParty $thirdParty) => $this->thirdPartyRender->renderString($thirdParty, []), $data['handling_3parties'])
),
],
];
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$p = self::PREFIX;
$qb->andWhere("acpw.handlingThierParty IN (:{$p}_3ps)");
$qb->setParameter("{$p}_3ps", $data['handling_3parties']);
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}