mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Partage d'export enregistré et génération asynchrone des exports
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
@@ -20,6 +21,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
class BirthdateFilter implements ExportElementValidatedInterface, FilterInterface
|
||||
{
|
||||
use \Chill\MainBundle\Export\ExportDataNormalizerTrait;
|
||||
// add specific role for this filter
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -28,7 +30,7 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
}
|
||||
|
||||
// here, we alter the query created by Export
|
||||
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
|
||||
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data, \Chill\MainBundle\Export\ExportGenerationContext $exportGenerationContext): void
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
// we create the clause here
|
||||
@@ -52,13 +54,13 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
}
|
||||
|
||||
// we give information on which type of export this filter applies
|
||||
public function applyOn()
|
||||
public function applyOn(): string
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
|
||||
// we build a form to collect some parameters from the users
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
|
||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder): void
|
||||
{
|
||||
$builder->add('date_from', DateType::class, [
|
||||
'label' => 'Born after this date',
|
||||
@@ -74,6 +76,18 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
'format' => 'dd-MM-yyyy',
|
||||
]);
|
||||
}
|
||||
public function getNormalizationVersion(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public function normalizeFormData(array $formData): array
|
||||
{
|
||||
return ['date_from' => $this->normalizeDate($formData['date_from']), 'date_to' => $this->normalizeDate($formData['date_to'])];
|
||||
}
|
||||
public function denormalizeFormData(array $formData, int $fromVersion): array
|
||||
{
|
||||
return ['date_from' => $this->denormalizeDate($formData['date_from']), 'date_to' => $this->denormalizeDate($formData['date_to'])];
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['date_from' => new DateTime(), 'date_to' => new DateTime()];
|
||||
@@ -81,7 +95,7 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
|
||||
// here, we create a simple string which will describe the action of
|
||||
// the filter in the Response
|
||||
public function describeAction($data, $format = 'string')
|
||||
public function describeAction($data, ExportGenerationContext $context): string|\Symfony\Contracts\Translation\TranslatableInterface|array
|
||||
{
|
||||
return ['Filtered by person\'s birtdate: '
|
||||
. 'between %date_from% and %date_to%', [
|
||||
@@ -90,7 +104,7 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
], ];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle(): string|\Symfony\Contracts\Translation\TranslatableInterface
|
||||
{
|
||||
return 'Filter by person\'s birthdate';
|
||||
}
|
||||
@@ -99,7 +113,7 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
// is executed here. This function is added by the interface
|
||||
// `ExportElementValidatedInterface`, and can be ignore if there is
|
||||
// no need for a validation
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
public function validateForm($data, ExecutionContextInterface $context): void
|
||||
{
|
||||
$date_from = $data['date_from'];
|
||||
$date_to = $data['date_to'];
|
||||
|
@@ -36,6 +36,18 @@ class CountPerson implements ExportInterface
|
||||
{
|
||||
// this export does not add any form
|
||||
}
|
||||
public function getNormalizationVersion(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public function normalizeFormData(array $formData): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function denormalizeFormData(array $formData, int $fromVersion): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
@@ -60,29 +72,29 @@ class CountPerson implements ExportInterface
|
||||
};
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
// this array match the result keys in the query. We have only
|
||||
// one column.
|
||||
return ['export_result'];
|
||||
}
|
||||
|
||||
public function getResult($query, $data)
|
||||
public function getResult($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 'Count peoples';
|
||||
}
|
||||
|
||||
public function getType()
|
||||
public function getType(): string
|
||||
{
|
||||
return Declarations::PERSON_TYPE;
|
||||
}
|
||||
|
||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): \Doctrine\ORM\QueryBuilder
|
||||
{
|
||||
// we gather all center the user choose.
|
||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||
|
Reference in New Issue
Block a user