mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
Merge remote-tracking branch 'origin/master' into rector/rules-up-to-php80
Conflicts: src/Bundle/ChillActivityBundle/Controller/ActivityController.php src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php src/Bundle/ChillCalendarBundle/Command/MapAndSubscribeUserCalendarCommand.php src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MSGraphUserRepository.php src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php src/Bundle/ChillEventBundle/Search/EventSearch.php src/Bundle/ChillMainBundle/Controller/ExportController.php src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php src/Bundle/ChillMainBundle/Cron/CronManager.php src/Bundle/ChillMainBundle/Entity/CronJobExecution.php src/Bundle/ChillMainBundle/Export/ExportManager.php src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php src/Bundle/ChillMainBundle/Repository/NotificationRepository.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperFactory.php src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AgeAggregator.php src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php
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);
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ class RegroupmentType extends AbstractType
|
||||
->add('centers', EntityType::class, [
|
||||
'class' => Center::class,
|
||||
'multiple' => true,
|
||||
'attr' => ['class' => 'select2'],
|
||||
'expanded' => true,
|
||||
])
|
||||
->add('isActive', CheckboxType::class, [
|
||||
'label' => 'Actif ?',
|
||||
|
@@ -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,33 +34,39 @@ final class PickCenterType extends AbstractType
|
||||
{
|
||||
public const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
private UserInterface $user;
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelper;
|
||||
|
||||
private ExportManager $exportManager;
|
||||
|
||||
private RegroupmentRepository $regroupmentRepository;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
private ExportManager $exportManager,
|
||||
private RegroupmentRepository $regroupmentRepository,
|
||||
private AuthorizationHelperInterface $authorizationHelper
|
||||
ExportManager $exportManager,
|
||||
RegroupmentRepository $regroupmentRepository,
|
||||
AuthorizationHelperForCurrentUserInterface $authorizationHelper
|
||||
) {
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->exportManager = $exportManager;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->regroupmentRepository = $regroupmentRepository;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$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)
|
||||
|
@@ -12,7 +12,10 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Form\Type\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
||||
@@ -27,10 +30,6 @@ use function count;
|
||||
|
||||
final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
{
|
||||
public function __construct(private RequestStack $requestStack)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
/** @var FilterOrderHelper $helper */
|
||||
@@ -40,22 +39,16 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add('q', SearchType::class, [
|
||||
'label' => false,
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'placeholder' => 'filter_order.Search',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$checkboxesBuilder = $builder->create('checkboxes', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||
$choices = array_combine(
|
||||
array_map(static function ($c, $t) {
|
||||
if (null !== $t) {
|
||||
return $t;
|
||||
}
|
||||
|
||||
return $c;
|
||||
}, $c['choices'], $c['trans']),
|
||||
$c['choices']
|
||||
);
|
||||
$choices = self::buildCheckboxChoices($c['choices'], $c['trans']);
|
||||
|
||||
$checkboxesBuilder->add($name, ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
@@ -68,6 +61,25 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add($checkboxesBuilder);
|
||||
}
|
||||
|
||||
if ([] !== $helper->getEntityChoices()) {
|
||||
$entityChoicesBuilder = $builder->create('entity_choices', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getEntityChoices() as $key => [
|
||||
'label' => $label, 'choices' => $choices, 'options' => $opts, 'class' => $class
|
||||
]) {
|
||||
$entityChoicesBuilder->add($key, EntityType::class, [
|
||||
'label' => $label,
|
||||
'choices' => $choices,
|
||||
'class' => $class,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
...$opts,
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add($entityChoicesBuilder);
|
||||
}
|
||||
|
||||
if (0 < count($helper->getDateRanges())) {
|
||||
$dateRangesBuilder = $builder->create('dateRanges', null, ['compound' => true]);
|
||||
|
||||
@@ -94,29 +106,51 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add($dateRangesBuilder);
|
||||
}
|
||||
|
||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'q':
|
||||
case 'checkboxes' . $key:
|
||||
case $key . '_from':
|
||||
case $key . '_to':
|
||||
break;
|
||||
if ([] !== $helper->getSingleCheckbox()) {
|
||||
$singleCheckBoxBuilder = $builder->create('single_checkboxes', null, ['compound' => true]);
|
||||
|
||||
case 'page':
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => 1,
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => $value,
|
||||
]);
|
||||
|
||||
break;
|
||||
foreach ($helper->getSingleCheckbox() as $name => ['label' => $label]) {
|
||||
$singleCheckBoxBuilder->add($name, CheckboxType::class, ['label' => $label, 'required' => false]);
|
||||
}
|
||||
|
||||
$builder->add($singleCheckBoxBuilder);
|
||||
}
|
||||
|
||||
if ([] !== $helper->getUserPickers()) {
|
||||
$userPickersBuilder = $builder->create('user_pickers', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getUserPickers() as $name => [
|
||||
'label' => $label, 'options' => $opts
|
||||
]) {
|
||||
|
||||
$userPickersBuilder->add(
|
||||
$name,
|
||||
PickUserDynamicType::class,
|
||||
[
|
||||
'multiple' => true,
|
||||
'label' => $label,
|
||||
...$opts,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$builder->add($userPickersBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function buildCheckboxChoices(array $choices, array $trans = []): array
|
||||
{
|
||||
return array_combine(
|
||||
array_map(static function ($c, $t) {
|
||||
if (null !== $t) {
|
||||
return $t;
|
||||
}
|
||||
|
||||
return $c;
|
||||
}, $choices, $trans),
|
||||
$choices
|
||||
);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
|
Reference in New Issue
Block a user