Commit 89f1824a authored by Mat's avatar Mat
Browse files

Membre, le CRUD basique complet

parent 4b562940
......@@ -10,35 +10,33 @@ use AssoBundle\Form\Membre\MembreType;
class MembreController extends Controller
{
/**
*
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request)
{
$membre = new Membre();
$form = $this->createForm(MembreType::class, $membre);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($membre);
$em->flush();
return $this->redirectToRoute('asso_membre_read');
}
return $this->render('@Asso/Membre/create.html.twig', array(
'formMembre' => $form->createView()
));
}
/**
*
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function readAction()
......@@ -49,5 +47,53 @@ class MembreController extends Controller
));
}
/**
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$membre = $em->getRepository('AssoBundle:Membre')->findOneByUpdate($id);
if ($membre === null) {
throw $this->createNotFoundException();
}
$form = $this->createForm(MembreType::class, $membre);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->persist($membre);
$em->flush();
return $this->redirectToRoute('asso_membre_read');
}
return $this->render('@Asso/Membre/update.html.twig', array(
'id' => $id,
'formMembre' => $form->createView()
));
}
/**
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$membre = $em->getRepository('AssoBundle:Membre')->findOneByDelete($id);
if ($membre !== null)
{
$em->remove($membre);
$em->flush();
return $this->redirectToRoute('asso_membre_read');
}
}
}
......@@ -21,8 +21,8 @@ class MembreType extends AbstractType
{
parent::buildForm($builder, $options);
$builder->add('nom', TextType::class);
$builder->add('prenom', TextType::class);
$builder->add('nom', TextType::class);
$builder->add('email', TextType::class);
$builder->add('association', EntityType::class, array(
'class' => Association::class,
......
......@@ -10,8 +10,11 @@ namespace AssoBundle\Repository;
*/
class MembreRepository extends \Doctrine\ORM\EntityRepository
{
public function findAllByIndex()
/**
* @return Membre[]
*/
public function findAllByIndex()
{
$qb = $this->createQueryBuilder('m')
->join('m.association', 'a')
......@@ -19,6 +22,35 @@ class MembreRepository extends \Doctrine\ORM\EntityRepository
->orderBy('m.id', 'ASC');
return $qb->getQuery()->getResult();
}
/**
* @param $id
* @return Membre
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByUpdate($id)
{
$qb = $this->createQueryBuilder('m')
->join('m.association', 'a')
->addSelect('a')
->where('m.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return Membre
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByDelete($id)
{
$qb = $this->createQueryBuilder('m')
->where('m.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -17,3 +17,13 @@ asso_membre_create:
path: /membre/add
defaults:
_controller: AssoBundle:Membre:create
asso_membre_update:
path: /membre/edit/{id}
defaults:
_controller: AssoBundle:Membre:update
asso_membre_delete:
path: /membre/delete/{id}
defaults:
_controller: AssoBundle:Membre:delete
{% extends "@Asso/base.html.twig" %}
{% block title %}
Créer les membres
Créer un membre
{% endblock %}
{% block body %}
......
......@@ -8,12 +8,15 @@
<h2>{{ block('title') }}</h2>
<ul>
{% for membre in membres %}
<li>
{{ membre.nom }}
{{ membre.prenom }}
{{ membre.email }}
{{ membre.getAssociation().nom }}
</li>
<li>
{{ membre.nom }}
{{ membre.prenom }}
{{ membre.email }}
{{ membre.getAssociation().nom }}
<a href="{{ path('asso_membre_update', {'id': membre.id }) }}">Editer</a>
<a href="{{ path('asso_membre_delete', {'id': membre.id }) }}">Effacer</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% extends "@Asso/base.html.twig" %}
{% block title %}
Modifier le membre n° {{ id }}
{% endblock %}
{% block body %}
<h2>{{ block('title') }}</h2>
{{ form(formMembre) }}
{% 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