Commit 037dc592 authored by Mat's avatar Mat
Browse files

Légume, Update et Delete

parent 4033b073
......@@ -58,7 +58,28 @@ class LegumeController extends Controller
*/
public function updateAction(Request $request, $id)
{
return $this->render('@Potage/Legume/update.html.twig', array());
$em = $this->getDoctrine()->getManager();
$legume = $em->getRepository('PotageBundle:Legume')->findOneByUpdate($id);
if ($legume === null) {
throw $this->createNotFoundException();
}
$form = $this->createForm(LegumeType::class, $legume);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->persist($legume);
$em->flush();
return $this->redirectToRoute('potage_legume_read');
}
return $this->render('@Potage/Legume/update.html.twig', array(
'id' => $id,
'formLegume' => $form->createView()
));
}
/**
......@@ -68,7 +89,16 @@ class LegumeController extends Controller
*/
public function deleteAction($id)
{
return $this->render('@Potage/Legume/delete.html.twig', array());
$em = $this->getDoctrine()->getManager();
$legume = $em->getRepository('PotageBundle:Legume')->findOneByDelete($id);
if ($legume !== null) {
$em->remove($legume);
$em->flush();
return $this->redirectToRoute('potage_legume_read');
}
}
}
......@@ -10,6 +10,7 @@ namespace PotageBundle\Repository;
*/
class LegumeRepository extends \Doctrine\ORM\EntityRepository
{
/**
*
* @return Legume[]
......@@ -22,9 +23,33 @@ class LegumeRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getResult();
}
/**
* @var id
* @return Legume
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByUpdate($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @var id
* @return Legume
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByDelete($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -9,6 +9,7 @@
{{ block('breadcrumb') }}
<h1>{{ block('title') }}</h1>
<a href="{{ path('potage_legume_read') }}"><i class="fas fa-arrow-left fa-fw"></i>Retour vers la liste</a>
<div class="row">
<div class="col-9">
......
......@@ -64,7 +64,7 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Effacer l'association{{ legume.id }}</h5>
<h5 class="modal-title">Effacer le légume{{ legume.id }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
......
......@@ -9,6 +9,54 @@
{{ block('breadcrumb') }}
<h1>{{ block('title') }}</h1>
<a href="{{ path('potage_legume_read') }}"><i class="fas fa-arrow-left fa-fw"></i>Retour vers la liste</a>
<div class="row">
<div class="col-9">
{{ form_start(formLegume) }}
{{ form_errors(formLegume) }}
<div class="form-group row">{{ form_label(formLegume.nom) }}
<div class="col-sm-8">{{ form_widget(formLegume.nom) }}</div>
{{ form_errors(formLegume.nom) }}</div>
<div class="form-group row">{{ form_label(formLegume.description) }}
<div class="col-sm-8">{{ form_widget(formLegume.description) }}</div>
{{ form_errors(formLegume.description) }}</div>
<div class="form-group row">{{ form_label(formLegume.logoPath) }}
<div class="col-sm-8">{{ form_widget(formLegume.logoPath) }}</div>
{{ form_errors(formLegume.logoPath) }}</div>
<div class="form-group row">{{ form_label(formLegume.unite) }}
<div class="col-sm-8">{{ form_widget(formLegume.unite) }}</div>
{{ form_errors(formLegume.unite) }}</div>
<div class="form-group row">{{ form_label(formLegume.quantiteMin) }}
<div class="col-sm-8">{{ form_widget(formLegume.quantiteMin) }}</div>
{{ form_errors(formLegume.quantiteMin) }}</div>
<div class="form-group row">{{ form_label(formLegume.quantiteMax) }}
<div class="col-sm-8">{{ form_widget(formLegume.quantiteMax) }}</div>
{{ form_errors(formLegume.quantiteMax) }}</div>
<div class="form-group row">{{ form_label(formLegume.quantiteStep) }}
<div class="col-sm-8">{{ form_widget(formLegume.quantiteStep) }}</div>
{{ form_errors(formLegume.quantiteStep) }}</div>
<div class="form-group row">{{ form_label(formLegume.prixUnitaire) }}
<div class="col-sm-8">{{ form_widget(formLegume.prixUnitaire) }}</div>
{{ form_errors(formLegume.prixUnitaire) }}</div>
<div class="form-group row">{{ form_label(formLegume.sauver) }}
<div class="col-sm-8">{{ form_widget(formLegume.sauver) }}</div>
</div>
{{ form_end(formLegume) }}
</div>
</div>
{% endblock %}
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