FEATURE [datamapper][regroupment] minor fix

This commit is contained in:
2023-02-07 15:39:36 +01:00
parent 1a44a516c2
commit a4e21b7834
3 changed files with 30 additions and 27 deletions

View File

@@ -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<string, FormInterface> $form */
$form = iterator_to_array($forms);
/** @var array<string, FormInterface> $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)