mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
Merge remote-tracking branch 'origin/118-design-filterOrder' into user_filter_tasks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
$form['regroupment']->setData($pickedRegroupment);
|
||||
$form['centers']->setData($data);
|
||||
// NOTE: we do not map back the regroupments
|
||||
}
|
||||
|
||||
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,19 @@ final class PickCenterType extends AbstractType
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->user,
|
||||
$export->requiredRole()
|
||||
);
|
||||
|
||||
// order alphabetically
|
||||
usort($centers, fn (Center $a, Center $b) => $a->getCenter() <=> $b->getName());
|
||||
|
||||
$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)
|
||||
|
@@ -39,6 +39,9 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add('q', SearchType::class, [
|
||||
'label' => false,
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'placeholder' => 'activity_filter.Search',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user