Partage d'export enregistré et génération asynchrone des exports

This commit is contained in:
2025-07-08 13:53:25 +00:00
parent c4cc0baa8e
commit 8bc16dadb0
447 changed files with 14134 additions and 3854 deletions

View File

@@ -26,15 +26,21 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\ReportBundle\Entity\Report;
use Chill\ReportBundle\Security\Authorization\ReportVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @template-implements ListInterface<QueryBuilder, array{fields: list<string>, address_date: \DateTime}>
*/
class ReportList implements ExportElementValidatedInterface, ListInterface
{
use \Chill\MainBundle\Export\ExportDataNormalizerTrait;
protected array $fields = [
'person_id', 'person_firstName', 'person_lastName', 'person_birthdate',
'person_placeOfBirth', 'person_gender', 'person_memo', 'person_email', 'person_phonenumber',
@@ -97,6 +103,21 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
]);
}
public function getNormalizationVersion(): int
{
return 1;
}
public function normalizeFormData(array $formData): array
{
return ['fields' => $formData['fields'], 'address_date' => $this->normalizeDate($formData['address_date'])];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return ['fields' => $formData['fields'], 'address_date' => $this->denormalizeDate($formData['address_date'])];
}
public function getFormDefaultData(): array
{
return ['address_date' => new \DateTime()];
@@ -253,7 +274,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
}
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
$fields = [];
@@ -267,12 +288,12 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
return [...$fields, ...\array_keys($this->slugs)];
}
public function getResult($query, $data)
public function getResult(QueryBuilder|NativeQuery $query, $data, \Chill\MainBundle\Export\ExportGenerationContext $context): array
{
return $query->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
public function getTitle()
public function getTitle(): string|\Symfony\Contracts\Translation\TranslatableInterface
{
return $this->translator->trans(
"List for report '%type%'",
@@ -282,12 +303,12 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
);
}
public function getType()
public function getType(): string
{
return 'report';
}
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
public function initiateQuery(array $requiredModifiers, array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): QueryBuilder
{
$centers = array_map(static fn ($el) => $el['center'], $acl);
@@ -413,7 +434,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
return [Declarations::PERSON_TYPE, 'report'];
}
public function validateForm($data, ExecutionContextInterface $context)
public function validateForm($data, ExecutionContextInterface $context): void
{
// get the field starting with address_
$addressFields = array_filter(

View File

@@ -53,7 +53,7 @@ class ReportListProvider implements ExportElementsProviderInterface
$this->customFieldProvider = $customFieldProvider;
}
public function getExportElements()
public function getExportElements(): iterable
{
$groups = $this->em->getRepository(CustomFieldsGroup::class)
->findBy(['entity' => Report::class]);

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Export\Filter;
use Chill\MainBundle\Export\ExportGenerationContext;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
@@ -26,7 +27,7 @@ class ReportDateFilter implements FilterInterface
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data, ExportGenerationContext $exportGenerationContext): void
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->between(
@@ -52,12 +53,12 @@ class ReportDateFilter implements FilterInterface
);
}
public function applyOn()
public function applyOn(): string
{
return 'report';
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder): void
{
$builder->add('date_from', PickRollingDateType::class, [
'label' => 'Report is after this date',
@@ -68,12 +69,27 @@ class ReportDateFilter implements FilterInterface
]);
}
public function getNormalizationVersion(): int
{
return 1;
}
public function normalizeFormData(array $formData): array
{
return ['date_from' => $formData['date_from']->normalize(), 'date_to' => $formData['date_to']->normalize()];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return ['date_from' => RollingDate::fromNormalized($formData['date_from']), 'date_to' => RollingDate::fromNormalized($formData['date_to'])];
}
public function getFormDefaultData(): array
{
return ['date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'date_to' => new RollingDate(RollingDate::T_TODAY)];
}
public function describeAction($data, $format = 'string')
public function describeAction($data, ExportGenerationContext $context): string|\Symfony\Contracts\Translation\TranslatableInterface|array
{
return ['Filtered by report\'s date: '
.'between %date_from% and %date_to%', [
@@ -82,7 +98,7 @@ class ReportDateFilter implements FilterInterface
], ];
}
public function getTitle()
public function getTitle(): string|\Symfony\Contracts\Translation\TranslatableInterface
{
return 'Filter by report\'s date';
}