mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Implement ByStepFilter for AccompanyingPeriodStepHistoryFilters and its tests
A new feature has been added, the ByStepFilter, to the Chill project. The ByStepFilter provides a way to filter data in AccompanyingPeriodStepHistoryFilters based on certain steps. In addition, a new test suite has been introduced to ensure the correct functionality of this filter. The necessary translations for completing this feature have also been included.
This commit is contained in:
parent
44ccfe92b6
commit
97d401b7f6
@ -0,0 +1,87 @@
|
|||||||
|
<?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\AccompanyingPeriodStepHistoryFilters;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
final readonly class ByStepFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TranslatorInterface $translator,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return 'export.filter.step_history.by_step.title';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$steps = [
|
||||||
|
AccompanyingPeriod::STEP_CONFIRMED,
|
||||||
|
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT,
|
||||||
|
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG,
|
||||||
|
AccompanyingPeriod::STEP_CLOSED,
|
||||||
|
];
|
||||||
|
|
||||||
|
$builder->add('steps', ChoiceType::class, [
|
||||||
|
'choices' => array_combine(
|
||||||
|
array_map(static fn (string $step): string => 'accompanying_period.'.$step, $steps),
|
||||||
|
$steps
|
||||||
|
),
|
||||||
|
'label' => 'export.filter.step_history.by_step.pick_steps',
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormDefaultData(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'steps' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'export.filter.step_history.by_step.description',
|
||||||
|
[
|
||||||
|
'%steps%' => implode(', ', array_map(fn (string $step) => $this->translator->trans('accompanying_period.'.$step), $data['steps'])),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRole(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
$qb
|
||||||
|
->andWhere('acpstephistory.step IN (:acpstephistory_by_step_filter_steps)')
|
||||||
|
->setParameter('acpstephistory_by_step_filter_steps', $data['steps']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::ACP_STEP_HISTORY;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
<?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 src\Bundle\ChillPersonBundle\Tests\Export\Filter\AccompanyingPeriodStepHistoryFilters;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodStepHistory;
|
||||||
|
use Chill\PersonBundle\Export\Filter\AccompanyingPeriodStepHistoryFilters\ByStepFilter;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class ByStepFilterTest extends AbstractFilterTest
|
||||||
|
{
|
||||||
|
public function getFilter()
|
||||||
|
{
|
||||||
|
$translator = new class () implements TranslatorInterface {
|
||||||
|
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null)
|
||||||
|
{
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ByStepFilter($translator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormData()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'steps' => [AccompanyingPeriod::STEP_CONFIRMED, AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'steps' => [AccompanyingPeriod::STEP_CLOSED],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQueryBuilders()
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
$qb = $em->createQueryBuilder()
|
||||||
|
->select('COUNT(DISTINCT acpstephistory.id) As export_result')
|
||||||
|
->from(AccompanyingPeriodStepHistory::class, 'acpstephistory')
|
||||||
|
->join('acpstephistory.period', 'acp');
|
||||||
|
|
||||||
|
return [
|
||||||
|
$qb,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -786,6 +786,8 @@ accompanying_period:
|
|||||||
DRAFT: Brouillon
|
DRAFT: Brouillon
|
||||||
CONFIRMED: Confirmé
|
CONFIRMED: Confirmé
|
||||||
CLOSED: Clotûré
|
CLOSED: Clotûré
|
||||||
|
CONFIRMED_INACTIVE_SHORT: Hors file active
|
||||||
|
CONFIRMED_INACTIVE_LONG: Pré-archivé
|
||||||
emergency: Urgent
|
emergency: Urgent
|
||||||
occasional: ponctuel
|
occasional: ponctuel
|
||||||
regular: régulier
|
regular: régulier
|
||||||
@ -1132,7 +1134,10 @@ export:
|
|||||||
Filtered by person's geographical unit (based on address) computed at %datecalc%, only %units%: Filtré par unité géographique (sur base de l'adresse), calculé le %datecalc%, seulement %units%
|
Filtered by person's geographical unit (based on address) computed at %datecalc%, only %units%: Filtré par unité géographique (sur base de l'adresse), calculé le %datecalc%, seulement %units%
|
||||||
|
|
||||||
step_history:
|
step_history:
|
||||||
by_closing_motive
|
by_step:
|
||||||
|
title: Filtrer les changements de statut du parcours par étape
|
||||||
|
pick_steps: Nouvelles étapes
|
||||||
|
description: "Filtré par étape: seulement %steps%"
|
||||||
by_date:
|
by_date:
|
||||||
title: Filtrer les changements de statut du parcours par date
|
title: Filtrer les changements de statut du parcours par date
|
||||||
start_date_label: Changements après le
|
start_date_label: Changements après le
|
||||||
|
Loading…
x
Reference in New Issue
Block a user