mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-23 17:17:43 +00:00
Export: add an ActivityPresenceFilter
This commit is contained in:
parent
4112e59af4
commit
27012d842d
5
.changes/unreleased/Feature-20231109-173500.yaml
Normal file
5
.changes/unreleased/Feature-20231109-173500.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
kind: Feature
|
||||||
|
body: 'Export: add a filter "filter activity by activity presence"'
|
||||||
|
time: 2023-11-09T17:35:00.158055832+01:00
|
||||||
|
custom:
|
||||||
|
Issue: "199"
|
@ -0,0 +1,82 @@
|
|||||||
|
<?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\ActivityBundle\Export\Filter;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityPresence;
|
||||||
|
use Chill\ActivityBundle\Export\Declarations;
|
||||||
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
final readonly class ActivityPresenceFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||||
|
private TranslatorInterface $translator
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return 'export.filter.activity.by_presence.Filter activity by activity presence';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder->add('presences', EntityType::class, [
|
||||||
|
'class' => ActivityPresence::class,
|
||||||
|
'choice_label' => fn (ActivityPresence $presence) => $this->translatableStringHelper->localize($presence->getName())
|
||||||
|
.($presence->isActive() ? '' : ' ('.$this->translator->trans('inactive').')'),
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true,
|
||||||
|
'label' => 'export.filter.activity.by_presence.presences',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormDefaultData(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
$presences = array_map(
|
||||||
|
fn (ActivityPresence $presence) => $this->translatableStringHelper->localize($presence->getName()),
|
||||||
|
$data['presences'] instanceof Collection ? $data['presences']->toArray() : $data['presences']
|
||||||
|
);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'export.filter.activity.by_presence.Filtered by activity presence: only %presences%',
|
||||||
|
['%presences%' => implode(', ', $presences)],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRole(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
$qb
|
||||||
|
->andWhere('activity.attendee IN (:activity_presence_filter_presences)')
|
||||||
|
->setParameter('activity_presence_filter_presences', $data['presences']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::ACTIVITY;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
<?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\ActivityBundle\Tests\Export\Filter;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
|
use Chill\ActivityBundle\Export\Filter\ActivityPresenceFilter;
|
||||||
|
use Chill\ActivityBundle\Repository\ActivityPresenceRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class ActivityPresenceFilterTest extends AbstractFilterTest
|
||||||
|
{
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
$this->translator = self::$container->get(TranslatorInterface::class);
|
||||||
|
$this->translatableStringHelper = self::$container->get(TranslatableStringHelperInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilter()
|
||||||
|
{
|
||||||
|
return new ActivityPresenceFilter($this->translatableStringHelper, $this->translator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormData()
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
$presences = self::$container->get(ActivityPresenceRepositoryInterface::class)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'presences' => $presences,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'presences' => new ArrayCollection($presences),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQueryBuilders()
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
yield $em->createQueryBuilder()
|
||||||
|
->select('count(activity.id)')
|
||||||
|
->from(Activity::class, 'activity');
|
||||||
|
|
||||||
|
self::ensureKernelShutdown();
|
||||||
|
}
|
||||||
|
}
|
@ -135,6 +135,11 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: 'period_having_activity_betw_dates_filter' }
|
- { name: chill.export_filter, alias: 'period_having_activity_betw_dates_filter' }
|
||||||
|
|
||||||
|
Chill\ActivityBundle\Export\Filter\ActivityPresenceFilter:
|
||||||
|
tags:
|
||||||
|
- { name: chill.export_filter, alias: 'activity_presence_filter' }
|
||||||
|
|
||||||
|
|
||||||
## Aggregators
|
## Aggregators
|
||||||
Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityReasonAggregator:
|
Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityReasonAggregator:
|
||||||
tags:
|
tags:
|
||||||
|
@ -389,6 +389,10 @@ export:
|
|||||||
Sent or received: Envoyé ou reçu
|
Sent or received: Envoyé ou reçu
|
||||||
is sent: envoyé
|
is sent: envoyé
|
||||||
is received: reçu
|
is received: reçu
|
||||||
|
by_presence:
|
||||||
|
Filter activity by activity presence: Filtrer les échanges par présence de l'usager
|
||||||
|
presences: Présences
|
||||||
|
'Filtered by activity presence: only %presences%': 'Filtré par présence de l''usager: seulement %presences%'
|
||||||
|
|
||||||
aggregator:
|
aggregator:
|
||||||
acp:
|
acp:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user