mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FEATURE [regroupment][form] integrate in regroupment admin entity into PickCenterType, datamapping not working
This commit is contained in:
parent
7f9e045d5d
commit
c83e8ad9a4
@ -13,13 +13,17 @@ namespace Chill\MainBundle\Form\Type\Export;
|
||||
|
||||
use Chill\MainBundle\Center\GroupingCenterInterface;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Regroupment;
|
||||
use Chill\MainBundle\Export\ExportManager;
|
||||
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;
|
||||
|
||||
@ -34,7 +38,7 @@ use function in_array;
|
||||
/**
|
||||
* Pick centers amongst available centers for the user.
|
||||
*/
|
||||
class PickCenterType extends AbstractType
|
||||
class PickCenterType extends AbstractType implements DataMapperInterface
|
||||
{
|
||||
public const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
@ -42,10 +46,10 @@ class PickCenterType extends AbstractType
|
||||
|
||||
protected ExportManager $exportManager;
|
||||
|
||||
/**
|
||||
* @var array|GroupingCenterInterface[]
|
||||
*/
|
||||
protected array $groupingCenters = [];
|
||||
// /**
|
||||
// * @var array|GroupingCenterInterface[]
|
||||
// */
|
||||
// protected array $groupingCenters = [];
|
||||
|
||||
protected UserInterface $user;
|
||||
|
||||
@ -72,8 +76,9 @@ class PickCenterType extends AbstractType
|
||||
$export->requiredRole()
|
||||
);
|
||||
|
||||
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, [
|
||||
$builder->add('center', EntityType::class, [
|
||||
'class' => Center::class,
|
||||
'label' => 'center',
|
||||
'choices' => $centers,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
@ -81,9 +86,19 @@ class PickCenterType extends AbstractType
|
||||
return $c->getName();
|
||||
},
|
||||
'data' => count($this->groupingCenters) > 0 ? null : $centers,
|
||||
]);
|
||||
])
|
||||
->add('regroupment', EntityType::class, [
|
||||
'class' => Regroupment::class,
|
||||
'label' => 'regroupment',
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choice_label' => static function (Regroupment $r) {
|
||||
return $r->getName();
|
||||
},
|
||||
])
|
||||
->setDataMapper($this);
|
||||
|
||||
if (count($this->groupingCenters) > 0) {
|
||||
/* if (count($this->groupingCenters) > 0) {
|
||||
$groupingBuilder = $builder->create('g', null, [
|
||||
'compound' => true,
|
||||
]);
|
||||
@ -105,18 +120,65 @@ class PickCenterType extends AbstractType
|
||||
if ($groupingBuilder->count() > 0) {
|
||||
$builder->add($groupingBuilder);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
/* $builder->addModelTransformer(new CallbackTransformer(
|
||||
function ($data) use ($centers) {
|
||||
return $this->transform($data, $centers);
|
||||
},
|
||||
function ($data) use ($centers) {
|
||||
return $this->reverseTransform($data, $centers);
|
||||
}
|
||||
));
|
||||
));*/
|
||||
}
|
||||
|
||||
public function mapDataToForms($viewData, $forms)
|
||||
{
|
||||
if (null === $viewData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$viewData instanceof Center || !$viewData instanceof Regroupment) {
|
||||
throw new UnexpectedTypeException($viewData, [Center::class, Regroupment::class]);
|
||||
}
|
||||
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
$forms['centers']->setData($viewData->getCenters());
|
||||
|
||||
}
|
||||
|
||||
public function mapFormsToData($forms, &$viewData)
|
||||
{
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
$centersArray = [];
|
||||
|
||||
array_push($centersArray, $forms['center']);
|
||||
|
||||
dump($forms['regroupment']);
|
||||
|
||||
// array_push($centersArray, )
|
||||
|
||||
// $viewData = array_merge($centersArray, $forms['regroupment']);
|
||||
|
||||
$viewData = $forms['regroupment'];
|
||||
dump($forms);
|
||||
dump($viewData);
|
||||
|
||||
}
|
||||
|
||||
/* public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$export = $this->exportManager->getExport($options['export_alias']);
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->user,
|
||||
$export->requiredRole()
|
||||
);
|
||||
|
||||
$view->vars['is_hidden'] = count($centers) <= 1;
|
||||
}*/
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setRequired('export_alias');
|
||||
@ -137,7 +199,7 @@ class PickCenterType extends AbstractType
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function reverseTransform($data, $centers)
|
||||
/* protected function reverseTransform($data, $centers)
|
||||
{
|
||||
$picked = $data[self::CENTERS_IDENTIFIERS]
|
||||
instanceof \Doctrine\Common\Collections\Collection ?
|
||||
@ -159,10 +221,10 @@ class PickCenterType extends AbstractType
|
||||
}
|
||||
|
||||
return array_unique($picked);
|
||||
}
|
||||
}*/
|
||||
|
||||
protected function transform($data, $centers)
|
||||
/* protected function transform($data, $centers)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{#
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
<info@champs-libres.coop> / <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -22,39 +22,43 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="col-md-10">
|
||||
|
||||
|
||||
{{ include('@ChillMain/Export/_breadcrumb.html.twig') }}
|
||||
|
||||
|
||||
<h1>{{ export.title|trans }}</h1>
|
||||
|
||||
|
||||
<p>{{ export.description|trans }}</p>
|
||||
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
|
||||
<section class="center mb-4">
|
||||
|
||||
|
||||
<h2>{{ 'Pick centers'|trans }}</h2>
|
||||
|
||||
|
||||
<p>{{ 'The export will contains only data from the picked centers.'|trans }}
|
||||
{{ 'This will eventually restrict your possibilities in filtering the data.'|trans }}</p>
|
||||
|
||||
{{ form_widget(form.centers.c) }}
|
||||
|
||||
{% if form.centers.children.g is defined %}
|
||||
|
||||
<h3>{{ 'Pick aggregated centers'|trans }}</h3>
|
||||
|
||||
{% for f in form.centers.children.g.children %}
|
||||
{{ form_row(f) }}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
<h3 class="m-3">{{ 'Center'|trans }}</h3>
|
||||
{{ form_widget(form.centers.center) }}
|
||||
|
||||
<h3 class="m-3">{{ 'Pick aggregated centers'|trans }}</h3>
|
||||
{{ form_widget(form.centers.regroupment) }}
|
||||
|
||||
{# {% if form.centers.children.g is defined %}#}
|
||||
{##}
|
||||
{# <h3>{{ 'Pick aggregated centers'|trans }}</h3>#}
|
||||
{##}
|
||||
{# {% for f in form.centers.children.g.children %}#}
|
||||
{# {{ form_row(f) }}#}
|
||||
{# {% endfor %}#}
|
||||
{##}
|
||||
{# {% endif %}#}
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<p>{{ form_widget(form.submit, { 'attr' : { 'class' : 'btn btn-action btn-create' }, 'label' : 'Go to export options' } ) }}</p>
|
||||
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user