diff --git a/src/Bundle/ChillMainBundle/Form/DataMapper/ExportPickCenterDataMapper.php b/src/Bundle/ChillMainBundle/Form/DataMapper/ExportPickCenterDataMapper.php index 884f8cb78..0d21b0adb 100644 --- a/src/Bundle/ChillMainBundle/Form/DataMapper/ExportPickCenterDataMapper.php +++ b/src/Bundle/ChillMainBundle/Form/DataMapper/ExportPickCenterDataMapper.php @@ -14,8 +14,10 @@ namespace Chill\MainBundle\Form\DataMapper; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Regroupment; use Chill\MainBundle\Repository\RegroupmentRepository; +use Exception; use Symfony\Component\Form\DataMapperInterface; use Symfony\Component\Form\FormInterface; +use function count; class ExportPickCenterDataMapper implements DataMapperInterface { @@ -24,34 +26,39 @@ class ExportPickCenterDataMapper implements DataMapperInterface /** * @param array|Center[] $data * @param $forms + * + * @throws Exception + * * @return mixed - * @throws \Exception */ public function mapDataToForms($data, $forms) { - throw new \Exception("not implemented"); + if (null === $data) { + return; + } - /** @var array $form */ - $form = iterator_to_array($forms); + /** @var array $form */ + $form = iterator_to_array($forms); - $pickedRegroupment = []; - foreach ($this->regroupmentRepository->findAll() as $regroupment) { - [$contained, $notContained] = $regroupment->getCenters()->partition(function (Center $center) { + $pickedRegroupment = []; - }); + foreach ($this->regroupmentRepository->findAll() as $regroupment) { + [$contained, $notContained] = $regroupment->getCenters()->partition(static function (Center $center) { + }); - if (0 === count($notContained)) { - $pickedRegroupment[] = $regroupment; - } - } + if (0 === count($notContained)) { + $pickedRegroupment[] = $regroupment; + } + } - $form['regroupment']->setData($pickedRegroupment); - $form['centers']->setData($data); + $form['regroupment']->setData($pickedRegroupment); + $form['centers']->setData($data); } /** * @param iterable $forms * @param array $data + * * @return void */ public function mapFormsToData($forms, &$data) diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php index 674f42aa7..17768544b 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php @@ -16,27 +16,15 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Regroupment; use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper; -use Chill\MainBundle\Form\DataMapper\PickCenterDataMapper; -use Chill\MainBundle\Form\DataMapper\RegroupmentDataMapper; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\CallbackTransformer; -use Symfony\Component\Form\DataMapperInterface; -use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\User\UserInterface; -use function array_intersect; -use function array_key_exists; -use function array_merge; -use function array_unique; use function count; -use function in_array; /** * Pick centers amongst available centers for the user. diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php index e60388fd3..7b04d2ebd 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php @@ -1,10 +1,18 @@