Commit 74d8e7f1 authored by Mat's avatar Mat
Browse files

Formulaire OffreLegumesSelect, nettoyage du code

parent 2948c151
......@@ -163,6 +163,7 @@ class LegumeAPIController extends MasterAPIController
}
}
/**
* @param Request $request
* @param $id
......@@ -211,6 +212,5 @@ class LegumeAPIController extends MasterAPIController
}
/*
* TODO filtrer le select (EntityType) pour qu'il n'affiche que les offres en préparation
* TODO submit du formulaire, persist et flush
*/
\ No newline at end of file
......@@ -7,7 +7,6 @@ use PotageBundle\Entity\OffreLegumes;
use PotageBundle\Repository\OffreRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
......@@ -19,53 +18,6 @@ class OffreLegumesInsertType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
/*
// 1) fonctionnel, mais liste toutes les offres
//
$builder->add('offre', EntityType::class, array(
'class' => Offre::class,
'label' => 'Offres en préparation',
'attr' => array(
'class' => 'form-control form-control-sm'
),
'choice_label' => 'getReference'
));
// 2) non fonctionnel mais utile dans d'autres cas
//
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event)
{
$form = $event->getForm();
$offre = $event->getData();
$offresByPrepa = $offre->getReference();
$choices = null === $offresByPrepa ? array() : $offresByPrepa->getAvailablePositions();
$form->add('offre', EntityType::class, array(
'class' => Offre::class,
'placeholder' => '',
'choices' => $choices,
));
// checks if the Offre object is "new"
// If no data is passed to the form, the data is "null".
// This should be considered a new "Offre"
if (!$offresByPrepa || null === $offresByPrepa->getId())
{
$form->add('offre', ChoiceType::class, array(
'mapped' => false,
'data' => ($offresByPrepa->getAssociation() === null) ? null : $offresByPrepa->getAssociation()->getTva()
));
}
}
);
*/
// 3) fonctionne ! cfr: http://symfony.com/doc/3.4/form/dynamic_form_modification.html#customizing-the-form-type
//
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event)
......@@ -87,8 +39,6 @@ class OffreLegumesInsertType extends AbstractType
));
}
);
////
$builder->add('sauver', SubmitType::class, array(
'label' => 'Enregistrer',
......
......@@ -90,17 +90,4 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $status
* @return Offre[]
*/
public function findAllByStatusForInsert()
{
$qb = $this->createQueryBuilder('o')
->where('o.status = :status')
->setParameter(':status', 'draft')
->orderBy('o.reference', 'ASC');
return $qb->getQuery()->getResult();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment