Commit 974268b8 authored by Mat's avatar Mat
Browse files

Association: CRUD basique complet

parent 89f1824a
......@@ -49,7 +49,51 @@ class AssociationController extends Controller
/**
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$association = $em->getRepository('AssoBundle:Association')->findOneByUpdate($id);
if ($association === null) {
throw $this->createNotFoundException();
}
$form = $this->createForm(AssociationType::class, $association);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->persist($association);
$em->flush();
return $this->redirectToRoute('asso_association_read');
}
return $this->render('@Asso/Association/update.html.twig', array(
'id' => $id,
'formAssociation' => $form->createView()
));
}
/**
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$association = $em->getRepository('AssoBundle:Association')->findOneByDelete($id);
if ($association !== null)
{
$em->remove($association);
$em->flush();
return $this->redirectToRoute('asso_association_read');
}
}
}
......@@ -10,12 +10,44 @@ namespace AssoBundle\Repository;
*/
class AssociationRepository extends \Doctrine\ORM\EntityRepository
{
public function findAllByIndex()
/**
* @return Association[]
*
*/
public function findAllByIndex()
{
$qb = $this->createQueryBuilder('a')
->orderBy('a.id', 'ASC');
return $qb->getQuery()->getResult();
}
/**
* @var id
* @return Association
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByUpdate($id)
{
$qb = $this->createQueryBuilder('a')
->where('a.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @var id
* @return Association
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByDelete($id)
{
$qb = $this->createQueryBuilder('a')
->where('a.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -8,6 +8,16 @@ asso_association_create:
defaults:
_controller: AssoBundle:Association:create
asso_association_update:
path: /edit/{id}
defaults:
_controller: AssoBundle:Association:update
asso_association_delete:
path: /delete/{id}
defaults:
_controller: AssoBundle:Association:delete
asso_membre_read:
path: /membres
defaults:
......
......@@ -13,7 +13,9 @@
{{ asso.objetSocial }}
{{ asso.email }}
{{ asso.tva }}
<a href="{{ path('asso_association_update', {'id': asso.id }) }}">Editer</a>
<a href="{{ path('asso_association_delete', {'id': asso.id }) }}">Effacer</a>
</li>
{% endfor %}
......
{% extends "@Asso/base.html.twig" %}
{% block title %}
Modifier l'association n° {{ id }}
{% endblock %}
{% block body %}
<h2>{{ block('title') }}</h2>
{{ form(formAssociation) }}
{% 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