From ccf3324bc268c4b165134c301a9ed9fe9b616bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 15 Mar 2024 15:02:12 +0100 Subject: [PATCH] Refactor ListPersonHelper and ListPerson to simplify process and allow to add customization of fields --- .../unreleased/Feature-20240319-172100.yaml | 5 + .../ChillPersonBundle/ChillPersonBundle.php | 3 + .../Export/Export/ListPerson.php | 110 ++--------------- .../ListPersonHavingAccompanyingPeriod.php | 91 +------------- ...istPersonWithAccompanyingPeriodDetails.php | 2 +- .../CustomizeListPersonHelperInterface.php | 36 ++++++ .../Export/Helper/ListPersonHelper.php | 114 +++++++++++------- ...ListPersonHavingAccompanyingPeriodTest.php | 6 +- .../Tests/Export/Export/ListPersonTest.php | 14 +-- .../config/services/exports_person.yaml | 4 + 10 files changed, 134 insertions(+), 251 deletions(-) create mode 100644 .changes/unreleased/Feature-20240319-172100.yaml create mode 100644 src/Bundle/ChillPersonBundle/Export/Helper/CustomizeListPersonHelperInterface.php diff --git a/.changes/unreleased/Feature-20240319-172100.yaml b/.changes/unreleased/Feature-20240319-172100.yaml new file mode 100644 index 000000000..d50de48b3 --- /dev/null +++ b/.changes/unreleased/Feature-20240319-172100.yaml @@ -0,0 +1,5 @@ +kind: Feature +body: Allow to customize list person with new fields +time: 2024-03-19T17:21:00.873293991+01:00 +custom: + Issue: "238" diff --git a/src/Bundle/ChillPersonBundle/ChillPersonBundle.php b/src/Bundle/ChillPersonBundle/ChillPersonBundle.php index 8a48cccba..89477a47b 100644 --- a/src/Bundle/ChillPersonBundle/ChillPersonBundle.php +++ b/src/Bundle/ChillPersonBundle/ChillPersonBundle.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle; use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface; use Chill\PersonBundle\DependencyInjection\CompilerPass\AccompanyingPeriodTimelineCompilerPass; +use Chill\PersonBundle\Export\Helper\CustomizeListPersonHelperInterface; use Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoUnionQueryPartInterface; use Chill\PersonBundle\Widget\PersonListWidgetFactory; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -32,5 +33,7 @@ class ChillPersonBundle extends Bundle ->addTag('chill_person.accompanying_period_info_part'); $container->registerForAutoconfiguration(PersonMoveSqlHandlerInterface::class) ->addTag('chill_person.person_move_handler'); + $container->registerForAutoconfiguration(CustomizeListPersonHelperInterface::class) + ->addTag('chill_person.list_person_customizer'); } } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php index 8529fac10..37b7ca7d7 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php @@ -14,10 +14,8 @@ namespace Chill\PersonBundle\Export\Export; use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice; use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\CustomFieldsBundle\Service\CustomFieldProvider; -use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; -use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Templating\TranslatableStringHelper; @@ -30,21 +28,17 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use PhpOffice\PhpSpreadsheet\Shared\Date; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Callback; -use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Render a list of people. */ -class ListPerson implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface +class ListPerson implements ListInterface, GroupedExportInterface { private array $slugs = []; private readonly bool $filterStatsByCenters; public function __construct( - private readonly ExportAddressHelper $addressHelper, private readonly CustomFieldProvider $customFieldProvider, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager, @@ -56,39 +50,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou public function buildForm(FormBuilderInterface $builder) { - $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); - - foreach ($this->getCustomFields() as $cf) { - $choices[$this->translatableStringHelper->localize($cf->getName())] - = - $cf->getSlug(); - } - - // Add a checkbox to select fields - $builder->add('fields', ChoiceType::class, [ - 'multiple' => true, - 'expanded' => true, - 'choices' => $choices, - 'label' => 'Fields to include in export', - 'choice_attr' => static function (string $val): array { - // add a 'data-display-target' for address fields - if (str_starts_with($val, 'address') || 'center' === $val || 'household' === $val) { - return ['data-display-target' => 'address_date']; - } - - return []; - }, - 'constraints' => [new Callback([ - 'callback' => static function ($selected, ExecutionContextInterface $context) { - if (0 === \count($selected)) { - $context->buildViolation('You must select at least one element') - ->atPath('fields') - ->addViolation(); - } - }, - ])], - ]); - // add a date field for addresses $builder->add('address_date', ChillDateType::class, [ 'label' => 'Data valid at this date', @@ -99,15 +60,7 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou public function getFormDefaultData(): array { - $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); - - foreach ($this->getCustomFields() as $cf) { - $choices[$this->translatableStringHelper->localize($cf->getName())] - = - $cf->getSlug(); - } - - return ['fields' => array_values($choices), 'address_date' => new \DateTimeImmutable()]; + return ['address_date' => new \DateTimeImmutable()]; } public function getAllowedFormattersTypes() @@ -127,7 +80,7 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou public function getLabels($key, array $values, $data) { - if (\in_array($key, $this->listPersonHelper->getAllPossibleFields(), true)) { + if (\in_array($key, $this->listPersonHelper->getAllKeys(), true)) { return $this->listPersonHelper->getLabels($key, $values, $data); } @@ -138,28 +91,12 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou { $fields = []; - foreach (ListPersonHelper::FIELDS as $key) { - if (!\in_array($key, $data['fields'], true)) { - continue; - } - - if (str_starts_with($key, 'address_fields')) { - $fields = \array_merge($fields, $this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields')); - - continue; - } - - if ('lifecycleUpdate' === $key) { - $fields = \array_merge($fields, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']); - - continue; - } - + foreach ($this->listPersonHelper->getAllKeys() as $key) { $fields[] = $key; } // add the key from slugs and return - return \array_merge($fields, \array_keys($this->slugs)); + return [...$fields, ...\array_keys($this->slugs)]; } public function getResult($query, $data) @@ -184,11 +121,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou { $centers = array_map(static fn ($el) => $el['center'], $acl); - // throw an error if any fields are present - if (!\array_key_exists('fields', $data)) { - throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked'); - } - $qb = $this->entityManager->createQueryBuilder() ->from(Person::class, 'person'); @@ -202,15 +134,9 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou ->setParameter('authorized_centers', $centers); } - $fields = $data['fields']; - - $this->listPersonHelper->addSelect($qb, $fields, $data['address_date']); + $this->listPersonHelper->addSelect($qb, $data['address_date']); foreach ($this->getCustomFields() as $cf) { - if (!\in_array($cf->getSlug(), $fields, true)) { - continue; - } - $cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType()); if ($cfType instanceof CustomFieldChoice && $cfType->isMultiple($cf)) { @@ -251,26 +177,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou return [Declarations::PERSON_TYPE]; } - public function validateForm($data, ExecutionContextInterface $context) - { - // get the field starting with address_ - $addressFields = array_filter( - ListPersonHelper::FIELDS, - static fn (string $el): bool => str_starts_with($el, 'address_') - ); - - // check if there is one field starting with address in data - if (\count(array_intersect($data['fields'], $addressFields)) > 0) { - // if a field address is checked, the date must not be empty - if (!$data['address_date'] instanceof \DateTimeImmutable) { - $context - ->buildViolation('You must set this date if an address is checked') - ->atPath('address_date') - ->addViolation(); - } - } - } - private function DQLToSlug($cleanedSlug) { return $this->slugs[$cleanedSlug]['slug']; @@ -293,9 +199,9 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou { return $this->entityManager ->createQuery('SELECT cf ' - .'FROM ChillCustomFieldsBundle:CustomField cf ' + .'FROM '.CustomField::class.' cf ' .'JOIN cf.customFieldGroup g ' - .'WHERE cf.type != :title AND g.entity LIKE :entity') + .'WHERE cf.type != :title AND g.entity LIKE :entity AND cf.active = TRUE') ->setParameters([ 'title' => 'title', 'entity' => \addcslashes(Person::class, '\\'), diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php index e638838fb..4a44f2dc5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php @@ -12,10 +12,8 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; use Chill\MainBundle\Export\AccompanyingCourseExportHelper; -use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; -use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; @@ -30,22 +28,18 @@ use DateTimeImmutable; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Callback; -use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * List the persons, having an accompanying period. * * Details of the accompanying period are not included */ -final readonly class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface +final readonly class ListPersonHavingAccompanyingPeriod implements ListInterface, GroupedExportInterface { private bool $filterStatsByCenters; public function __construct( - private ExportAddressHelper $addressHelper, private ListPersonHelper $listPersonHelper, private EntityManagerInterface $entityManager, private RollingDateConverterInterface $rollingDateConverter, @@ -56,32 +50,6 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement public function buildForm(FormBuilderInterface $builder) { - $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); - - $builder->add('fields', ChoiceType::class, [ - 'multiple' => true, - 'expanded' => true, - 'choices' => $choices, - 'label' => 'Fields to include in export', - 'choice_attr' => static function (string $val): array { - // add a 'data-display-target' for address fields - if (str_starts_with($val, 'address') || 'center' === $val || 'household' === $val) { - return ['data-display-target' => 'address_date']; - } - - return []; - }, - 'constraints' => [new Callback([ - 'callback' => static function ($selected, ExecutionContextInterface $context) { - if (0 === \count($selected)) { - $context->buildViolation('You must select at least one element') - ->atPath('fields') - ->addViolation(); - } - }, - ])], - ]); - $builder->add('address_date_rolling', PickRollingDateType::class, [ 'label' => 'Data valid at this date', 'help' => 'Data regarding center, addresses, and so on will be computed at this date', @@ -90,9 +58,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement public function getFormDefaultData(): array { - $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); - - return ['fields' => array_values($choices), 'address_date_rolling' => new RollingDate(RollingDate::T_TODAY)]; + return ['address_date_rolling' => new RollingDate(RollingDate::T_TODAY)]; } public function getAllowedFormattersTypes() @@ -117,29 +83,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement public function getQueryKeys($data) { - $fields = []; - - foreach (ListPersonHelper::FIELDS as $key) { - if (!\in_array($key, $data['fields'], true)) { - continue; - } - - if (str_starts_with($key, 'address_fields')) { - $fields = array_merge($fields, $this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields')); - - continue; - } - - if ('lifecycleUpdate' === $key) { - $fields = array_merge($fields, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']); - - continue; - } - - $fields[] = $key; - } - - return $fields; + return $this->listPersonHelper->getAllKeys(); } public function getResult($query, $data) @@ -164,11 +108,6 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement { $centers = array_map(static fn ($el) => $el['center'], $acl); - // throw an error if any fields are present - if (!\array_key_exists('fields', $data)) { - throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked'); - } - $qb = $this->entityManager->createQueryBuilder(); $qb->from(Person::class, 'person') @@ -185,9 +124,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement )->setParameter('authorized_centers', $centers); } - $fields = $data['fields']; - - $this->listPersonHelper->addSelect($qb, $fields, $this->rollingDateConverter->convert($data['address_date_rolling'])); + $this->listPersonHelper->addSelect($qb, $this->rollingDateConverter->convert($data['address_date_rolling'])); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); @@ -208,24 +145,4 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement { return [Declarations::PERSON_TYPE, Declarations::ACP_TYPE]; } - - public function validateForm($data, ExecutionContextInterface $context) - { - // get the field starting with address_ - $addressFields = array_filter( - ListPersonHelper::FIELDS, - static fn (string $el): bool => str_starts_with($el, 'address_') - ); - - // check if there is one field starting with address in data - if (\count(array_intersect($data['fields'], $addressFields)) > 0) { - // if a field address is checked, the date must not be empty - if (!$data['address_date'] instanceof \DateTimeImmutable) { - $context - ->buildViolation('You must set this date if an address is checked') - ->atPath('address_date') - ->addViolation(); - } - } - } } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php index d29ba3fde..81cc09c8d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php @@ -120,7 +120,7 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte $this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data); - $this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $this->rollingDateConverter->convert($data['address_date'])); + $this->listPersonHelper->addSelect($qb, $this->rollingDateConverter->convert($data['address_date'])); $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date'])); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Helper/CustomizeListPersonHelperInterface.php b/src/Bundle/ChillPersonBundle/Export/Helper/CustomizeListPersonHelperInterface.php new file mode 100644 index 000000000..049f79f58 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Helper/CustomizeListPersonHelperInterface.php @@ -0,0 +1,36 @@ + + */ + private iterable $customPersonHelpers, + ) { } /** @@ -82,26 +96,34 @@ class ListPersonHelper */ public function getAllKeys(): array { - return [ - ...array_filter( - ListPersonHelper::FIELDS, - fn (string $key) => !\in_array($key, ['address_fields', 'lifecycleUpdate'], true) - ), + $keys = [ + ...ListPersonHelper::FIELDS, ...$this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields'), - ...['createdAt', 'createdBy', 'updatedAt', 'updatedBy'], ]; + + foreach ($this->customPersonHelpers as $customize) { + $keys = $customize->alterKeys($keys); + } + + return $keys; } - /** - * @param array> $fields - */ - public function addSelect(QueryBuilder $qb, array $fields, \DateTimeImmutable $computedDate): void + public function addSelect(QueryBuilder $qb, \DateTimeImmutable $computedDate): void { - foreach (ListPersonHelper::FIELDS as $f) { - if (!\in_array($f, $fields, true)) { - continue; - } + // we first add all the fields which are handled by the + $focusedFieldKeys = [ + 'personId', 'countryOfBirth', 'nationality', // 'address_fields', + 'spokenLanguages', 'household_id', 'center', // 'lifecycleUpdate', + 'genderComment', 'maritalStatus', 'maritalStatusComment', 'civility', + 'createdAt', 'createdBy', 'updatedAt', 'updatedBy', + ]; + $filteredFields = array_filter( + ListPersonHelper::FIELDS, + fn ($field) => !in_array($field, $focusedFieldKeys, true) + ); + + foreach ($this->getAllKeys() as $f) { switch ($f) { case 'personId': $qb->addSelect('person.id AS personId'); @@ -114,13 +136,6 @@ class ListPersonHelper break; - case 'address_fields': - $this->addCurrentAddressAt($qb, $computedDate); - $qb->leftJoin('personHouseholdAddress.address', 'personAddress'); - $this->addressHelper->addSelectClauses(ExportAddressHelper::F_ALL, $qb, 'personAddress', 'address_fields'); - - break; - case 'spokenLanguages': $qb->addSelect('(SELECT AGGREGATE(language.id) FROM '.Language::class.' language WHERE language MEMBER OF person.spokenLanguages) AS spokenLanguages'); @@ -154,15 +169,6 @@ class ListPersonHelper break; - case 'lifecycleUpdate': - $qb - ->addSelect('person.createdAt AS createdAt') - ->addSelect('IDENTITY(person.createdBy) AS createdBy') - ->addSelect('person.updatedAt AS updatedAt') - ->addSelect('IDENTITY(person.updatedBy) AS updatedBy'); - - break; - case 'genderComment': $qb->addSelect('person.genderComment.comment AS genderComment'); @@ -184,25 +190,47 @@ class ListPersonHelper break; default: - $qb->addSelect(sprintf('person.%s as %s', $f, $f)); + if (in_array($f, $filteredFields, true)) { + $qb->addSelect(sprintf('person.%s as %s', $f, $f)); + } } } + + // address + $this->addCurrentAddressAt($qb, $computedDate); + $qb->leftJoin('personHouseholdAddress.address', 'personAddress'); + $this->addressHelper->addSelectClauses(ExportAddressHelper::F_ALL, $qb, 'personAddress', 'address_fields'); + + // lifecycle update + $qb + ->addSelect('person.createdAt AS createdAt') + ->addSelect('IDENTITY(person.createdBy) AS createdBy') + ->addSelect('person.updatedAt AS updatedAt') + ->addSelect('IDENTITY(person.updatedBy) AS updatedBy'); + + foreach ($this->customPersonHelpers as $customPersonHelper) { + $customPersonHelper->alterSelect($qb, $computedDate); + } } /** * @return array|string[] + * + * @deprecated */ public function getAllPossibleFields(): array { - return array_merge( - self::FIELDS, - ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'], - $this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields') - ); + return $this->getAllKeys(); } public function getLabels($key, array $values, $data): callable { + foreach ($this->customPersonHelpers as $customPersonHelper) { + if (null !== $callable = $customPersonHelper->getLabels($key, $values, $data)) { + return $callable; + } + } + if (str_starts_with((string) $key, 'address_fields')) { return $this->addressHelper->getLabel($key, $values, $data, 'address_fields'); } @@ -366,7 +394,7 @@ class ListPersonHelper }; default: - if (!\in_array($key, self::getAllPossibleFields(), true)) { + if (!\in_array($key, self::getAllKeys(), true)) { throw new \RuntimeException("this key is not supported by this helper: {$key}"); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php index c050779e2..118b08443 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; -use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Test\Export\AbstractExportTest; @@ -35,13 +34,11 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest public function getExport() { - $addressHelper = self::$container->get(ExportAddressHelper::class); $listPersonHelper = self::$container->get(ListPersonHelper::class); $entityManager = self::$container->get(EntityManagerInterface::class); $rollingDateconverter = self::$container->get(RollingDateConverterInterface::class); yield new ListPersonHavingAccompanyingPeriod( - $addressHelper, $listPersonHelper, $entityManager, $rollingDateconverter, @@ -49,7 +46,6 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest ); yield new ListPersonHavingAccompanyingPeriod( - $addressHelper, $listPersonHelper, $entityManager, $rollingDateconverter, @@ -59,7 +55,7 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest public function getFormData() { - return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY), 'fields' => ListPersonHelper::FIELDS]]; + return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY)]]; } public function getModifiersCombination() diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php index b398d1c91..75a8dc35c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; use Chill\CustomFieldsBundle\Service\CustomFieldProvider; -use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Export\ListPerson; @@ -50,14 +49,12 @@ final class ListPersonTest extends AbstractExportTest public function getExport() { - $addressHelper = self::$container->get(ExportAddressHelper::class); $customFieldProvider = self::$container->get(CustomFieldProvider::class); $listPersonHelper = self::$container->get(ListPersonHelper::class); $entityManager = self::$container->get(EntityManagerInterface::class); $translatableStringHelper = self::$container->get(TranslatableStringHelper::class); yield new ListPerson( - $addressHelper, $customFieldProvider, $listPersonHelper, $entityManager, @@ -66,7 +63,6 @@ final class ListPersonTest extends AbstractExportTest ); yield new ListPerson( - $addressHelper, $customFieldProvider, $listPersonHelper, $entityManager, @@ -77,15 +73,7 @@ final class ListPersonTest extends AbstractExportTest public function getFormData(): iterable { - foreach ([ - ['fields' => ['id', 'firstName', 'lastName']], - ['fields' => ['id', 'birthdate', 'gender', 'memo', 'email', 'phonenumber']], - ['fields' => ['firstName', 'lastName', 'phonenumber']], - ['fields' => ['id', 'nationality']], - ['fields' => ['id', 'countryOfBirth']], - ] as $base) { - yield [...$base, 'address_date' => new \DateTimeImmutable('today')]; - } + yield ['address_date' => new \DateTimeImmutable('today')]; } public function getModifiersCombination(): array diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index c0ed03115..263e172d0 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -16,6 +16,10 @@ services: tags: - { name: chill.export, alias: list_person } + Chill\PersonBundle\Export\Helper\ListPersonHelper: + arguments: + $customPersonHelpers: !tagged_iterator chill_person.list_person_customizer + Chill\PersonBundle\Export\Export\ListPersonHavingAccompanyingPeriod: tags: - { name: chill.export, alias: list_person_with_acp }