mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
[export form] decouple data from PickCenter form
This commit is contained in:
@@ -22,7 +22,10 @@ use function count;
|
||||
|
||||
class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
{
|
||||
protected RegroupmentRepository $regroupmentRepository;
|
||||
public function __construct(
|
||||
private RegroupmentRepository $regroupmentRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function mapDataToForms($data, $forms): void
|
||||
{
|
||||
@@ -37,15 +40,15 @@ class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
|
||||
foreach ($this->regroupmentRepository->findAll() as $regroupment) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
[$contained, $notContained] = $regroupment->getCenters()->partition(static fn (Center $center): bool => false);
|
||||
[$contained, $notContained] = $regroupment->getCenters()->partition(static fn (int $id, Center $center): bool => false);
|
||||
|
||||
if (0 === count($notContained)) {
|
||||
$pickedRegroupment[] = $regroupment;
|
||||
}
|
||||
}
|
||||
|
||||
$form['regroupment']->setData($pickedRegroupment);
|
||||
$form['centers']->setData($data);
|
||||
$form['regroupment']->setData([]);
|
||||
$form['center']->setData($data);
|
||||
}
|
||||
|
||||
public function mapFormsToData($forms, &$data): void
|
||||
|
@@ -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) {
|
||||
@@ -82,7 +77,7 @@ final class PickCenterType extends AbstractType
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->setDataMapper(new ExportPickCenterDataMapper());
|
||||
$builder->setDataMapper(new ExportPickCenterDataMapper($this->regroupmentRepository));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
Reference in New Issue
Block a user