Commit 91f48f55 authored by Mat's avatar Mat

un premier formulaire de commande, basique, qui fonctionne

parent 05db4da1
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
namespace PotageBundle\Controller; namespace PotageBundle\Controller;
use PotageBundle\Entity\Commande;
use PotageBundle\Entity\Groupe; use PotageBundle\Entity\Groupe;
use PotageBundle\Entity\Lettre; use PotageBundle\Entity\Lettre;
use PotageBundle\Entity\Offre; use PotageBundle\Entity\Offre;
use PotageBundle\Entity\OffreLegumes; use PotageBundle\Entity\OffreLegumes;
use PotageBundle\Entity\User; use PotageBundle\Entity\User;
use PotageBundle\Entity\Utilisateur; use PotageBundle\Entity\Utilisateur;
use PotageBundle\Form\Membre\CommandeType;
use PotageBundle\Services\LettreToken; use PotageBundle\Services\LettreToken;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -64,11 +66,12 @@ class MembreController extends MasterController ...@@ -64,11 +66,12 @@ class MembreController extends MasterController
/** /**
* Lorsqu'on pointe explicitement la référence de l'offre * Lorsqu'on pointe explicitement la référence de l'offre
* *
* @param Request $request
* @param string $offre_ref * @param string $offre_ref
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException * @throws \Doctrine\ORM\NonUniqueResultException
*/ */
public function todayOneAction($offre_ref) public function todayOneAction(Request $request, $offre_ref)
{ {
$user = $this->getUser(); $user = $this->getUser();
...@@ -77,6 +80,7 @@ class MembreController extends MasterController ...@@ -77,6 +80,7 @@ class MembreController extends MasterController
$groupes = $this->getGroupesDepotLettresAndOffreLegumes($user); $groupes = $this->getGroupesDepotLettresAndOffreLegumes($user);
$currentOffre = $this->getCurrentOffre($offre_ref); $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 * 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 ...@@ -85,6 +89,18 @@ class MembreController extends MasterController
{ {
return $this->redirectToRoute('potage_today'); 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( return $this->render('@Potage/Membre/today.html.twig', array(
'user' => $user, 'user' => $user,
...@@ -94,6 +110,7 @@ class MembreController extends MasterController ...@@ -94,6 +110,7 @@ class MembreController extends MasterController
'offreOne' => $currentOffre['offreOne'], 'offreOne' => $currentOffre['offreOne'],
'legumesSorted' => $currentOffre['legumesSorted'], 'legumesSorted' => $currentOffre['legumesSorted'],
'groupeOne' => $currentOffre['groupeOne'], 'groupeOne' => $currentOffre['groupeOne'],
'formCommande' => $form->createView(),
)); ));
} }
......
...@@ -58,7 +58,7 @@ class Commande ...@@ -58,7 +58,7 @@ class Commande
/** /**
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="updatedAt", type="datetime") * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/ */
private $updatedAt; private $updatedAt;
...@@ -83,10 +83,14 @@ class Commande ...@@ -83,10 +83,14 @@ class Commande
/** /**
* Commande constructor. * 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 ...@@ -67,7 +67,7 @@ class CommandeLegumes
/** /**
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="updatedAt", type="datetime") * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/ */
private $updatedAt; 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: ...@@ -10,7 +10,7 @@ potage_today:
path: /member/today path: /member/today
defaults: defaults:
_controller: PotageBundle:Membre:today _controller: PotageBundle:Membre:today
methods: [ GET ] methods: [ GET, POST ]
potage_today_one: potage_today_one:
path: /member/today/{offre_ref} path: /member/today/{offre_ref}
...@@ -18,7 +18,7 @@ potage_today_one: ...@@ -18,7 +18,7 @@ potage_today_one:
offre_ref: \w+ offre_ref: \w+
defaults: defaults:
_controller: PotageBundle:Membre:todayOne _controller: PotageBundle:Membre:todayOne
methods: [ GET ] methods: [ GET, POST ]
### ADMIN ### ADMIN
......
...@@ -29,4 +29,6 @@ ...@@ -29,4 +29,6 @@
</tbody> </tbody>
</table> </table>
<button type="button" class="btn btn-lg btn-block btn-primary float-right">Envoyer la commande</button> <button type="button" class="btn btn-lg btn-block btn-primary float-right">Envoyer la commande</button>
\ No newline at end of file
{{ 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