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\Center\GroupingCenterInterface;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Chill\MainBundle\Entity\Regroupment;
|
||||||
use Chill\MainBundle\Export\ExportManager;
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\CallbackTransformer;
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
|
use Symfony\Component\Form\DataMapperInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
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.
|
* Pick centers amongst available centers for the user.
|
||||||
*/
|
*/
|
||||||
class PickCenterType extends AbstractType
|
class PickCenterType extends AbstractType implements DataMapperInterface
|
||||||
{
|
{
|
||||||
public const CENTERS_IDENTIFIERS = 'c';
|
public const CENTERS_IDENTIFIERS = 'c';
|
||||||
|
|
||||||
@ -42,10 +46,10 @@ class PickCenterType extends AbstractType
|
|||||||
|
|
||||||
protected ExportManager $exportManager;
|
protected ExportManager $exportManager;
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @var array|GroupingCenterInterface[]
|
// * @var array|GroupingCenterInterface[]
|
||||||
*/
|
// */
|
||||||
protected array $groupingCenters = [];
|
// protected array $groupingCenters = [];
|
||||||
|
|
||||||
protected UserInterface $user;
|
protected UserInterface $user;
|
||||||
|
|
||||||
@ -72,8 +76,9 @@ class PickCenterType extends AbstractType
|
|||||||
$export->requiredRole()
|
$export->requiredRole()
|
||||||
);
|
);
|
||||||
|
|
||||||
$builder->add(self::CENTERS_IDENTIFIERS, EntityType::class, [
|
$builder->add('center', EntityType::class, [
|
||||||
'class' => Center::class,
|
'class' => Center::class,
|
||||||
|
'label' => 'center',
|
||||||
'choices' => $centers,
|
'choices' => $centers,
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
@ -81,9 +86,19 @@ class PickCenterType extends AbstractType
|
|||||||
return $c->getName();
|
return $c->getName();
|
||||||
},
|
},
|
||||||
'data' => count($this->groupingCenters) > 0 ? null : $centers,
|
'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, [
|
$groupingBuilder = $builder->create('g', null, [
|
||||||
'compound' => true,
|
'compound' => true,
|
||||||
]);
|
]);
|
||||||
@ -105,18 +120,65 @@ class PickCenterType extends AbstractType
|
|||||||
if ($groupingBuilder->count() > 0) {
|
if ($groupingBuilder->count() > 0) {
|
||||||
$builder->add($groupingBuilder);
|
$builder->add($groupingBuilder);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$builder->addModelTransformer(new CallbackTransformer(
|
/* $builder->addModelTransformer(new CallbackTransformer(
|
||||||
function ($data) use ($centers) {
|
function ($data) use ($centers) {
|
||||||
return $this->transform($data, $centers);
|
return $this->transform($data, $centers);
|
||||||
},
|
},
|
||||||
function ($data) use ($centers) {
|
function ($data) use ($centers) {
|
||||||
return $this->reverseTransform($data, $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)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setRequired('export_alias');
|
$resolver->setRequired('export_alias');
|
||||||
@ -137,7 +199,7 @@ class PickCenterType extends AbstractType
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function reverseTransform($data, $centers)
|
/* protected function reverseTransform($data, $centers)
|
||||||
{
|
{
|
||||||
$picked = $data[self::CENTERS_IDENTIFIERS]
|
$picked = $data[self::CENTERS_IDENTIFIERS]
|
||||||
instanceof \Doctrine\Common\Collections\Collection ?
|
instanceof \Doctrine\Common\Collections\Collection ?
|
||||||
@ -159,10 +221,10 @@ class PickCenterType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array_unique($picked);
|
return array_unique($picked);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
protected function transform($data, $centers)
|
/* protected function transform($data, $centers)
|
||||||
{
|
{
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,21 @@
|
|||||||
<p>{{ 'The export will contains only data from the picked centers.'|trans }}
|
<p>{{ 'The export will contains only data from the picked centers.'|trans }}
|
||||||
{{ 'This will eventually restrict your possibilities in filtering the data.'|trans }}</p>
|
{{ 'This will eventually restrict your possibilities in filtering the data.'|trans }}</p>
|
||||||
|
|
||||||
{{ form_widget(form.centers.c) }}
|
<h3 class="m-3">{{ 'Center'|trans }}</h3>
|
||||||
|
{{ form_widget(form.centers.center) }}
|
||||||
|
|
||||||
{% if form.centers.children.g is defined %}
|
<h3 class="m-3">{{ 'Pick aggregated centers'|trans }}</h3>
|
||||||
|
{{ form_widget(form.centers.regroupment) }}
|
||||||
|
|
||||||
<h3>{{ 'Pick aggregated centers'|trans }}</h3>
|
{# {% if form.centers.children.g is defined %}#}
|
||||||
|
{##}
|
||||||
{% for f in form.centers.children.g.children %}
|
{# <h3>{{ 'Pick aggregated centers'|trans }}</h3>#}
|
||||||
{{ form_row(f) }}
|
{##}
|
||||||
{% endfor %}
|
{# {% for f in form.centers.children.g.children %}#}
|
||||||
|
{# {{ form_row(f) }}#}
|
||||||
{% endif %}
|
{# {% endfor %}#}
|
||||||
|
{##}
|
||||||
|
{# {% endif %}#}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user