Skip to content

Commit

Permalink
Ref #8 : première version du CRUD des événements
Browse files Browse the repository at this point in the history
  • Loading branch information
DarckCrystale committed Jun 25, 2017
1 parent 685f2d5 commit fc10229
Show file tree
Hide file tree
Showing 9 changed files with 684 additions and 0 deletions.
52 changes: 52 additions & 0 deletions app/Resources/views/evenement/detail.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Evenement</h1>

<table>
<tbody>
<tr>
<th>Id</th>
<td>{{ evenement.id }}</td>
</tr>
<tr>
<th>Label</th>
<td>{{ evenement.label }}</td>
</tr>
<tr>
<th>Description</th>
<td>{{ evenement.description }}</td>
</tr>
<tr>
<th>Datecreation</th>
<td>{% if evenement.dateCreation %}{{ evenement.dateCreation|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
<tr>
<th>Datedebut</th>
<td>{% if evenement.dateDebut %}{{ evenement.dateDebut|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
<tr>
<th>Datefin</th>
<td>{% if evenement.dateFin %}{{ evenement.dateFin|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
<tr>
<th>Slug</th>
<td>{{ evenement.slug }}</td>
</tr>
</tbody>
</table>

<ul>
<li>
<a href="{{ path('evenement_liste') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('evenement_editer', { 'slug': evenement.slug }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}
21 changes: 21 additions & 0 deletions app/Resources/views/evenement/editer.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Evenement edit</h1>

{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
{{ form_end(edit_form) }}

<ul>
<li>
<a href="{{ path('evenement_liste') }}">Back to the list</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}
49 changes: 49 additions & 0 deletions app/Resources/views/evenement/liste.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Evenements list</h1>

<table>
<thead>
<tr>
<th>Id</th>
<th>Label</th>
<th>Description</th>
<th>Datecreation</th>
<th>Datedebut</th>
<th>Datefin</th>
<th>Slug</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for evenement in evenements %}
<tr>
<td><a href="{{ path('evenement_detail', { 'slug': evenement.slug }) }}">{{ evenement.id }}</a></td>
<td>{{ evenement.label }}</td>
<td>{{ evenement.description }}</td>
<td>{% if evenement.dateCreation %}{{ evenement.dateCreation|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>{% if evenement.dateDebut %}{{ evenement.dateDebut|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>{% if evenement.dateFin %}{{ evenement.dateFin|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>{{ evenement.slug }}</td>
<td>
<ul>
<li>
<a href="{{ path('evenement_detail', { 'slug': evenement.slug }) }}">show</a>
</li>
<li>
<a href="{{ path('evenement_editer', { 'slug': evenement.slug }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<ul>
<li>
<a href="{{ path('evenement_nouveau') }}">Create a new evenement</a>
</li>
</ul>
{% endblock %}
16 changes: 16 additions & 0 deletions app/Resources/views/evenement/nouveau.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Evenement creation</h1>

{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}

<ul>
<li>
<a href="{{ path('evenement_liste') }}">Back to the list</a>
</li>
</ul>
{% endblock %}
152 changes: 152 additions & 0 deletions src/AppBundle/Controller/EvenementController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

namespace AppBundle\Controller;

use AppBundle\Entity\Evenement;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;

/**
* Evenement controller.
*
* @Route("evenement")
*/
class EvenementController extends Controller
{
/**
* Lists all evenement entities.
*
* @Route("/", name="evenement_liste")
* @Method("GET")
*/
public function listeAction()
{
$em = $this->getDoctrine()->getManager();
$evenements = $em->getRepository('AppBundle:Evenement')->findAll();

$deleteForms = [];

foreach($evenements as $evenement)
{
$deleteForm = $this->createDeleteForm($evenement);
$deleteForms[$evenement->getId()] = $deleteForm->createView();
}

return $this->render('evenement/liste.html.twig', [
'evenements' => $evenements,
'forms_supprimer' => $deleteForms,
]);
}

/**
* Creates a new evenement entity.
*
* @Route("/nouveau", name="evenement_nouveau")
* @Method({"GET", "POST"})
*/
public function nouveauAction(Request $request)
{
$em = $this->getDoctrine()->getManager();

$evenement = new Evenement();
$form = $this->createForm('AppBundle\Form\EvenementType', $evenement);
$form->handleRequest($request);

$evenement->setDateCreation(new \DateTime());
// TODO:
// Remplacer l'id 2 par l'id de l'utilisateur connecté
$createur = $em->getRepository('AppBundle:Utilisateur')->find(2);
$evenement->setCreateur($createur);

if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($evenement);
$em->flush();

return $this->redirectToRoute('evenement_detail', ['slug' => $evenement->getSlug()]);
}

return $this->render('evenement/nouveau.html.twig', [
'evenement' => $evenement,
'form' => $form->createView(),
]);
}

/**
* Finds and displays a evenement entity.
*
* @Route("/{slug}", name="evenement_detail")
* @Method("GET")
*/
public function detailAction(Evenement $evenement)
{
$deleteForm = $this->createDeleteForm($evenement);

return $this->render('evenement/detail.html.twig', array(
'evenement' => $evenement,
'delete_form' => $deleteForm->createView(),
));
}

/**
* Displays a form to edit an existing evenement entity.
*
* @Route("/editer/{slug}", name="evenement_editer")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Evenement $evenement)
{
$deleteForm = $this->createDeleteForm($evenement);
$editForm = $this->createForm('AppBundle\Form\EvenementType', $evenement);
$editForm->handleRequest($request);

if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();

return $this->redirectToRoute('evenement_editer', ['slug' => $evenement->getSlug()]);
}

return $this->render('evenement/editer.html.twig', [
'evenement' => $evenement,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
]);
}

/**
* Deletes a evenement entity.
*
* @Route("/supprimer/{slug}", name="evenement_supprimer")
* @Method("DELETE")
*/
public function deleteAction(Request $request, Evenement $evenement)
{
$form = $this->createDeleteForm($evenement);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($evenement);
$em->flush();
}

return $this->redirectToRoute('evenement_liste');
}

/**
* Creates a form to delete a evenement entity.
*
* @param Evenement $evenement The evenement entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Evenement $evenement)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('evenement_supprimer', ['slug' => $evenement->getSlug()]))
->setMethod('DELETE')
->getForm()
;
}
}
Loading

0 comments on commit fc10229

Please sign in to comment.