mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
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:
commit
01dee54fab
6
.changes/unreleased/Feature-20230606-105153.yaml
Normal file
6
.changes/unreleased/Feature-20230606-105153.yaml
Normal 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"
|
6
.changes/unreleased/Feature-20230627-111222.yaml
Normal file
6
.changes/unreleased/Feature-20230627-111222.yaml
Normal 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: ""
|
6
.changes/unreleased/Feature-20230627-155925.yaml
Normal file
6
.changes/unreleased/Feature-20230627-155925.yaml
Normal 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: ""
|
@ -13,6 +13,7 @@ $finder = PhpCsFixer\Finder::create();
|
||||
|
||||
$finder
|
||||
->in(__DIR__.'/src')
|
||||
->in(__DIR__.'/utils')
|
||||
->append([__FILE__])
|
||||
->exclude(['docs/', 'tests/app'])
|
||||
->notPath('tests/app')
|
||||
|
@ -67,6 +67,7 @@
|
||||
"fakerphp/faker": "^1.13",
|
||||
"jangregor/phpstan-prophecy": "^1.0",
|
||||
"nelmio/alice": "^3.8",
|
||||
"nikic/php-parser": "^4.15",
|
||||
"phpspec/prophecy-phpunit": "^2.0",
|
||||
"phpstan/extension-installer": "^1.2",
|
||||
"phpstan/phpstan": "^1.9",
|
||||
@ -103,14 +104,16 @@
|
||||
"Chill\\ReportBundle\\": "src/Bundle/ChillReportBundle",
|
||||
"Chill\\TaskBundle\\": "src/Bundle/ChillTaskBundle",
|
||||
"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": {
|
||||
"psr-4": {
|
||||
"App\\": "tests/app/src/",
|
||||
"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": {
|
||||
|
@ -62,7 +62,6 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
{
|
||||
$builder->add('date_from', DateType::class, [
|
||||
'label' => 'Born after this date',
|
||||
'data' => new DateTime(),
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
@ -70,12 +69,15 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
|
||||
|
||||
$builder->add('date_to', DateType::class, [
|
||||
'label' => 'Born before this date',
|
||||
'data' => new DateTime(),
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'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
|
||||
// the filter in the Response
|
||||
|
@ -36,6 +36,10 @@ class CountPerson implements ExportInterface
|
||||
{
|
||||
// this export does not add any form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -2,6 +2,7 @@ parameters:
|
||||
level: 5
|
||||
paths:
|
||||
- src/
|
||||
- utils/
|
||||
tmpDir: .cache/
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
excludePaths:
|
||||
|
29
phpunit.rector.xml
Normal file
29
phpunit.rector.xml
Normal 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>
|
@ -24,6 +24,9 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
LevelSetList::UP_TO_PHP_74
|
||||
]);
|
||||
|
||||
// chill rules
|
||||
$rectorConfig->rule(\Chill\Utils\Rector\Rector\ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector::class);
|
||||
|
||||
// skip some path...
|
||||
$rectorConfig->skip([
|
||||
// make rector stuck for some files
|
||||
|
@ -40,6 +40,10 @@ class ByActivityNumberAggregator implements AggregatorInterface
|
||||
{
|
||||
// No form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -52,6 +52,10 @@ class ByCreatorAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class BySocialActionAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class BySocialIssueAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class ByThirdpartyAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class CreatorScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -29,14 +29,6 @@ class DateAggregator implements AggregatorInterface
|
||||
|
||||
private const DEFAULT_CHOICE = 'year';
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
@ -84,9 +76,12 @@ class DateAggregator implements AggregatorInterface
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'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)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class LocationTypeAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -60,6 +60,10 @@ class ActivityTypeAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form required for this aggregator
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ class ActivityUserAggregator implements AggregatorInterface
|
||||
{
|
||||
// nothing to add
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, $values, $data): Closure
|
||||
{
|
||||
|
@ -56,6 +56,10 @@ class ActivityUsersAggregator implements AggregatorInterface
|
||||
{
|
||||
// nothing to add on the form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -55,6 +55,10 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI
|
||||
{
|
||||
// nothing to add in the form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -55,6 +55,10 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato
|
||||
{
|
||||
// nothing to add in the form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -110,6 +110,10 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali
|
||||
]
|
||||
);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -47,6 +47,10 @@ class SentReceivedAggregator implements AggregatorInterface
|
||||
{
|
||||
// No form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): callable
|
||||
{
|
||||
|
@ -39,6 +39,10 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -40,6 +40,10 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -39,6 +39,10 @@ class CountActivity implements ExportInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -44,6 +44,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
|
||||
{
|
||||
$this->helper->buildForm($builder);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -40,6 +40,10 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -40,6 +40,10 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -35,6 +35,10 @@ class CountActivity implements ExportInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -88,6 +88,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
|
||||
])],
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -53,6 +53,10 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -68,6 +68,10 @@ class ActivityTypeFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -52,6 +52,10 @@ class ByCreatorFilter implements FilterInterface
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -60,6 +60,10 @@ class BySocialActionFilter implements FilterInterface
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -60,6 +60,10 @@ class BySocialIssueFilter implements FilterInterface
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -68,9 +68,12 @@ class EmergencyFilter implements FilterInterface
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'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
|
||||
{
|
||||
|
@ -44,6 +44,10 @@ class HasNoActivityFilter implements FilterInterface
|
||||
{
|
||||
//no form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -46,6 +46,10 @@ class LocationFilter implements FilterInterface
|
||||
'label' => 'pick location',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -65,6 +65,10 @@ class LocationTypeFilter implements FilterInterface
|
||||
//'label' => false,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -69,9 +69,12 @@ class SentReceivedFilter implements FilterInterface
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'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
|
||||
{
|
||||
|
@ -61,6 +61,10 @@ class UserFilter implements FilterInterface
|
||||
'label' => 'Creators',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -71,6 +71,10 @@ class UserScopeFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -80,11 +80,9 @@ class ActivityDateFilter implements FilterInterface
|
||||
$builder
|
||||
->add('date_from', PickRollingDateType::class, [
|
||||
'label' => 'Activities after this date',
|
||||
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
|
||||
])
|
||||
->add('date_to', PickRollingDateType::class, [
|
||||
'label' => 'Activities before this date',
|
||||
'data' => new RollingDate(RollingDate::T_TODAY),
|
||||
]);
|
||||
|
||||
$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')
|
||||
{
|
||||
|
@ -78,6 +78,10 @@ class ActivityTypeFilter implements ExportElementValidatedInterface, FilterInter
|
||||
],
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -56,6 +56,10 @@ class ActivityUsersFilter implements FilterInterface
|
||||
'label' => 'Users',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -82,6 +82,10 @@ class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInt
|
||||
'expanded' => false,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -112,7 +112,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
|
||||
{
|
||||
$builder->add('date_from', DateType::class, [
|
||||
'label' => 'Implied in an activity after this date',
|
||||
'data' => new DateTime(),
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
@ -120,7 +119,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
|
||||
|
||||
$builder->add('date_to', DateType::class, [
|
||||
'label' => 'Implied in an activity before this date',
|
||||
'data' => new DateTime(),
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
@ -130,7 +128,6 @@ class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInt
|
||||
'class' => ActivityReason::class,
|
||||
'choice_label' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()),
|
||||
'group_by' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()),
|
||||
'data' => $this->activityReasonRepository->findAll(),
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'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')
|
||||
{
|
||||
|
@ -60,6 +60,10 @@ class UsersJobFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -67,6 +67,10 @@ class UsersScopeFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -50,6 +50,10 @@ class ByActivityTypeAggregator implements AggregatorInterface
|
||||
{
|
||||
// No form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class ByUserJobAggregator implements AggregatorInterface
|
||||
{
|
||||
// nothing to add in the form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -57,6 +57,10 @@ class ByUserScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
// nothing to add in the form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
|
@ -34,6 +34,10 @@ class AvgAsideActivityDuration implements ExportInterface, GroupedExportInterfac
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -34,6 +34,10 @@ class CountAsideActivity implements ExportInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -73,6 +73,10 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
|
@ -34,6 +34,10 @@ class SumAsideActivityDuration implements ExportInterface, GroupedExportInterfac
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -76,6 +76,10 @@ class ByActivityTypeFilter implements FilterInterface
|
||||
},
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -72,11 +72,9 @@ class ByDateFilter implements FilterInterface
|
||||
$builder
|
||||
->add('date_from', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.Aside activities after this date',
|
||||
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
|
||||
])
|
||||
->add('date_to', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.Aside activities before this date',
|
||||
'data' => new RollingDate(RollingDate::T_TODAY),
|
||||
]);
|
||||
|
||||
$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
|
||||
{
|
||||
|
@ -53,6 +53,10 @@ class ByUserFilter implements FilterInterface
|
||||
'label' => 'Creators',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -60,6 +60,10 @@ class ByUserJobFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -67,6 +67,10 @@ class ByUserScopeFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ final class AgentAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -59,6 +59,10 @@ class CancelReasonAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ final class JobAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -52,6 +52,10 @@ final class LocationAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ final class LocationTypeAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -40,6 +40,10 @@ class MonthYearAggregator implements AggregatorInterface
|
||||
{
|
||||
// No form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -58,6 +58,10 @@ final class ScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -56,6 +56,10 @@ class UrgencyAggregator implements AggregatorInterface
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
{
|
||||
|
@ -36,6 +36,10 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
// No form necessary
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -36,6 +36,10 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
// no form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -36,6 +36,10 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
// no form needed
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes(): array
|
||||
{
|
||||
|
@ -63,6 +63,10 @@ class AgentFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -60,12 +60,12 @@ class BetweenDatesFilter implements FilterInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('date_from', PickRollingDateType::class, [
|
||||
'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
|
||||
])
|
||||
->add('date_to', PickRollingDateType::class, [
|
||||
'data' => new RollingDate(RollingDate::T_TODAY),
|
||||
]);
|
||||
->add('date_from', PickRollingDateType::class, [])
|
||||
->add('date_to', PickRollingDateType::class, []);
|
||||
}
|
||||
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
|
||||
|
@ -69,9 +69,12 @@ class CalendarRangeFilter implements FilterInterface
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'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
|
||||
{
|
||||
|
@ -76,6 +76,10 @@ class JobFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
|
@ -76,6 +76,10 @@ class ScopeFilter implements FilterInterface
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
|
@ -13,12 +13,16 @@ namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\SavedExport;
|
||||
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\Form\SavedExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\FormatterType;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Chill\MainBundle\Redis\ChillRedis;
|
||||
use Chill\MainBundle\Repository\SavedExportRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\SavedExportVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use LogicException;
|
||||
@ -36,6 +40,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function count;
|
||||
use function serialize;
|
||||
@ -86,7 +91,10 @@ class ExportController extends AbstractController
|
||||
LoggerInterface $logger,
|
||||
SessionInterface $session,
|
||||
TranslatorInterface $translator,
|
||||
EntityManagerInterface $entityManager
|
||||
EntityManagerInterface $entityManager,
|
||||
private readonly ExportFormHelper $exportFormHelper,
|
||||
private readonly SavedExportRepositoryInterface $savedExportRepository,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->redis = $chillRedis;
|
||||
@ -101,12 +109,11 @@ class ExportController extends AbstractController
|
||||
{
|
||||
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
|
||||
$export = $exportManager->getExport($alias);
|
||||
|
||||
$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']);
|
||||
|
||||
@ -120,6 +127,7 @@ class ExportController extends AbstractController
|
||||
'alias' => $alias,
|
||||
'export' => $export,
|
||||
'export_group' => $this->getExportGroup($export),
|
||||
'saved_export' => $savedExport,
|
||||
];
|
||||
|
||||
if ($formater instanceof \Chill\MainBundle\Export\Formatter\CSVListFormatter) {
|
||||
@ -144,8 +152,9 @@ class ExportController extends AbstractController
|
||||
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
$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(
|
||||
$alias,
|
||||
@ -204,12 +213,8 @@ class ExportController extends AbstractController
|
||||
* 3. 'generate': gather data from session from the previous steps, and
|
||||
* 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
|
||||
$exportManager = $this->exportManager;
|
||||
@ -219,26 +224,50 @@ class ExportController extends AbstractController
|
||||
throw $this->createAccessDeniedException('The user does not have access to this export');
|
||||
}
|
||||
|
||||
$savedExport = $this->getSavedExportFromRequest($request);
|
||||
|
||||
$step = $request->query->getAlpha('step', 'centers');
|
||||
|
||||
switch ($step) {
|
||||
case 'centers':
|
||||
return $this->selectCentersStep($request, $export, $alias);
|
||||
return $this->selectCentersStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'export':
|
||||
return $this->exportFormStep($request, $export, $alias);
|
||||
return $this->exportFormStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'formatter':
|
||||
return $this->formatterFormStep($request, $export, $alias);
|
||||
return $this->formatterFormStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'generate':
|
||||
return $this->forwardToGenerate($request, $export, $alias);
|
||||
return $this->forwardToGenerate($request, $export, $alias, $savedExport);
|
||||
|
||||
default:
|
||||
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")
|
||||
*/
|
||||
@ -282,45 +311,55 @@ class ExportController extends AbstractController
|
||||
/**
|
||||
* 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 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 */
|
||||
$exportManager = $this->exportManager;
|
||||
$isGenerate = strpos($step, 'generate_') === 0;
|
||||
|
||||
$builder = $this->formFactory
|
||||
->createNamedBuilder(null, FormType::class, [], [
|
||||
'method' => $isGenerate ? 'GET' : 'POST',
|
||||
'csrf_protection' => $isGenerate ? false : true,
|
||||
]);
|
||||
$options = match ($step) {
|
||||
'export', 'generate_export' => [
|
||||
'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,
|
||||
],
|
||||
};
|
||||
|
||||
// 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) {
|
||||
$builder->add('centers', PickCenterType::class, [
|
||||
'export_alias' => $alias,
|
||||
]);
|
||||
$builder->add('centers', PickCenterType::class, $options);
|
||||
}
|
||||
|
||||
if ('export' === $step || 'generate_export' === $step) {
|
||||
$builder->add('export', ExportType::class, [
|
||||
'export_alias' => $alias,
|
||||
'picked_centers' => $exportManager->getPickedCenters($data['centers']),
|
||||
]);
|
||||
$builder->add('export', ExportType::class, $options);
|
||||
}
|
||||
|
||||
if ('formatter' === $step || 'generate_formatter' === $step) {
|
||||
$builder->add('formatter', FormatterType::class, [
|
||||
'formatter_alias' => $exportManager
|
||||
->getFormatterAlias($data['export']),
|
||||
'export_alias' => $alias,
|
||||
'aggregator_aliases' => $exportManager
|
||||
->getUsedAggregatorsAliases($data['export']),
|
||||
]);
|
||||
$builder->add('formatter', FormatterType::class, $options);
|
||||
}
|
||||
|
||||
$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
|
||||
* 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;
|
||||
|
||||
@ -357,7 +391,7 @@ class ExportController extends AbstractController
|
||||
|
||||
$export = $exportManager->getExport($alias);
|
||||
|
||||
$form = $this->createCreateFormExport($alias, 'export', $data);
|
||||
$form = $this->createCreateFormExport($alias, 'export', $data, $savedExport);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
$form->handleRequest($request);
|
||||
@ -379,6 +413,7 @@ class ExportController extends AbstractController
|
||||
$this->generateUrl('chill_main_export_new', [
|
||||
'step' => $this->getNextStep('export', $export),
|
||||
'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
|
||||
* 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)
|
||||
$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') {
|
||||
$form->handleRequest($request);
|
||||
@ -436,6 +466,7 @@ class ExportController extends AbstractController
|
||||
[
|
||||
'alias' => $alias,
|
||||
'step' => $this->getNextStep('formatter', $export),
|
||||
'from_saved' => $request->get('from_saved', ''),
|
||||
]
|
||||
));
|
||||
}
|
||||
@ -462,7 +493,7 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* @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);
|
||||
$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) {
|
||||
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');
|
||||
|
||||
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);
|
||||
|
||||
$alias = $rawData['alias'];
|
||||
|
||||
$formCenters = $this->createCreateFormExport($alias, 'generate_centers');
|
||||
$formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport);
|
||||
$formCenters->submit($rawData['centers']);
|
||||
$dataCenters = $formCenters->getData();
|
||||
|
||||
$formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters);
|
||||
$formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters, $savedExport);
|
||||
$formExport->submit($rawData['export']);
|
||||
$dataExport = $formExport->getData();
|
||||
|
||||
@ -512,7 +549,8 @@ class ExportController extends AbstractController
|
||||
$formFormatter = $this->createCreateFormExport(
|
||||
$alias,
|
||||
'generate_formatter',
|
||||
$dataExport
|
||||
$dataExport,
|
||||
$savedExport
|
||||
);
|
||||
$formFormatter->submit($rawData['formatter']);
|
||||
$dataFormatter = $formFormatter->getData();
|
||||
@ -527,12 +565,12 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* @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 */
|
||||
$exportManager = $this->exportManager;
|
||||
|
||||
$form = $this->createCreateFormExport($alias, 'centers');
|
||||
$form = $this->createCreateFormExport($alias, 'centers', [], $savedExport);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
$form->handleRequest($request);
|
||||
@ -564,6 +602,7 @@ class ExportController extends AbstractController
|
||||
return $this->redirectToRoute('chill_main_export_new', [
|
||||
'step' => $this->getNextStep('centers', $export),
|
||||
'alias' => $alias,
|
||||
'from_saved' => $request->get('from_saved', ''),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -670,4 +709,18 @@ class ExportController extends AbstractController
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Closure;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for Aggregators.
|
||||
@ -21,6 +22,16 @@ use Closure;
|
||||
*/
|
||||
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
|
||||
* viewable and understable string.
|
||||
|
@ -11,10 +11,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -19,11 +19,6 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
*/
|
||||
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).
|
||||
*
|
||||
|
171
src/Bundle/ChillMainBundle/Export/ExportFormHelper.php
Normal file
171
src/Bundle/ChillMainBundle/Export/ExportFormHelper.php
Normal 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();
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace Chill\MainBundle\Export;
|
||||
|
||||
use Doctrine\ORM\NativeQuery;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for Export.
|
||||
@ -28,6 +29,16 @@ use Doctrine\ORM\QueryBuilder;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -12,7 +12,6 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Generator;
|
||||
@ -114,8 +113,12 @@ class ExportManager
|
||||
*
|
||||
* @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) {
|
||||
if (
|
||||
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
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
$alias = $prefix . '_' . $suffix;
|
||||
@ -173,23 +176,16 @@ class ExportManager
|
||||
* add a formatter.
|
||||
*
|
||||
* @internal used by DI
|
||||
*
|
||||
* @param string $alias
|
||||
*/
|
||||
public function addFormatter(FormatterInterface $formatter, $alias)
|
||||
public function addFormatter(FormatterInterface $formatter, string $alias)
|
||||
{
|
||||
$this->formatters[$alias] = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$centers = $this->getPickedCenters($pickedCentersData);
|
||||
@ -288,7 +284,11 @@ class ExportManager
|
||||
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) {
|
||||
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 = [];
|
||||
|
||||
@ -317,10 +319,8 @@ class ExportManager
|
||||
* @param string $alias
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*
|
||||
* @return ExportInterface
|
||||
*/
|
||||
public function getExport($alias)
|
||||
public function getExport($alias): ExportInterface|DirectExportInterface
|
||||
{
|
||||
if (!array_key_exists($alias, $this->exports)) {
|
||||
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
|
||||
*
|
||||
* @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) {
|
||||
if ($whereUserIsGranted) {
|
||||
@ -354,9 +354,9 @@ class ExportManager
|
||||
*
|
||||
* @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 = ['_' => []];
|
||||
|
||||
@ -375,10 +375,8 @@ class ExportManager
|
||||
* @param string $alias
|
||||
*
|
||||
* @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)) {
|
||||
throw new RuntimeException("The filter with alias {$alias} is not known.");
|
||||
@ -390,16 +388,17 @@ class ExportManager
|
||||
/**
|
||||
* 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) {
|
||||
yield $alias => $this->getFilter($alias);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormatter($alias)
|
||||
public function getFormatter(string $alias): FormatterInterface
|
||||
{
|
||||
if (!array_key_exists($alias, $this->formatters)) {
|
||||
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
|
||||
* @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)) {
|
||||
return $data[ExportType::PICK_FORMATTER_KEY]['alias'];
|
||||
@ -426,9 +425,9 @@ class ExportManager
|
||||
/**
|
||||
* 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) {
|
||||
if (in_array($formatter->getType(), $types, true)) {
|
||||
@ -445,7 +444,7 @@ class ExportManager
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\Center[] the picked center
|
||||
*/
|
||||
public function getPickedCenters(array $data)
|
||||
public function getPickedCenters(array $data): array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
@ -455,9 +454,9 @@ class ExportManager
|
||||
*
|
||||
* @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]);
|
||||
|
||||
@ -471,9 +470,8 @@ class ExportManager
|
||||
* @param \Chill\MainBundle\Export\ExportElementInterface $element
|
||||
* @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) {
|
||||
$role = $element->requiredRole();
|
||||
@ -548,13 +546,12 @@ class ExportManager
|
||||
* Check for acl. If an user is not authorized to see an aggregator, throw an
|
||||
* UnauthorizedException.
|
||||
*
|
||||
* @param type $data
|
||||
* @throw UnauthorizedHttpException if the user is not authorized
|
||||
*/
|
||||
private function handleAggregators(
|
||||
ExportInterface $export,
|
||||
QueryBuilder $qb,
|
||||
$data,
|
||||
array $data,
|
||||
array $center
|
||||
) {
|
||||
$aggregators = $this->retrieveUsedAggregators($data);
|
||||
@ -600,9 +597,9 @@ class ExportManager
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return AggregatorInterface[]
|
||||
* @return iterable<string, AggregatorInterface>
|
||||
*/
|
||||
private function retrieveUsedAggregators($data)
|
||||
private function retrieveUsedAggregators($data): iterable
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
|
@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for filters.
|
||||
*
|
||||
@ -23,6 +25,16 @@ interface FilterInterface extends ModifierInterface
|
||||
{
|
||||
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.
|
||||
*
|
||||
|
@ -86,6 +86,11 @@ class CSVFormatter implements FormatterInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormDefaultData(array $aggregatorAliases): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function gatherFiltersDescriptions()
|
||||
{
|
||||
$descriptions = [];
|
||||
|
@ -85,10 +85,14 @@ class CSVListFormatter implements FormatterInterface
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
'label' => 'Add a number on first column',
|
||||
'data' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(array $aggregatorAliases): array
|
||||
{
|
||||
return ['numerotation' => true];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'CSV vertical list';
|
||||
|
@ -84,6 +84,11 @@ class CSVPivotedListFormatter implements FormatterInterface
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(array $aggregatorAliases): array
|
||||
{
|
||||
return ['numerotation' => true];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'CSV horizontal list';
|
||||
|
@ -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)';
|
||||
}
|
||||
@ -185,7 +197,7 @@ class SpreadSheetFormatter implements FormatterInterface
|
||||
array $exportData,
|
||||
array $filtersData,
|
||||
array $aggregatorsData
|
||||
) {
|
||||
): Response {
|
||||
// store all data when the process is initiated
|
||||
$this->result = $result;
|
||||
$this->formatterData = $formatterData;
|
||||
@ -574,10 +586,8 @@ class SpreadSheetFormatter implements FormatterInterface
|
||||
*
|
||||
* This form allow to choose the aggregator position (row or column) and
|
||||
* the ordering
|
||||
*
|
||||
* @param string $nbAggregators
|
||||
*/
|
||||
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
||||
private function appendAggregatorForm(FormBuilderInterface $builder, int $nbAggregators): void
|
||||
{
|
||||
$builder->add('order', ChoiceType::class, [
|
||||
'choices' => array_combine(
|
||||
|
@ -104,10 +104,14 @@ class SpreadsheetListFormatter implements FormatterInterface
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
'label' => 'Add a number on first column',
|
||||
'data' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(array $aggregatorAliases): array
|
||||
{
|
||||
return ['numerotation' => true, 'format' => 'xlsx'];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Spreadsheet list formatter (.xlsx, .ods)';
|
||||
|
@ -34,6 +34,11 @@ interface FormatterInterface
|
||||
array $aggregatorAliases
|
||||
);
|
||||
|
||||
/**
|
||||
* get the default data for the form build by buildForm
|
||||
*/
|
||||
public function getFormDefaultData(array $aggregatorAliases): array;
|
||||
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
|
@ -20,35 +20,23 @@ use Symfony\Component\Form\FormInterface;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
final readonly class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
{
|
||||
protected RegroupmentRepository $regroupmentRepository;
|
||||
|
||||
public function mapDataToForms($data, $forms): void
|
||||
public function mapDataToForms($viewData, $forms): void
|
||||
{
|
||||
if (null === $data) {
|
||||
if (null === $viewData) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var array<string, FormInterface> $form */
|
||||
$form = iterator_to_array($forms);
|
||||
|
||||
$pickedRegroupment = [];
|
||||
$form['center']->setData($viewData);
|
||||
|
||||
foreach ($this->regroupmentRepository->findAll() as $regroupment) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
[$contained, $notContained] = $regroupment->getCenters()->partition(static fn (Center $center): bool => false);
|
||||
|
||||
if (0 === count($notContained)) {
|
||||
$pickedRegroupment[] = $regroupment;
|
||||
}
|
||||
// NOTE: we do not map back the regroupments
|
||||
}
|
||||
|
||||
$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 */
|
||||
$forms = iterator_to_array($forms);
|
||||
@ -68,6 +56,6 @@ class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
}
|
||||
}
|
||||
|
||||
$data = array_values($centers);
|
||||
$viewData = array_values($centers);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ class AggregatorType extends AbstractType
|
||||
->add('enabled', CheckboxType::class, [
|
||||
'value' => true,
|
||||
'required' => false,
|
||||
'data' => false,
|
||||
]);
|
||||
|
||||
$filterFormBuilder = $builder->create('form', FormType::class, [
|
||||
|
@ -33,7 +33,6 @@ class FilterType extends AbstractType
|
||||
$builder
|
||||
->add(self::ENABLED_FIELD, CheckboxType::class, [
|
||||
'value' => true,
|
||||
'data' => false,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
|
@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Regroupment;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper;
|
||||
use Chill\MainBundle\Repository\RegroupmentRepository;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@ -33,22 +34,18 @@ final class PickCenterType extends AbstractType
|
||||
{
|
||||
public const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelper;
|
||||
|
||||
private ExportManager $exportManager;
|
||||
|
||||
private RegroupmentRepository $regroupmentRepository;
|
||||
|
||||
private UserInterface $user;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
ExportManager $exportManager,
|
||||
RegroupmentRepository $regroupmentRepository,
|
||||
AuthorizationHelperInterface $authorizationHelper
|
||||
AuthorizationHelperForCurrentUserInterface $authorizationHelper
|
||||
) {
|
||||
$this->exportManager = $exportManager;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->regroupmentRepository = $regroupmentRepository;
|
||||
}
|
||||
@ -57,18 +54,16 @@ final class PickCenterType extends AbstractType
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->user,
|
||||
$export->requiredRole()
|
||||
);
|
||||
|
||||
$builder->add('center', EntityType::class, [
|
||||
'class' => Center::class,
|
||||
'label' => 'center',
|
||||
'choices' => $centers,
|
||||
'label' => 'center',
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choice_label' => static fn (Center $c) => $c->getName(),
|
||||
'data' => $centers,
|
||||
]);
|
||||
|
||||
if (count($this->regroupmentRepository->findAllActive()) > 0) {
|
||||
|
@ -47,8 +47,6 @@ class PickFormatterType extends AbstractType
|
||||
'multiple' => false,
|
||||
'placeholder' => 'Choose a format',
|
||||
]);
|
||||
|
||||
//$builder->get('type')->addModelTransformer($transformer);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
@ -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>
|
||||
|
||||
{% if not app.request.query.has('prevent_save') %}
|
||||
{% if saved_export is null %}
|
||||
<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>
|
||||
</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 %}
|
||||
</ul>
|
||||
</div>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user