Commit 2948c151 authored by Mat's avatar Mat
Browse files

Formulaire OffreLegumesSelect, filtrage du select pour qu'il n'affiche que les...

Formulaire OffreLegumesSelect, filtrage du select pour qu'il n'affiche que les offres en préparation
parent e98cd9f2
......@@ -179,13 +179,7 @@ class LegumeAPIController extends MasterAPIController
if ($legume === null ) {
return $this->api($legume, Response::HTTP_NOT_FOUND);
}
$offresPrepa = $em->getRepository('PotageBundle:Offre')
->findAllByStatusForInsert();
dump($legume);
dump($offresPrepa);
$offrelegumes = new OffreLegumes();
$offrelegumes
->setNom($legume)
......@@ -199,11 +193,8 @@ class LegumeAPIController extends MasterAPIController
->setFruit($legume)
->setRevente($legume)
->setImage($legume);
//$offrelegumes->setOffrePrepa($offresPrepa);
$form = $this->createForm(OffreLegumesInsertAPIType::class, $offrelegumes);
$form->handleRequest($request);
......
......@@ -4,16 +4,24 @@ namespace PotageBundle\Form\Offre;
use PotageBundle\Entity\Offre;
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;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
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',
......@@ -22,6 +30,65 @@ class OffreLegumesInsertType extends AbstractType
),
'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)
{
$form = $event->getForm();
$offre = $event->getData();
$form->add('offre', EntityType::class, array(
'class' => Offre::class,
'query_builder' => function (OffreRepository $er) use ($offre) {
return $er->createQueryBuilder('o')
->where('o.status = :status')
->setParameter(':status', 'draft')
->orderBy('o.reference', 'DESC');
},
'choice_label' => 'getReference',
'label' => 'Offres en préparation',
'attr' => array('class' => 'form-control form-control-sm'),
));
}
);
////
$builder->add('sauver', SubmitType::class, array(
'label' => 'Enregistrer',
......
......@@ -15,9 +15,14 @@
aria-label="LargeSearch" aria-describedby="inputGroup-sizing-sm">
</div>
</form>
<b>
<a href="{{ path('potage_offre_ajax_display') }}" class="nav-laterale left text-secondary"><i class="fas fa-long-arrow-alt-up fa-fw"></i> Toutes les offres</a>
</b>
<div class="nav-laterale left">
<b>
<a href="{{ path('potage_legume_ajax_display') }}" class="text-secondary">
<i class="fas fa-long-arrow-alt-up fa-fw" style="transform: rotate(-45deg);"></i>Les légumes</a>
<a href="{{ path('potage_offre_ajax_display') }}" class="text-secondary">
<i class="fas fa-long-arrow-alt-up fa-fw"></i> Toutes les offres</a>
</b>
</div>
</nav>
{% endblock %}
......@@ -59,18 +64,18 @@
</div>
<li class="list-group-item d-flex justify-content-between align-items-center">
<dt>Créée le </dt><dd>{{ offre.createdAt.format('d/m/Y H:i') }}</dd>
Créée le {{ offre.createdAt.format('d/m/Y H:i') }}
</li>
{#
<li class="list-group-item d-flex justify-content-between align-items-center">
<dt>Dernière modification: </dt><dd>{{ offre.updatedAt.format('d/m/Y H:i') }}</dd>
Dernière modification: {{ offre.updatedAt.format('d/m/Y H:i') }}
</li>
#}
<li class="list-group-item list-group-item-action {#list-group-item-warning#}">
<dt>Statut: </dt><dd>{{ offre.status }}</dd>
Statut: {{ offre.status }}
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<dt>Date d'expiration: </dt><dd>{{ offre.endedAt.format('d/m/Y H:i') }}</dd>
Date d'expiration: {{ offre.endedAt.format('d/m/Y H:i') }}
</li>
<li class="list-group-item d-flex">
<button class="btn btn-dark btn-sm mr-2 mb-2">
......
......@@ -55,10 +55,9 @@ nav.navbar-search:before {
footer#footer,
nav.navbar-search {
background-image: url("img/legume_background.nb.4.png");
/*
background-color: #9adbfb; */
background-repeat: repeat;
background-position: 0px -16px;
background-position: 0px -16px; /*
background-color: #9adbfb; */
}
#offre_ajax_display footer#footer,
#offre_ajax_display .navbar-search {
......
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