Commit 91f48f55 authored by Mat's avatar Mat

un premier formulaire de commande, basique, qui fonctionne

parent 05db4da1
......@@ -2,12 +2,14 @@
namespace PotageBundle\Controller;
use PotageBundle\Entity\Commande;
use PotageBundle\Entity\Groupe;
use PotageBundle\Entity\Lettre;
use PotageBundle\Entity\Offre;
use PotageBundle\Entity\OffreLegumes;
use PotageBundle\Entity\User;
use PotageBundle\Entity\Utilisateur;
use PotageBundle\Form\Membre\CommandeType;
use PotageBundle\Services\LettreToken;
use Symfony\Component\HttpFoundation\Request;
......@@ -64,11 +66,12 @@ class MembreController extends MasterController
/**
* Lorsqu'on pointe explicitement la référence de l'offre
*
* @param Request $request
* @param string $offre_ref
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function todayOneAction($offre_ref)
public function todayOneAction(Request $request, $offre_ref)
{
$user = $this->getUser();
......@@ -77,6 +80,7 @@ class MembreController extends MasterController
$groupes = $this->getGroupesDepotLettresAndOffreLegumes($user);
$currentOffre = $this->getCurrentOffre($offre_ref);
$offre = $currentOffre['offreOne'];
/**
* il faut que l'offre soit en cours, et qu'on aie le droit d'y accéder
......@@ -85,6 +89,18 @@ class MembreController extends MasterController
{
return $this->redirectToRoute('potage_today');
}
$commande = new Commande($offre, $user);
$form = $this->createForm(CommandeType::class, $commande);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($commande);
$em->flush();
}
return $this->render('@Potage/Membre/today.html.twig', array(
'user' => $user,
......@@ -94,6 +110,7 @@ class MembreController extends MasterController
'offreOne' => $currentOffre['offreOne'],
'legumesSorted' => $currentOffre['legumesSorted'],
'groupeOne' => $currentOffre['groupeOne'],
'formCommande' => $form->createView(),
));
}
......
......@@ -58,7 +58,7 @@ class Commande
/**
* @var \DateTime
*
* @ORM\Column(name="updatedAt", type="datetime")
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
private $updatedAt;
......@@ -83,10 +83,14 @@ class Commande
/**
* Commande constructor.
*
* @param Offre $offre
* @param User $user
*/
public function __construct()
public function __construct($offre, $user)
{
$this->offre = $offre;
$this->user = $user;
}
/**
......
......@@ -67,7 +67,7 @@ class CommandeLegumes
/**
* @var \DateTime
*
* @ORM\Column(name="updatedAt", type="datetime")
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
private $updatedAt;
......
<?php
namespace PotageBundle\Form\Membre;
use PotageBundle\Entity\Commande;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CommandeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('prixTotal')
->add('sauver', SubmitType::class, array(
'label' => 'Enregistrer',
'attr' => array('class' => 'btn btn-dark mb-2')
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', Commande::class);
$resolver->setDefault('attr', array(
'class' => 'formulaire formulaire_commande',
));
}
public function getBlockPrefix()
{
return 'commande';
}
}
......@@ -10,7 +10,7 @@ potage_today:
path: /member/today
defaults:
_controller: PotageBundle:Membre:today
methods: [ GET ]
methods: [ GET, POST ]
potage_today_one:
path: /member/today/{offre_ref}
......@@ -18,7 +18,7 @@ potage_today_one:
offre_ref: \w+
defaults:
_controller: PotageBundle:Membre:todayOne
methods: [ GET ]
methods: [ GET, POST ]
### ADMIN
......
......@@ -29,4 +29,6 @@
</tbody>
</table>
<button type="button" class="btn btn-lg btn-block btn-primary float-right">Envoyer la commande</button>
\ No newline at end of file
<button type="button" class="btn btn-lg btn-block btn-primary float-right">Envoyer la commande</button>
{{ form(formCommande) }}
\ No newline at end of file
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