mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Regenerate data from saved export on formatter test
[ci-skip]
This commit is contained in:
parent
fb0afc7e0a
commit
cb0a6bbd21
@ -297,8 +297,18 @@ class ExportController extends AbstractController
|
|||||||
$isGenerate = strpos($step, 'generate_') === 0;
|
$isGenerate = strpos($step, 'generate_') === 0;
|
||||||
|
|
||||||
$options = match ($step) {
|
$options = match ($step) {
|
||||||
'export', 'generate_export' => ['picked_centers' => $exportManager->getPickedCenters($data['centers'])],
|
'export', 'generate_export' => [
|
||||||
default => [],
|
'export_alias' => $alias,
|
||||||
|
'picked_centers' => $exportManager->getPickedCenters($data['centers'])
|
||||||
|
],
|
||||||
|
'formatter', 'generate_formatter' => [
|
||||||
|
'export_alias' => $alias,
|
||||||
|
'formatter_alias' => $exportManager->getFormatterAlias($data['export']),
|
||||||
|
'aggregator_aliases' => $exportManager->getUsedAggregatorsAliases($data['export']),
|
||||||
|
],
|
||||||
|
default => [
|
||||||
|
'export_alias' => $alias,
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
$defaultFormData = match ($savedExport) {
|
$defaultFormData = match ($savedExport) {
|
||||||
@ -318,26 +328,15 @@ class ExportController extends AbstractController
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ('centers' === $step || 'generate_centers' === $step) {
|
if ('centers' === $step || 'generate_centers' === $step) {
|
||||||
$builder->add('centers', PickCenterType::class, [
|
$builder->add('centers', PickCenterType::class, $options);
|
||||||
'export_alias' => $alias,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('export' === $step || 'generate_export' === $step) {
|
if ('export' === $step || 'generate_export' === $step) {
|
||||||
$builder->add('export', ExportType::class, [
|
$builder->add('export', ExportType::class, $options);
|
||||||
'export_alias' => $alias,
|
|
||||||
'picked_centers' => $exportManager->getPickedCenters($data['centers']),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('formatter' === $step || 'generate_formatter' === $step) {
|
if ('formatter' === $step || 'generate_formatter' === $step) {
|
||||||
$builder->add('formatter', FormatterType::class, [
|
$builder->add('formatter', FormatterType::class, $options);
|
||||||
'formatter_alias' => $exportManager
|
|
||||||
->getFormatterAlias($data['export']),
|
|
||||||
'export_alias' => $alias,
|
|
||||||
'aggregator_aliases' => $exportManager
|
|
||||||
->getUsedAggregatorsAliases($data['export']),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->add('submit', SubmitType::class, [
|
$builder->add('submit', SubmitType::class, [
|
||||||
|
@ -14,6 +14,7 @@ namespace Chill\MainBundle\Export;
|
|||||||
use Chill\MainBundle\Entity\SavedExport;
|
use Chill\MainBundle\Entity\SavedExport;
|
||||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||||
|
use Chill\MainBundle\Form\Type\Export\FormatterType;
|
||||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||||
@ -33,11 +34,18 @@ final readonly class ExportFormHelper
|
|||||||
return match ($step) {
|
return match ($step) {
|
||||||
'centers', 'generate_centers' => ['centers' => $this->authorizationHelper->getReachableCenters($export->requiredRole())],
|
'centers', 'generate_centers' => ['centers' => $this->authorizationHelper->getReachableCenters($export->requiredRole())],
|
||||||
'export', 'generate_export' => ['export' => $this->getDefaultDataStepExport($export, $options)],
|
'export', 'generate_export' => ['export' => $this->getDefaultDataStepExport($export, $options)],
|
||||||
'formatter', 'generate_formatter' => [],
|
'formatter', 'generate_formatter' => ['formatter' => $this->getDefaultDataStepFormatter($options)],
|
||||||
default => throw new \LogicException("step not allowed : " . $step),
|
default => throw new \LogicException("step not allowed : " . $step),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getDefaultDataStepFormatter(array $options): array
|
||||||
|
{
|
||||||
|
$formatter = $this->exportManager->getFormatter($options['formatter_alias']);
|
||||||
|
|
||||||
|
return $formatter->getFormDefaultData($options['aggregator_aliases']);
|
||||||
|
}
|
||||||
|
|
||||||
private function getDefaultDataStepExport(ExportInterface|DirectExportInterface $export, array $options): array
|
private function getDefaultDataStepExport(ExportInterface|DirectExportInterface $export, array $options): array
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
@ -87,7 +95,7 @@ final readonly class ExportFormHelper
|
|||||||
return match ($step) {
|
return match ($step) {
|
||||||
'centers', 'generate_centers' => $this->savedExportDataToFormDataStepCenter($savedExport),
|
'centers', 'generate_centers' => $this->savedExportDataToFormDataStepCenter($savedExport),
|
||||||
'export', 'generate_export' => $this->savedExportDataToFormDataStepExport($savedExport, $formOptions),
|
'export', 'generate_export' => $this->savedExportDataToFormDataStepExport($savedExport, $formOptions),
|
||||||
'formatter', 'generate_formatter' => [],
|
'formatter', 'generate_formatter' => $this->savedExportDataToFormDataStepFormatter($savedExport, $formOptions),
|
||||||
default => throw new \LogicException("this step is not allowed: " . $step),
|
default => throw new \LogicException("this step is not allowed: " . $step),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -134,4 +142,27 @@ final readonly class ExportFormHelper
|
|||||||
|
|
||||||
return $form->getData();
|
return $form->getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function savedExportDataToFormDataStepFormatter(
|
||||||
|
SavedExport $savedExport,
|
||||||
|
array $formOptions
|
||||||
|
): array {
|
||||||
|
dump(__METHOD__);
|
||||||
|
$builder = $this->formFactory
|
||||||
|
->createBuilder(
|
||||||
|
FormType::class,
|
||||||
|
[],
|
||||||
|
[
|
||||||
|
'csrf_protection' => false,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$builder->add('formatter', FormatterType::class, [
|
||||||
|
'export_alias' => $savedExport->getExportAlias(), ...$formOptions
|
||||||
|
]);
|
||||||
|
$form = $builder->getForm();
|
||||||
|
$form->submit($savedExport->getOptions()['formatter']);
|
||||||
|
|
||||||
|
return $form->getData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,19 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getFormDefaultData(array $aggregatorAliases): array
|
||||||
|
{
|
||||||
|
$data = ['format' => 'xlsx'];
|
||||||
|
|
||||||
|
$aggregators = iterator_to_array($this->exportManager->getAggregators($aggregatorAliases));
|
||||||
|
foreach (array_keys($aggregators) as $index => $alias) {
|
||||||
|
$data[$alias] = ['order' => $index + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'SpreadSheet (xlsx, ods)';
|
return 'SpreadSheet (xlsx, ods)';
|
||||||
}
|
}
|
||||||
@ -185,7 +197,7 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
array $exportData,
|
array $exportData,
|
||||||
array $filtersData,
|
array $filtersData,
|
||||||
array $aggregatorsData
|
array $aggregatorsData
|
||||||
) {
|
): Response {
|
||||||
// store all data when the process is initiated
|
// store all data when the process is initiated
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
$this->formatterData = $formatterData;
|
$this->formatterData = $formatterData;
|
||||||
@ -574,10 +586,8 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
*
|
*
|
||||||
* This form allow to choose the aggregator position (row or column) and
|
* This form allow to choose the aggregator position (row or column) and
|
||||||
* the ordering
|
* the ordering
|
||||||
*
|
|
||||||
* @param string $nbAggregators
|
|
||||||
*/
|
*/
|
||||||
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
private function appendAggregatorForm(FormBuilderInterface $builder, int $nbAggregators): void
|
||||||
{
|
{
|
||||||
$builder->add('order', ChoiceType::class, [
|
$builder->add('order', ChoiceType::class, [
|
||||||
'choices' => array_combine(
|
'choices' => array_combine(
|
||||||
|
@ -88,6 +88,7 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
|
|
||||||
public function applyOn()
|
public function applyOn()
|
||||||
{
|
{
|
||||||
|
return 'abcde';
|
||||||
return 'person';
|
return 'person';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +104,13 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFormDefaultData(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'group_by_level' => 'country',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data)
|
||||||
{
|
{
|
||||||
$labels = [];
|
$labels = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user