Merge branch '110-export-editable' into 'master'

Feature: make saved export editables ( OP#203 )

Closes #110

See merge request Chill-Projet/chill-bundles!554
This commit is contained in:
Julien Fastré 2023-06-27 16:32:37 +00:00
commit 01dee54fab
225 changed files with 2619 additions and 304 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: 'Edit saved exports options: the saved exports options (forms, filters, aggregators)
are now editable.'
time: 2023-06-06T10:51:53.331701352+02:00
custom:
Issue: "110"

View File

@ -0,0 +1,6 @@
kind: Feature
body: '[export] Set the default date of calculation of the accompanying period''s
list as "today"'
time: 2023-06-27T11:12:22.296330037+02:00
custom:
Issue: ""

View File

@ -0,0 +1,6 @@
kind: Feature
body: 'Rename label of filter in French: "parcours actif" => "parcours ouvert", and
"filtrer les parcours ouverts" => "Filtrer les parcours dont la date d''ouverture"'
time: 2023-06-27T15:59:25.442854464+02:00
custom:
Issue: ""

View File

@ -13,6 +13,7 @@ $finder = PhpCsFixer\Finder::create();
$finder $finder
->in(__DIR__.'/src') ->in(__DIR__.'/src')
->in(__DIR__.'/utils')
->append([__FILE__]) ->append([__FILE__])
->exclude(['docs/', 'tests/app']) ->exclude(['docs/', 'tests/app'])
->notPath('tests/app') ->notPath('tests/app')

View File

@ -67,6 +67,7 @@
"fakerphp/faker": "^1.13", "fakerphp/faker": "^1.13",
"jangregor/phpstan-prophecy": "^1.0", "jangregor/phpstan-prophecy": "^1.0",
"nelmio/alice": "^3.8", "nelmio/alice": "^3.8",
"nikic/php-parser": "^4.15",
"phpspec/prophecy-phpunit": "^2.0", "phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.2", "phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9", "phpstan/phpstan": "^1.9",
@ -103,14 +104,16 @@
"Chill\\ReportBundle\\": "src/Bundle/ChillReportBundle", "Chill\\ReportBundle\\": "src/Bundle/ChillReportBundle",
"Chill\\TaskBundle\\": "src/Bundle/ChillTaskBundle", "Chill\\TaskBundle\\": "src/Bundle/ChillTaskBundle",
"Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle", "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle",
"Chill\\WopiBundle\\": "src/Bundle/ChillWopiBundle/src" "Chill\\WopiBundle\\": "src/Bundle/ChillWopiBundle/src",
"Chill\\Utils\\Rector\\": "utils/rector/src"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"App\\": "tests/app/src/", "App\\": "tests/app/src/",
"Chill\\DocGeneratorBundle\\Tests\\": "src/Bundle/ChillDocGeneratorBundle/tests", "Chill\\DocGeneratorBundle\\Tests\\": "src/Bundle/ChillDocGeneratorBundle/tests",
"Chill\\WopiBundle\\Tests\\": "src/Bundle/ChillDocGeneratorBundle/tests" "Chill\\WopiBundle\\Tests\\": "src/Bundle/ChillDocGeneratorBundle/tests",
"Chill\\Utils\\Rector\\Tests\\": "utils/rector/tests"
} }
}, },
"config": { "config": {

View File

@ -62,7 +62,6 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
{ {
$builder->add('date_from', DateType::class, [ $builder->add('date_from', DateType::class, [
'label' => 'Born after this date', 'label' => 'Born after this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'], 'attr' => ['class' => 'datepicker'],
'widget' => 'single_text', 'widget' => 'single_text',
'format' => 'dd-MM-yyyy', 'format' => 'dd-MM-yyyy',
@ -70,12 +69,15 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
$builder->add('date_to', DateType::class, [ $builder->add('date_to', DateType::class, [
'label' => 'Born before this date', 'label' => 'Born before this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'], 'attr' => ['class' => 'datepicker'],
'widget' => 'single_text', 'widget' => 'single_text',
'format' => 'dd-MM-yyyy', 'format' => 'dd-MM-yyyy',
]); ]);
} }
public function getFormDefaultData(): array
{
return ['date_from' => new DateTime(), 'date_to' => new DateTime()];
}
// here, we create a simple string which will describe the action of // here, we create a simple string which will describe the action of
// the filter in the Response // the filter in the Response

View File

@ -36,6 +36,10 @@ class CountPerson implements ExportInterface
{ {
// this export does not add any form // this export does not add any form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -2,6 +2,7 @@ parameters:
level: 5 level: 5
paths: paths:
- src/ - src/
- utils/
tmpDir: .cache/ tmpDir: .cache/
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
excludePaths: excludePaths:

29
phpunit.rector.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/app/vendor/autoload.php"
cacheResultFile=".cache/phpunit/test-results-rector"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true"
>
<testsuites>
<testsuite name="default">
<directory>utils/rector/tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".cache/phpunit/code-coverage-rector"
processUncoveredFiles="true">
<include>
<directory suffix=".php">utils/rector/src</directory>
</include>
</coverage>
</phpunit>

View File

@ -24,6 +24,9 @@ return static function (RectorConfig $rectorConfig): void {
LevelSetList::UP_TO_PHP_74 LevelSetList::UP_TO_PHP_74
]); ]);
// chill rules
$rectorConfig->rule(\Chill\Utils\Rector\Rector\ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector::class);
// skip some path... // skip some path...
$rectorConfig->skip([ $rectorConfig->skip([
// make rector stuck for some files // make rector stuck for some files

View File

@ -40,6 +40,10 @@ class ByActivityNumberAggregator implements AggregatorInterface
{ {
// No form needed // No form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -52,6 +52,10 @@ class ByCreatorAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class BySocialActionAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class BySocialIssueAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class ByThirdpartyAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class CreatorScopeAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -29,14 +29,6 @@ class DateAggregator implements AggregatorInterface
private const DEFAULT_CHOICE = 'year'; private const DEFAULT_CHOICE = 'year';
private TranslatorInterface $translator;
public function __construct(
TranslatorInterface $translator
) {
$this->translator = $translator;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -84,9 +76,12 @@ class DateAggregator implements AggregatorInterface
'multiple' => false, 'multiple' => false,
'expanded' => true, 'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE, 'empty_data' => self::DEFAULT_CHOICE,
'data' => self::DEFAULT_CHOICE,
]); ]);
} }
public function getFormDefaultData(): array
{
return ['frequency' => self::DEFAULT_CHOICE];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class LocationTypeAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -60,6 +60,10 @@ class ActivityTypeAggregator implements AggregatorInterface
{ {
// no form required for this aggregator // no form required for this aggregator
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -58,6 +58,10 @@ class ActivityUserAggregator implements AggregatorInterface
{ {
// nothing to add // nothing to add
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, $values, $data): Closure public function getLabels($key, $values, $data): Closure
{ {

View File

@ -56,6 +56,10 @@ class ActivityUsersAggregator implements AggregatorInterface
{ {
// nothing to add on the form // nothing to add on the form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -55,6 +55,10 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI
{ {
// nothing to add in the form // nothing to add in the form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -55,6 +55,10 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato
{ {
// nothing to add in the form // nothing to add in the form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -110,6 +110,10 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali
] ]
); );
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -47,6 +47,10 @@ class SentReceivedAggregator implements AggregatorInterface
{ {
// No form needed // No form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): callable public function getLabels($key, array $values, $data): callable
{ {

View File

@ -39,6 +39,10 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -40,6 +40,10 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
{ {
// TODO: Implement buildForm() method. // TODO: Implement buildForm() method.
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -39,6 +39,10 @@ class CountActivity implements ExportInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -44,6 +44,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
{ {
$this->helper->buildForm($builder); $this->helper->buildForm($builder);
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -40,6 +40,10 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
{ {
// TODO: Implement buildForm() method. // TODO: Implement buildForm() method.
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -40,6 +40,10 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
{ {
// TODO: Implement buildForm() method. // TODO: Implement buildForm() method.
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -35,6 +35,10 @@ class CountActivity implements ExportInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -88,6 +88,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
])], ])],
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -53,6 +53,10 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -68,6 +68,10 @@ class ActivityTypeFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -52,6 +52,10 @@ class ByCreatorFilter implements FilterInterface
'multiple' => true, 'multiple' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -60,6 +60,10 @@ class BySocialActionFilter implements FilterInterface
'multiple' => true, 'multiple' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -60,6 +60,10 @@ class BySocialIssueFilter implements FilterInterface
'multiple' => true, 'multiple' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -68,9 +68,12 @@ class EmergencyFilter implements FilterInterface
'multiple' => false, 'multiple' => false,
'expanded' => true, 'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE, 'empty_data' => self::DEFAULT_CHOICE,
'data' => self::DEFAULT_CHOICE,
]); ]);
} }
public function getFormDefaultData(): array
{
return ['accepted_emergency' => self::DEFAULT_CHOICE];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -44,6 +44,10 @@ class HasNoActivityFilter implements FilterInterface
{ {
//no form needed //no form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -46,6 +46,10 @@ class LocationFilter implements FilterInterface
'label' => 'pick location', 'label' => 'pick location',
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -65,6 +65,10 @@ class LocationTypeFilter implements FilterInterface
//'label' => false, //'label' => false,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -69,9 +69,12 @@ class SentReceivedFilter implements FilterInterface
'multiple' => false, 'multiple' => false,
'expanded' => true, 'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE, 'empty_data' => self::DEFAULT_CHOICE,
'data' => self::DEFAULT_CHOICE,
]); ]);
} }
public function getFormDefaultData(): array
{
return ['accepted_sentreceived' => self::DEFAULT_CHOICE];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -61,6 +61,10 @@ class UserFilter implements FilterInterface
'label' => 'Creators', 'label' => 'Creators',
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -71,6 +71,10 @@ class UserScopeFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -80,11 +80,9 @@ class ActivityDateFilter implements FilterInterface
$builder $builder
->add('date_from', PickRollingDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'label' => 'Activities after this date', 'label' => 'Activities after this date',
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
]) ])
->add('date_to', PickRollingDateType::class, [ ->add('date_to', PickRollingDateType::class, [
'label' => 'Activities before this date', 'label' => 'Activities before this date',
'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
@ -127,6 +125,10 @@ class ActivityDateFilter implements FilterInterface
} }
}); });
} }
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, $format = 'string')
{ {

View File

@ -78,6 +78,10 @@ class ActivityTypeFilter implements ExportElementValidatedInterface, FilterInter
], ],
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -56,6 +56,10 @@ class ActivityUsersFilter implements FilterInterface
'label' => 'Users', 'label' => 'Users',
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -82,6 +82,10 @@ class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInt
'expanded' => false, 'expanded' => false,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -112,7 +112,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
{ {
$builder->add('date_from', DateType::class, [ $builder->add('date_from', DateType::class, [
'label' => 'Implied in an activity after this date', 'label' => 'Implied in an activity after this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'], 'attr' => ['class' => 'datepicker'],
'widget' => 'single_text', 'widget' => 'single_text',
'format' => 'dd-MM-yyyy', 'format' => 'dd-MM-yyyy',
@ -120,7 +119,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
$builder->add('date_to', DateType::class, [ $builder->add('date_to', DateType::class, [
'label' => 'Implied in an activity before this date', 'label' => 'Implied in an activity before this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'], 'attr' => ['class' => 'datepicker'],
'widget' => 'single_text', 'widget' => 'single_text',
'format' => 'dd-MM-yyyy', 'format' => 'dd-MM-yyyy',
@ -130,7 +128,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
'class' => ActivityReason::class, 'class' => ActivityReason::class,
'choice_label' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()), 'choice_label' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()),
'group_by' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()), 'group_by' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()),
'data' => $this->activityReasonRepository->findAll(),
'multiple' => true, 'multiple' => true,
'expanded' => false, 'expanded' => false,
'label' => 'Activity reasons for those activities', 'label' => 'Activity reasons for those activities',
@ -176,6 +173,10 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
} }
}); });
} }
public function getFormDefaultData(): array
{
return ['date_from' => new DateTime(), 'date_to' => new DateTime(), 'reasons' => $this->activityReasonRepository->findAll()];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -60,6 +60,10 @@ class UsersJobFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -67,6 +67,10 @@ class UsersScopeFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -50,6 +50,10 @@ class ByActivityTypeAggregator implements AggregatorInterface
{ {
// No form needed // No form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class ByUserJobAggregator implements AggregatorInterface
{ {
// nothing to add in the form // nothing to add in the form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -57,6 +57,10 @@ class ByUserScopeAggregator implements AggregatorInterface
{ {
// nothing to add in the form // nothing to add in the form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {

View File

@ -34,6 +34,10 @@ class AvgAsideActivityDuration implements ExportInterface, GroupedExportInterfac
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -34,6 +34,10 @@ class CountAsideActivity implements ExportInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -73,6 +73,10 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
{ {

View File

@ -34,6 +34,10 @@ class SumAsideActivityDuration implements ExportInterface, GroupedExportInterfac
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -76,6 +76,10 @@ class ByActivityTypeFilter implements FilterInterface
}, },
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -72,11 +72,9 @@ class ByDateFilter implements FilterInterface
$builder $builder
->add('date_from', PickRollingDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'label' => 'export.filter.Aside activities after this date', 'label' => 'export.filter.Aside activities after this date',
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
]) ])
->add('date_to', PickRollingDateType::class, [ ->add('date_to', PickRollingDateType::class, [
'label' => 'export.filter.Aside activities before this date', 'label' => 'export.filter.Aside activities before this date',
'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
@ -119,6 +117,10 @@ class ByDateFilter implements FilterInterface
} }
}); });
} }
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'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -53,6 +53,10 @@ class ByUserFilter implements FilterInterface
'label' => 'Creators', 'label' => 'Creators',
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -60,6 +60,10 @@ class ByUserJobFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -67,6 +67,10 @@ class ByUserScopeFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -58,6 +58,10 @@ final class AgentAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -59,6 +59,10 @@ class CancelReasonAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -58,6 +58,10 @@ final class JobAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -52,6 +52,10 @@ final class LocationAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -58,6 +58,10 @@ final class LocationTypeAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -40,6 +40,10 @@ class MonthYearAggregator implements AggregatorInterface
{ {
// No form needed // No form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -58,6 +58,10 @@ final class ScopeAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -56,6 +56,10 @@ class UrgencyAggregator implements AggregatorInterface
{ {
// no form // no form
} }
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, $data): Closure public function getLabels($key, array $values, $data): Closure
{ {

View File

@ -36,6 +36,10 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
{ {
// No form necessary // No form necessary
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -36,6 +36,10 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
{ {
// no form needed // no form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -36,6 +36,10 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
{ {
// no form needed // no form needed
} }
public function getFormDefaultData(): array
{
return [];
}
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
{ {

View File

@ -63,6 +63,10 @@ class AgentFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -60,12 +60,12 @@ class BetweenDatesFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_from', PickRollingDateType::class, [ ->add('date_from', PickRollingDateType::class, [])
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ->add('date_to', PickRollingDateType::class, []);
]) }
->add('date_to', PickRollingDateType::class, [ public function getFormDefaultData(): array
'data' => new RollingDate(RollingDate::T_TODAY), {
]); return ['date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'date_to' => new RollingDate(RollingDate::T_TODAY)];
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array

View File

@ -69,9 +69,12 @@ class CalendarRangeFilter implements FilterInterface
'multiple' => false, 'multiple' => false,
'expanded' => true, 'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE, 'empty_data' => self::DEFAULT_CHOICE,
'data' => self::DEFAULT_CHOICE,
]); ]);
} }
public function getFormDefaultData(): array
{
return ['hasCalendarRange' => self::DEFAULT_CHOICE];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -76,6 +76,10 @@ class JobFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {

View File

@ -76,6 +76,10 @@ class ScopeFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
} }
public function getFormDefaultData(): array
{
return [];
}
public function describeAction($data, $format = 'string') public function describeAction($data, $format = 'string')
{ {

View File

@ -13,12 +13,16 @@ namespace Chill\MainBundle\Controller;
use Chill\MainBundle\Entity\SavedExport; use Chill\MainBundle\Entity\SavedExport;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\DirectExportInterface;
use Chill\MainBundle\Export\ExportFormHelper;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Form\SavedExportType; use Chill\MainBundle\Form\SavedExportType;
use Chill\MainBundle\Form\Type\Export\ExportType; use Chill\MainBundle\Form\Type\Export\ExportType;
use Chill\MainBundle\Form\Type\Export\FormatterType; use Chill\MainBundle\Form\Type\Export\FormatterType;
use Chill\MainBundle\Form\Type\Export\PickCenterType; use Chill\MainBundle\Form\Type\Export\PickCenterType;
use Chill\MainBundle\Redis\ChillRedis; use Chill\MainBundle\Redis\ChillRedis;
use Chill\MainBundle\Repository\SavedExportRepositoryInterface;
use Chill\MainBundle\Security\Authorization\SavedExportVoter; use Chill\MainBundle\Security\Authorization\SavedExportVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use LogicException; use LogicException;
@ -36,6 +40,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
use function count; use function count;
use function serialize; use function serialize;
@ -86,7 +91,10 @@ class ExportController extends AbstractController
LoggerInterface $logger, LoggerInterface $logger,
SessionInterface $session, SessionInterface $session,
TranslatorInterface $translator, TranslatorInterface $translator,
EntityManagerInterface $entityManager EntityManagerInterface $entityManager,
private readonly ExportFormHelper $exportFormHelper,
private readonly SavedExportRepositoryInterface $savedExportRepository,
private readonly Security $security,
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->redis = $chillRedis; $this->redis = $chillRedis;
@ -101,12 +109,11 @@ class ExportController extends AbstractController
{ {
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */ /** @var \Chill\MainBundle\Export\ExportManager $exportManager */
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
$export = $exportManager->getExport($alias); $export = $exportManager->getExport($alias);
$key = $request->query->get('key', null); $key = $request->query->get('key', null);
$savedExport = $this->getSavedExportFromRequest($request);
[$dataCenters, $dataExport, $dataFormatter] = $this->rebuildData($key); [$dataCenters, $dataExport, $dataFormatter] = $this->rebuildData($key, $savedExport);
$formatterAlias = $exportManager->getFormatterAlias($dataExport['export']); $formatterAlias = $exportManager->getFormatterAlias($dataExport['export']);
@ -120,6 +127,7 @@ class ExportController extends AbstractController
'alias' => $alias, 'alias' => $alias,
'export' => $export, 'export' => $export,
'export_group' => $this->getExportGroup($export), 'export_group' => $this->getExportGroup($export),
'saved_export' => $savedExport,
]; ];
if ($formater instanceof \Chill\MainBundle\Export\Formatter\CSVListFormatter) { if ($formater instanceof \Chill\MainBundle\Export\Formatter\CSVListFormatter) {
@ -144,8 +152,9 @@ class ExportController extends AbstractController
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */ /** @var \Chill\MainBundle\Export\ExportManager $exportManager */
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
$key = $request->query->get('key', null); $key = $request->query->get('key', null);
$savedExport = $this->getSavedExportFromRequest($request);
[$dataCenters, $dataExport, $dataFormatter] = $this->rebuildData($key); [$dataCenters, $dataExport, $dataFormatter] = $this->rebuildData($key, $savedExport);
return $exportManager->generate( return $exportManager->generate(
$alias, $alias,
@ -204,12 +213,8 @@ class ExportController extends AbstractController
* 3. 'generate': gather data from session from the previous steps, and * 3. 'generate': gather data from session from the previous steps, and
* make a redirection to the "generate" action with data in query (HTTP GET) * make a redirection to the "generate" action with data in query (HTTP GET)
* *
* @param string $request
* @param Request $alias
*
* @return \Symfony\Component\HttpFoundation\Response
*/ */
public function newAction(Request $request, $alias) public function newAction(Request $request, string $alias): Response
{ {
// first check for ACL // first check for ACL
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
@ -219,26 +224,50 @@ class ExportController extends AbstractController
throw $this->createAccessDeniedException('The user does not have access to this export'); throw $this->createAccessDeniedException('The user does not have access to this export');
} }
$savedExport = $this->getSavedExportFromRequest($request);
$step = $request->query->getAlpha('step', 'centers'); $step = $request->query->getAlpha('step', 'centers');
switch ($step) { switch ($step) {
case 'centers': case 'centers':
return $this->selectCentersStep($request, $export, $alias); return $this->selectCentersStep($request, $export, $alias, $savedExport);
case 'export': case 'export':
return $this->exportFormStep($request, $export, $alias); return $this->exportFormStep($request, $export, $alias, $savedExport);
case 'formatter': case 'formatter':
return $this->formatterFormStep($request, $export, $alias); return $this->formatterFormStep($request, $export, $alias, $savedExport);
case 'generate': case 'generate':
return $this->forwardToGenerate($request, $export, $alias); return $this->forwardToGenerate($request, $export, $alias, $savedExport);
default: default:
throw $this->createNotFoundException("The given step '{$step}' is invalid"); throw $this->createNotFoundException("The given step '{$step}' is invalid");
} }
} }
/**
* @Route("/{_locale}/export/saved/update-from-key/{id}/{key}", name="chill_main_export_saved_edit_options_from_key")
*/
public function editSavedExportOptionsFromKey(SavedExport $savedExport, string $key): Response
{
$this->denyAccessUnlessGranted('ROLE_USER');
$user = $this->getUser();
if (!$user instanceof User) {
throw new AccessDeniedHttpException();
}
$data = $this->rebuildRawData($key);
$savedExport
->setOptions($data);
$this->entityManager->flush();
return $this->redirectToRoute('chill_main_export_saved_edit', ['id' => $savedExport->getId()]);
}
/** /**
* @Route("/{_locale}/export/save-from-key/{alias}/{key}", name="chill_main_export_save_from_key") * @Route("/{_locale}/export/save-from-key/{alias}/{key}", name="chill_main_export_save_from_key")
*/ */
@ -282,45 +311,55 @@ class ExportController extends AbstractController
/** /**
* create a form to show on different steps. * create a form to show on different steps.
* *
* @param string $alias
* @param array $data the data from previous step. Required for steps 'formatter' and 'generate_formatter' * @param array $data the data from previous step. Required for steps 'formatter' and 'generate_formatter'
* @param mixed $step
*/ */
protected function createCreateFormExport($alias, $step, $data = []): FormInterface protected function createCreateFormExport(string $alias, string $step, array $data, ?SavedExport $savedExport): FormInterface
{ {
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */ /** @var \Chill\MainBundle\Export\ExportManager $exportManager */
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
$isGenerate = strpos($step, 'generate_') === 0; $isGenerate = strpos($step, 'generate_') === 0;
$builder = $this->formFactory $options = match ($step) {
->createNamedBuilder(null, FormType::class, [], [ 'export', 'generate_export' => [
'method' => $isGenerate ? 'GET' : 'POST', 'export_alias' => $alias,
'csrf_protection' => $isGenerate ? false : true, '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,
],
};
// TODO: add a condition to be able to select a regroupment of centers? $defaultFormData = match ($savedExport) {
null => $this->exportFormHelper->getDefaultData($step, $exportManager->getExport($alias), $options),
default => $this->exportFormHelper->savedExportDataToFormData($savedExport, $step, $options),
};
$builder = $this->formFactory
->createNamedBuilder(
null,
FormType::class,
$defaultFormData,
[
'method' => $isGenerate ? 'GET' : 'POST',
'csrf_protection' => !$isGenerate,
]
);
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, [
@ -335,13 +374,8 @@ class ExportController extends AbstractController
* *
* When the method is POST, the form is stored if valid, and a redirection * When the method is POST, the form is stored if valid, and a redirection
* is done to next step. * is done to next step.
*
* @param string $alias
* @param \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export
*
* @return \Symfony\Component\HttpFoundation\Response
*/ */
protected function exportFormStep(Request $request, $export, $alias) private function exportFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response
{ {
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
@ -357,7 +391,7 @@ class ExportController extends AbstractController
$export = $exportManager->getExport($alias); $export = $exportManager->getExport($alias);
$form = $this->createCreateFormExport($alias, 'export', $data); $form = $this->createCreateFormExport($alias, 'export', $data, $savedExport);
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$form->handleRequest($request); $form->handleRequest($request);
@ -379,6 +413,7 @@ class ExportController extends AbstractController
$this->generateUrl('chill_main_export_new', [ $this->generateUrl('chill_main_export_new', [
'step' => $this->getNextStep('export', $export), 'step' => $this->getNextStep('export', $export),
'alias' => $alias, 'alias' => $alias,
'from_saved' => $request->get('from_saved', '')
]) ])
); );
} }
@ -399,13 +434,8 @@ class ExportController extends AbstractController
* *
* If the form is posted and valid, store the data in session and * If the form is posted and valid, store the data in session and
* redirect to the next step. * redirect to the next step.
*
* @param \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export
* @param string $alias
*
* @return \Symfony\Component\HttpFoundation\Response
*/ */
protected function formatterFormStep(Request $request, $export, $alias) private function formatterFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response
{ {
// check we have data from the previous step (export step) // check we have data from the previous step (export step)
$data = $this->session->get('export_step', null); $data = $this->session->get('export_step', null);
@ -417,7 +447,7 @@ class ExportController extends AbstractController
]); ]);
} }
$form = $this->createCreateFormExport($alias, 'formatter', $data); $form = $this->createCreateFormExport($alias, 'formatter', $data, $savedExport);
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$form->handleRequest($request); $form->handleRequest($request);
@ -436,6 +466,7 @@ class ExportController extends AbstractController
[ [
'alias' => $alias, 'alias' => $alias,
'step' => $this->getNextStep('formatter', $export), 'step' => $this->getNextStep('formatter', $export),
'from_saved' => $request->get('from_saved', ''),
] ]
)); ));
} }
@ -462,7 +493,7 @@ class ExportController extends AbstractController
* *
* @return \Symfony\Component\HttpFoundation\RedirectResponse * @return \Symfony\Component\HttpFoundation\RedirectResponse
*/ */
protected function forwardToGenerate(Request $request, $export, $alias) private function forwardToGenerate(Request $request, $export, $alias, ?SavedExport $savedExport)
{ {
$dataCenters = $this->session->get('centers_step_raw', null); $dataCenters = $this->session->get('centers_step_raw', null);
$dataFormatter = $this->session->get('formatter_step_raw', null); $dataFormatter = $this->session->get('formatter_step_raw', null);
@ -470,7 +501,9 @@ class ExportController extends AbstractController
if (null === $dataFormatter && $export instanceof \Chill\MainBundle\Export\ExportInterface) { if (null === $dataFormatter && $export instanceof \Chill\MainBundle\Export\ExportInterface) {
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true), 'alias' => $alias,
'step' => $this->getNextStep('generate', $export, true),
'from_saved' => $savedExport?->getId() ?? '',
]); ]);
} }
@ -491,20 +524,24 @@ class ExportController extends AbstractController
$this->session->remove('formatter_step_raw'); $this->session->remove('formatter_step_raw');
$this->session->remove('formatter_step'); $this->session->remove('formatter_step');
return $this->redirectToRoute('chill_main_export_download', ['key' => $key, 'alias' => $alias]); return $this->redirectToRoute('chill_main_export_download', [
'key' => $key,
'alias' => $alias,
'from_saved' => $savedExport?->getId(),
]);
} }
protected function rebuildData($key) private function rebuildData($key, ?SavedExport $savedExport)
{ {
$rawData = $this->rebuildRawData($key); $rawData = $this->rebuildRawData($key);
$alias = $rawData['alias']; $alias = $rawData['alias'];
$formCenters = $this->createCreateFormExport($alias, 'generate_centers'); $formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport);
$formCenters->submit($rawData['centers']); $formCenters->submit($rawData['centers']);
$dataCenters = $formCenters->getData(); $dataCenters = $formCenters->getData();
$formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters); $formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters, $savedExport);
$formExport->submit($rawData['export']); $formExport->submit($rawData['export']);
$dataExport = $formExport->getData(); $dataExport = $formExport->getData();
@ -512,7 +549,8 @@ class ExportController extends AbstractController
$formFormatter = $this->createCreateFormExport( $formFormatter = $this->createCreateFormExport(
$alias, $alias,
'generate_formatter', 'generate_formatter',
$dataExport $dataExport,
$savedExport
); );
$formFormatter->submit($rawData['formatter']); $formFormatter->submit($rawData['formatter']);
$dataFormatter = $formFormatter->getData(); $dataFormatter = $formFormatter->getData();
@ -527,12 +565,12 @@ class ExportController extends AbstractController
* *
* @return Response * @return Response
*/ */
protected function selectCentersStep(Request $request, $export, $alias) private function selectCentersStep(Request $request, $export, $alias, ?SavedExport $savedExport = null)
{ {
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */ /** @var \Chill\MainBundle\Export\ExportManager $exportManager */
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
$form = $this->createCreateFormExport($alias, 'centers'); $form = $this->createCreateFormExport($alias, 'centers', [], $savedExport);
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$form->handleRequest($request); $form->handleRequest($request);
@ -564,6 +602,7 @@ class ExportController extends AbstractController
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
'step' => $this->getNextStep('centers', $export), 'step' => $this->getNextStep('centers', $export),
'alias' => $alias, 'alias' => $alias,
'from_saved' => $request->get('from_saved', ''),
]); ]);
} }
} }
@ -670,4 +709,18 @@ class ExportController extends AbstractController
return $rawData; return $rawData;
} }
private function getSavedExportFromRequest(Request $request): ?SavedExport
{
$savedExport = match ($savedExportId = $request->query->get('from_saved', '')) {
'' => null,
default => $this->savedExportRepository->find($savedExportId),
};
if (null !== $savedExport && !$this->security->isGranted(SavedExportVoter::EDIT, $savedExport)) {
throw new AccessDeniedHttpException("saved export edition not allowed");
}
return $savedExport;
}
} }

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export; namespace Chill\MainBundle\Export;
use Closure; use Closure;
use Symfony\Component\Form\FormBuilderInterface;
/** /**
* Interface for Aggregators. * Interface for Aggregators.
@ -21,6 +22,16 @@ use Closure;
*/ */
interface AggregatorInterface extends ModifierInterface interface AggregatorInterface extends ModifierInterface
{ {
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
/**
* Get the default data, that can be use as "data" for the form
*/
public function getFormDefaultData(): array;
/** /**
* get a callable which will be able to transform the results into * get a callable which will be able to transform the results into
* viewable and understable string. * viewable and understable string.

View File

@ -11,10 +11,21 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export; namespace Chill\MainBundle\Export;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
interface DirectExportInterface extends ExportElementInterface interface DirectExportInterface extends ExportElementInterface
{ {
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
/**
* Get the default data, that can be use as "data" for the form
*/
public function getFormDefaultData(): array;
/** /**
* Generate the export. * Generate the export.
*/ */

View File

@ -19,11 +19,6 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
interface ExportElementInterface interface ExportElementInterface
{ {
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
/** /**
* get a title, which will be used in UI (and translated). * get a title, which will be used in UI (and translated).
* *

View File

@ -0,0 +1,171 @@
<?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\MainBundle\Export;
use Chill\MainBundle\Entity\SavedExport;
use Chill\MainBundle\Form\Type\Export\ExportType;
use Chill\MainBundle\Form\Type\Export\FilterType;
use Chill\MainBundle\Form\Type\Export\FormatterType;
use Chill\MainBundle\Form\Type\Export\PickCenterType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormFactoryInterface;
final readonly class ExportFormHelper
{
public function __construct(
private AuthorizationHelperForCurrentUserInterface $authorizationHelper,
private ExportManager $exportManager,
private FormFactoryInterface $formFactory,
) {
}
public function getDefaultData(string $step, ExportInterface|DirectExportInterface $export, array $options = []): array
{
return match ($step) {
'centers', 'generate_centers' => ['centers' => $this->authorizationHelper->getReachableCenters($export->requiredRole())],
'export', 'generate_export' => ['export' => $this->getDefaultDataStepExport($export, $options)],
'formatter', 'generate_formatter' => ['formatter' => $this->getDefaultDataStepFormatter($options)],
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
{
$data = [
ExportType::EXPORT_KEY => $export->getFormDefaultData(),
ExportType::FILTER_KEY => [],
ExportType::AGGREGATOR_KEY => [],
ExportType::PICK_FORMATTER_KEY => [],
];
$filters = $this->exportManager->getFiltersApplyingOn($export, $options['picked_centers']);
foreach ($filters as $alias => $filter) {
$data[ExportType::FILTER_KEY][$alias] = [
FilterType::ENABLED_FIELD => false,
'form' => $filter->getFormDefaultData()
];
}
$aggregators = $this->exportManager
->getAggregatorsApplyingOn($export, $options['picked_centers']);
foreach ($aggregators as $alias => $aggregator) {
$data[ExportType::AGGREGATOR_KEY][$alias] = [
'enabled' => false,
'form' => $aggregator->getFormDefaultData(),
];
}
if ($export instanceof ExportInterface) {
$allowedFormatters = $this->exportManager
->getFormattersByTypes($export->getAllowedFormattersTypes());
$choices = [];
foreach (array_keys(iterator_to_array($allowedFormatters)) as $alias) {
$choices[] = $alias;
}
$data[ExportType::PICK_FORMATTER_KEY]['alias'] = match (count($choices)) {
1 => $choices[0],
default => null,
};
} else {
unset($data[ExportType::PICK_FORMATTER_KEY]);
}
return $data;
}
public function savedExportDataToFormData(
SavedExport $savedExport,
string $step,
array $formOptions = [],
): array {
return match ($step) {
'centers', 'generate_centers' => $this->savedExportDataToFormDataStepCenter($savedExport),
'export', 'generate_export' => $this->savedExportDataToFormDataStepExport($savedExport, $formOptions),
'formatter', 'generate_formatter' => $this->savedExportDataToFormDataStepFormatter($savedExport, $formOptions),
default => throw new \LogicException("this step is not allowed: " . $step),
};
}
private function savedExportDataToFormDataStepCenter(
SavedExport $savedExport,
): array {
$builder = $this->formFactory
->createBuilder(
FormType::class,
[],
[
'csrf_protection' => false,
]
);
$builder->add('centers', PickCenterType::class, [
'export_alias' => $savedExport->getExportAlias(),
]);
$form = $builder->getForm();
$form->submit($savedExport->getOptions()['centers']);
return $form->getData();
}
private function savedExportDataToFormDataStepExport(
SavedExport $savedExport,
array $formOptions
): array {
$builder = $this->formFactory
->createBuilder(
FormType::class,
[],
[
'csrf_protection' => false,
]
);
$builder->add('export', ExportType::class, [
'export_alias' => $savedExport->getExportAlias(), ...$formOptions
]);
$form = $builder->getForm();
$form->submit($savedExport->getOptions()['export']);
return $form->getData();
}
private function savedExportDataToFormDataStepFormatter(
SavedExport $savedExport,
array $formOptions
): array {
$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();
}
}

View File

@ -13,6 +13,7 @@ namespace Chill\MainBundle\Export;
use Doctrine\ORM\NativeQuery; use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
/** /**
* Interface for Export. * Interface for Export.
@ -28,6 +29,16 @@ use Doctrine\ORM\QueryBuilder;
*/ */
interface ExportInterface extends ExportElementInterface interface ExportInterface extends ExportElementInterface
{ {
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
/**
* Get the default data, that can be use as "data" for the form
*/
public function getFormDefaultData(): array;
/** /**
* Return which formatter type is allowed for this report. * Return which formatter type is allowed for this report.
* *

View File

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export; namespace Chill\MainBundle\Export;
use Chill\MainBundle\Form\Type\Export\ExportType; use Chill\MainBundle\Form\Type\Export\ExportType;
use Chill\MainBundle\Form\Type\Export\PickCenterType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Generator; use Generator;
@ -114,8 +113,12 @@ class ExportManager
* *
* @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias * @return FilterInterface[] a \Generator that contains filters. The key is the filter's alias
*/ */
public function &getFiltersApplyingOn(ExportInterface $export, ?array $centers = null) public function &getFiltersApplyingOn(ExportInterface|DirectExportInterface $export, ?array $centers = null): iterable
{ {
if ($export instanceof DirectExportInterface) {
return;
}
foreach ($this->filters as $alias => $filter) { foreach ($this->filters as $alias => $filter) {
if ( if (
in_array($filter->applyOn(), $export->supportsModifiers(), true) in_array($filter->applyOn(), $export->supportsModifiers(), true)
@ -131,11 +134,11 @@ class ExportManager
* *
* @internal This class check the interface implemented by export, and, if ´ListInterface´ is used, return an empty array * @internal This class check the interface implemented by export, and, if ´ListInterface´ is used, return an empty array
* *
* @return AggregatorInterface[] a \Generator that contains aggretagors. The key is the filter's alias * @return null|iterable<string, AggregatorInterface> a \Generator that contains aggretagors. The key is the filter's alias
*/ */
public function &getAggregatorsApplyingOn(ExportInterface $export, ?array $centers = null) public function &getAggregatorsApplyingOn(ExportInterface|DirectExportInterface $export, ?array $centers = null): ?iterable
{ {
if ($export instanceof ListInterface) { if ($export instanceof ListInterface || $export instanceof DirectExportInterface) {
return; return;
} }
@ -149,7 +152,7 @@ class ExportManager
} }
} }
public function addExportElementsProvider(ExportElementsProviderInterface $provider, $prefix) public function addExportElementsProvider(ExportElementsProviderInterface $provider, string $prefix): void
{ {
foreach ($provider->getExportElements() as $suffix => $element) { foreach ($provider->getExportElements() as $suffix => $element) {
$alias = $prefix . '_' . $suffix; $alias = $prefix . '_' . $suffix;
@ -173,23 +176,16 @@ class ExportManager
* add a formatter. * add a formatter.
* *
* @internal used by DI * @internal used by DI
*
* @param string $alias
*/ */
public function addFormatter(FormatterInterface $formatter, $alias) public function addFormatter(FormatterInterface $formatter, string $alias)
{ {
$this->formatters[$alias] = $formatter; $this->formatters[$alias] = $formatter;
} }
/** /**
* Generate a response which contains the requested data. * Generate a response which contains the requested data.
*
* @param string $exportAlias
* @param mixed[] $data
*
* @return Response
*/ */
public function generate($exportAlias, array $pickedCentersData, array $data, array $formatterData) public function generate(string $exportAlias, array $pickedCentersData, array $data, array $formatterData): Response
{ {
$export = $this->getExport($exportAlias); $export = $this->getExport($exportAlias);
$centers = $this->getPickedCenters($pickedCentersData); $centers = $this->getPickedCenters($pickedCentersData);
@ -288,7 +284,11 @@ class ExportManager
return $this->aggregators[$alias]; return $this->aggregators[$alias];
} }
public function getAggregators(array $aliases) /**
* @param array $aliases
* @return iterable<string, AggregatorInterface>
*/
public function getAggregators(array $aliases): iterable
{ {
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
yield $alias => $this->getAggregator($alias); yield $alias => $this->getAggregator($alias);
@ -296,9 +296,11 @@ class ExportManager
} }
/** /**
* @return string[] the existing type for known exports * Get the types for known exports
*
* @return list<string> the existing type for known exports
*/ */
public function getExistingExportsTypes() public function getExistingExportsTypes(): array
{ {
$existingTypes = []; $existingTypes = [];
@ -317,10 +319,8 @@ class ExportManager
* @param string $alias * @param string $alias
* *
* @throws RuntimeException * @throws RuntimeException
*
* @return ExportInterface
*/ */
public function getExport($alias) public function getExport($alias): ExportInterface|DirectExportInterface
{ {
if (!array_key_exists($alias, $this->exports)) { if (!array_key_exists($alias, $this->exports)) {
throw new RuntimeException("The export with alias {$alias} is not known."); throw new RuntimeException("The export with alias {$alias} is not known.");
@ -334,9 +334,9 @@ class ExportManager
* *
* @param bool $whereUserIsGranted if true (default), restrict to user which are granted the right to execute the export * @param bool $whereUserIsGranted if true (default), restrict to user which are granted the right to execute the export
* *
* @return ExportInterface[] an array where export's alias are keys * @return iterable<string, ExportInterface|DirectExportInterface> an array where export's alias are keys
*/ */
public function getExports($whereUserIsGranted = true) public function getExports($whereUserIsGranted = true): iterable
{ {
foreach ($this->exports as $alias => $export) { foreach ($this->exports as $alias => $export) {
if ($whereUserIsGranted) { if ($whereUserIsGranted) {
@ -354,9 +354,9 @@ class ExportManager
* *
* @param bool $whereUserIsGranted * @param bool $whereUserIsGranted
* *
* @return array where keys are the groups's name and value is an array of exports * @return array<string, array<string, ExportInterface|DirectExportInterface>> where keys are the groups's name and value is an array of exports
*/ */
public function getExportsGrouped($whereUserIsGranted = true): array public function getExportsGrouped(bool $whereUserIsGranted = true): array
{ {
$groups = ['_' => []]; $groups = ['_' => []];
@ -375,10 +375,8 @@ class ExportManager
* @param string $alias * @param string $alias
* *
* @throws RuntimeException if the filter is not known * @throws RuntimeException if the filter is not known
*
* @return FilterInterface
*/ */
public function getFilter($alias) public function getFilter(string $alias): FilterInterface
{ {
if (!array_key_exists($alias, $this->filters)) { if (!array_key_exists($alias, $this->filters)) {
throw new RuntimeException("The filter with alias {$alias} is not known."); throw new RuntimeException("The filter with alias {$alias} is not known.");
@ -390,16 +388,17 @@ class ExportManager
/** /**
* get all filters. * get all filters.
* *
* @param Generator $aliases * @param array<string> $aliases
* @return iterable<string, FilterInterface> $aliases
*/ */
public function getFilters(array $aliases) public function getFilters(array $aliases): iterable
{ {
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
yield $alias => $this->getFilter($alias); yield $alias => $this->getFilter($alias);
} }
} }
public function getFormatter($alias) public function getFormatter(string $alias): FormatterInterface
{ {
if (!array_key_exists($alias, $this->formatters)) { if (!array_key_exists($alias, $this->formatters)) {
throw new RuntimeException("The formatter with alias {$alias} is not known."); throw new RuntimeException("The formatter with alias {$alias} is not known.");
@ -414,7 +413,7 @@ class ExportManager
* @param array $data the data from the export form * @param array $data the data from the export form
* @string the formatter alias|null * @string the formatter alias|null
*/ */
public function getFormatterAlias(array $data) public function getFormatterAlias(array $data): ?string
{ {
if (array_key_exists(ExportType::PICK_FORMATTER_KEY, $data)) { if (array_key_exists(ExportType::PICK_FORMATTER_KEY, $data)) {
return $data[ExportType::PICK_FORMATTER_KEY]['alias']; return $data[ExportType::PICK_FORMATTER_KEY]['alias'];
@ -426,9 +425,9 @@ class ExportManager
/** /**
* Get all formatters which supports one of the given types. * Get all formatters which supports one of the given types.
* *
* @return Generator * @return iterable<string, FormatterInterface>
*/ */
public function getFormattersByTypes(array $types) public function getFormattersByTypes(array $types): iterable
{ {
foreach ($this->formatters as $alias => $formatter) { foreach ($this->formatters as $alias => $formatter) {
if (in_array($formatter->getType(), $types, true)) { if (in_array($formatter->getType(), $types, true)) {
@ -445,7 +444,7 @@ class ExportManager
* *
* @return \Chill\MainBundle\Entity\Center[] the picked center * @return \Chill\MainBundle\Entity\Center[] the picked center
*/ */
public function getPickedCenters(array $data) public function getPickedCenters(array $data): array
{ {
return $data; return $data;
} }
@ -455,9 +454,9 @@ class ExportManager
* *
* @param array $data the data from the export form * @param array $data the data from the export form
* *
* @return string[] * @return list<string>
*/ */
public function getUsedAggregatorsAliases(array $data) public function getUsedAggregatorsAliases(array $data): array
{ {
$aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]); $aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]);
@ -471,9 +470,8 @@ class ExportManager
* @param \Chill\MainBundle\Export\ExportElementInterface $element * @param \Chill\MainBundle\Export\ExportElementInterface $element
* @param DirectExportInterface|ExportInterface $export * @param DirectExportInterface|ExportInterface $export
* *
* @return bool
*/ */
public function isGrantedForElement(ExportElementInterface $element, ?ExportElementInterface $export = null, ?array $centers = null) public function isGrantedForElement(ExportElementInterface $element, ?ExportElementInterface $export = null, ?array $centers = null): bool
{ {
if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) { if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) {
$role = $element->requiredRole(); $role = $element->requiredRole();
@ -548,13 +546,12 @@ class ExportManager
* Check for acl. If an user is not authorized to see an aggregator, throw an * Check for acl. If an user is not authorized to see an aggregator, throw an
* UnauthorizedException. * UnauthorizedException.
* *
* @param type $data
* @throw UnauthorizedHttpException if the user is not authorized * @throw UnauthorizedHttpException if the user is not authorized
*/ */
private function handleAggregators( private function handleAggregators(
ExportInterface $export, ExportInterface $export,
QueryBuilder $qb, QueryBuilder $qb,
$data, array $data,
array $center array $center
) { ) {
$aggregators = $this->retrieveUsedAggregators($data); $aggregators = $this->retrieveUsedAggregators($data);
@ -600,9 +597,9 @@ class ExportManager
/** /**
* @param mixed $data * @param mixed $data
* *
* @return AggregatorInterface[] * @return iterable<string, AggregatorInterface>
*/ */
private function retrieveUsedAggregators($data) private function retrieveUsedAggregators($data): iterable
{ {
if (null === $data) { if (null === $data) {
return []; return [];

View File

@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export; namespace Chill\MainBundle\Export;
use Symfony\Component\Form\FormBuilderInterface;
/** /**
* Interface for filters. * Interface for filters.
* *
@ -23,6 +25,16 @@ interface FilterInterface extends ModifierInterface
{ {
public const STRING_FORMAT = 'string'; public const STRING_FORMAT = 'string';
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
/**
* Get the default data, that can be use as "data" for the form
*/
public function getFormDefaultData(): array;
/** /**
* Describe the filtering action. * Describe the filtering action.
* *

View File

@ -86,6 +86,11 @@ class CSVFormatter implements FormatterInterface
} }
} }
public function getFormDefaultData(array $aggregatorAliases): array
{
return [];
}
public function gatherFiltersDescriptions() public function gatherFiltersDescriptions()
{ {
$descriptions = []; $descriptions = [];

View File

@ -85,10 +85,14 @@ class CSVListFormatter implements FormatterInterface
'expanded' => true, 'expanded' => true,
'multiple' => false, 'multiple' => false,
'label' => 'Add a number on first column', 'label' => 'Add a number on first column',
'data' => true,
]); ]);
} }
public function getFormDefaultData(array $aggregatorAliases): array
{
return ['numerotation' => true];
}
public function getName() public function getName()
{ {
return 'CSV vertical list'; return 'CSV vertical list';

View File

@ -84,6 +84,11 @@ class CSVPivotedListFormatter implements FormatterInterface
]); ]);
} }
public function getFormDefaultData(array $aggregatorAliases): array
{
return ['numerotation' => true];
}
public function getName() public function getName()
{ {
return 'CSV horizontal list'; return 'CSV horizontal list';

View File

@ -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(

View File

@ -104,10 +104,14 @@ class SpreadsheetListFormatter implements FormatterInterface
'expanded' => true, 'expanded' => true,
'multiple' => false, 'multiple' => false,
'label' => 'Add a number on first column', 'label' => 'Add a number on first column',
'data' => true,
]); ]);
} }
public function getFormDefaultData(array $aggregatorAliases): array
{
return ['numerotation' => true, 'format' => 'xlsx'];
}
public function getName() public function getName()
{ {
return 'Spreadsheet list formatter (.xlsx, .ods)'; return 'Spreadsheet list formatter (.xlsx, .ods)';

View File

@ -34,6 +34,11 @@ interface FormatterInterface
array $aggregatorAliases array $aggregatorAliases
); );
/**
* get the default data for the form build by buildForm
*/
public function getFormDefaultData(array $aggregatorAliases): array;
public function getName(); public function getName();
/** /**

View File

@ -20,35 +20,23 @@ use Symfony\Component\Form\FormInterface;
use function array_key_exists; use function array_key_exists;
use function count; use function count;
class ExportPickCenterDataMapper implements DataMapperInterface final readonly class ExportPickCenterDataMapper implements DataMapperInterface
{ {
protected RegroupmentRepository $regroupmentRepository; public function mapDataToForms($viewData, $forms): void
public function mapDataToForms($data, $forms): void
{ {
if (null === $data) { if (null === $viewData) {
return; return;
} }
/** @var array<string, FormInterface> $form */ /** @var array<string, FormInterface> $form */
$form = iterator_to_array($forms); $form = iterator_to_array($forms);
$pickedRegroupment = []; $form['center']->setData($viewData);
foreach ($this->regroupmentRepository->findAll() as $regroupment) { // NOTE: we do not map back the regroupments
/** @phpstan-ignore-next-line */
[$contained, $notContained] = $regroupment->getCenters()->partition(static fn (Center $center): bool => false);
if (0 === count($notContained)) {
$pickedRegroupment[] = $regroupment;
}
}
$form['regroupment']->setData($pickedRegroupment);
$form['centers']->setData($data);
} }
public function mapFormsToData($forms, &$data): void public function mapFormsToData($forms, &$viewData): void
{ {
/** @var array<string, FormInterface> $forms */ /** @var array<string, FormInterface> $forms */
$forms = iterator_to_array($forms); $forms = iterator_to_array($forms);
@ -68,6 +56,6 @@ class ExportPickCenterDataMapper implements DataMapperInterface
} }
} }
$data = array_values($centers); $viewData = array_values($centers);
} }
} }

View File

@ -32,7 +32,6 @@ class AggregatorType extends AbstractType
->add('enabled', CheckboxType::class, [ ->add('enabled', CheckboxType::class, [
'value' => true, 'value' => true,
'required' => false, 'required' => false,
'data' => false,
]); ]);
$filterFormBuilder = $builder->create('form', FormType::class, [ $filterFormBuilder = $builder->create('form', FormType::class, [

View File

@ -33,7 +33,6 @@ class FilterType extends AbstractType
$builder $builder
->add(self::ENABLED_FIELD, CheckboxType::class, [ ->add(self::ENABLED_FIELD, CheckboxType::class, [
'value' => true, 'value' => true,
'data' => false,
'required' => false, 'required' => false,
]); ]);

View File

@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper; use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper;
use Chill\MainBundle\Repository\RegroupmentRepository; use Chill\MainBundle\Repository\RegroupmentRepository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
@ -33,22 +34,18 @@ final class PickCenterType extends AbstractType
{ {
public const CENTERS_IDENTIFIERS = 'c'; public const CENTERS_IDENTIFIERS = 'c';
private AuthorizationHelperInterface $authorizationHelper; private AuthorizationHelperForCurrentUserInterface $authorizationHelper;
private ExportManager $exportManager; private ExportManager $exportManager;
private RegroupmentRepository $regroupmentRepository; private RegroupmentRepository $regroupmentRepository;
private UserInterface $user;
public function __construct( public function __construct(
TokenStorageInterface $tokenStorage,
ExportManager $exportManager, ExportManager $exportManager,
RegroupmentRepository $regroupmentRepository, RegroupmentRepository $regroupmentRepository,
AuthorizationHelperInterface $authorizationHelper AuthorizationHelperForCurrentUserInterface $authorizationHelper
) { ) {
$this->exportManager = $exportManager; $this->exportManager = $exportManager;
$this->user = $tokenStorage->getToken()->getUser();
$this->authorizationHelper = $authorizationHelper; $this->authorizationHelper = $authorizationHelper;
$this->regroupmentRepository = $regroupmentRepository; $this->regroupmentRepository = $regroupmentRepository;
} }
@ -57,18 +54,16 @@ final class PickCenterType extends AbstractType
{ {
$export = $this->exportManager->getExport($options['export_alias']); $export = $this->exportManager->getExport($options['export_alias']);
$centers = $this->authorizationHelper->getReachableCenters( $centers = $this->authorizationHelper->getReachableCenters(
$this->user,
$export->requiredRole() $export->requiredRole()
); );
$builder->add('center', EntityType::class, [ $builder->add('center', EntityType::class, [
'class' => Center::class, 'class' => Center::class,
'label' => 'center',
'choices' => $centers, 'choices' => $centers,
'label' => 'center',
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
'choice_label' => static fn (Center $c) => $c->getName(), 'choice_label' => static fn (Center $c) => $c->getName(),
'data' => $centers,
]); ]);
if (count($this->regroupmentRepository->findAllActive()) > 0) { if (count($this->regroupmentRepository->findAllActive()) > 0) {

View File

@ -47,8 +47,6 @@ class PickFormatterType extends AbstractType
'multiple' => false, 'multiple' => false,
'placeholder' => 'Choose a format', 'placeholder' => 'Choose a format',
]); ]);
//$builder->get('type')->addModelTransformer($transformer);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View File

@ -53,9 +53,23 @@ window.addEventListener("DOMContentLoaded", function(e) {
<li class="cancel"><a href="{{ chill_return_path_or('chill_main_export_index') }}" class="btn btn-cancel">{{ 'Back to the list'|trans }}</a></li> <li class="cancel"><a href="{{ chill_return_path_or('chill_main_export_index') }}" class="btn btn-cancel">{{ 'Back to the list'|trans }}</a></li>
{% if not app.request.query.has('prevent_save') %} {% if not app.request.query.has('prevent_save') %}
{% if saved_export is null %}
<li> <li>
<a href="{{ chill_path_add_return_path('chill_main_export_save_from_key', { alias: alias, key: app.request.query.get('key')}) }}" class="btn btn-save">{{ 'Save'|trans }}</a> <a href="{{ chill_path_add_return_path('chill_main_export_save_from_key', { alias: alias, key: app.request.query.get('key')}) }}" class="btn btn-save">{{ 'Save'|trans }}</a>
</li> </li>
{% else %}
<li>
<div class="dropdown">
<button class="btn btn-save dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ 'Save'|trans }}
</button>
<ul class="dropdown-menu">
<li><a href="{{ chill_path_add_return_path('chill_main_export_save_from_key', { alias: alias, key: app.request.query.get('key')}) }}" class="dropdown-item">{{ 'Save'|trans }}</a></li>
<li><a href="{{ chill_path_add_return_path('chill_main_export_saved_edit_options_from_key', { id: saved_export.id(), key: app.request.query.get('key') }) }}" class="dropdown-item">{{ 'saved_export.Update existing'|trans }}</a></li>
</ul>
</div>
</li>
{% endif %}
{% endif %} {% endif %}
</ul> </ul>
</div> </div>

Some files were not shown because too many files have changed in this diff Show More