From 993882e92504b09e7caf2cad2e1e5e56c3588366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 14:18:03 +0100 Subject: [PATCH 1/2] feature: update an existing participation The update allow to modify the status and role of a participation. ref #8 --- Controller/ParticipationController.php | 90 ++++++++++++++++++++ Resources/config/routing/participation.yml | 9 ++ Resources/translations/messages.fr.yml | 1 + Resources/views/Event/show.html.twig | 7 +- Resources/views/Participation/edit.html.twig | 41 +++++++++ Resources/views/Participation/new.html.twig | 2 + 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 Resources/views/Participation/edit.html.twig diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 8b9685462..8cf065706 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -148,4 +148,94 @@ class ParticipationController extends Controller return $form; } + /** + * show an edit form for the participation with the given id. + * + * @param int $participation_id + * @return \Symfony\Component\HttpFoundation\Response + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found + * @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation + */ + public function editAction($participation_id) + { + /* @var $participation Participation */ + $participation = $this->getDoctrine()->getManager() + ->getRepository('ChillEventBundle:Participation') + ->find($participation_id); + + if ($participation === NULL) { + throw $this->createNotFoundException('The participation is not found'); + } + + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + 'You are not allowed to edit this participation'); + + $form = $this->createEditForm($participation); + + return $this->render('ChillEventBundle:Participation:edit.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + public function updateAction($participation_id, Request $request) + { + /* @var $participation Participation */ + $participation = $this->getDoctrine()->getManager() + ->getRepository('ChillEventBundle:Participation') + ->find($participation_id); + + if ($participation === NULL) { + throw $this->createNotFoundException('The participation is not found'); + } + + $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation, + 'You are not allowed to edit this participation'); + + $form = $this->createEditForm($participation); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans( + 'The participation was updated' + )); + + return $this->redirectToRoute('event_show', array( + 'event_id' => $participation->getEvent()->getId() + )); + + } + + return $this->render('ChillEventBundle:Participation:edit.html.twig', array( + 'form' => $form->createView(), + 'participation' => $participation + )); + } + + /** + * + * @param Participation $participation + * @return \Symfony\Component\Form\FormInterface + */ + public function createEditForm(Participation $participation) + { + $form = $this->createForm(ParticipationType::class, $participation, array( + 'event_type' => $participation->getEvent()->getType(), + 'action' => $this->generateUrl('chill_event_participation_update', array( + 'participation_id' => $participation->getId() + )) + )); + + $form->add('submit', SubmitType::class, array( + 'label' => 'Edit' + )); + + return $form; + } + } diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml index f79e584a6..54d18fb71 100644 --- a/Resources/config/routing/participation.yml +++ b/Resources/config/routing/participation.yml @@ -5,3 +5,12 @@ chill_event_participation_new: chill_event_participation_create: path: /create defaults: { _controller: ChillEventBundle:Participation:create } + +chill_event_participation_edit: + path: /{participation_id}/edit + defaults: { _controller: ChillEventBundle:Participation:edit } + +chill_event_participation_update: + path: /{participation_id}/update + defaults: { _controller: ChillEventBundle:Participation:update } + methods: [POST] diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index e5d2a5e98..91e7e1ea8 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -19,6 +19,7 @@ Associated person: Personne associée Associated event: Événement associé Back to the event: Retour à l'événement The participation was created: La participation a été créée +The participation was updated: La participation a été mise à jour #search Event search: Recherche d'événements diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig index 720075281..e28fec753 100644 --- a/Resources/views/Event/show.html.twig +++ b/Resources/views/Event/show.html.twig @@ -57,14 +57,17 @@ {{ person_macro.render(participation.person) }} {{ participation.role.label|localize_translatable_string }} {{ participation.status.label|localize_translatable_string }} - {{ participation.lastUpdate|localizeddate("long", "none") }} + {{ participation.lastUpdate|time_diff }} diff --git a/Resources/views/Participation/edit.html.twig b/Resources/views/Participation/edit.html.twig new file mode 100644 index 000000000..438fba6b3 --- /dev/null +++ b/Resources/views/Participation/edit.html.twig @@ -0,0 +1,41 @@ +{% extends 'ChillEventBundle::layout.html.twig' %} + +{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} + +{% block event_content -%} +

{{ 'Participation Edit'|trans }}

+ + + + + + + + + + + + + + + + +
{{ 'Associated person'|trans }}{{ person_macro.render(participation.person) }}
{{ 'Associated event'|trans }} {{ participation.event.label }}
{{ 'Date'|trans }} {{ participation.event.date|localizeddate('long', 'none') }}
+ + {{ form_start(form) }} + {{ form_row(form.role) }} + {{ form_row(form.status) }} + + + + {{ form_end(form) }} +{% endblock %} diff --git a/Resources/views/Participation/new.html.twig b/Resources/views/Participation/new.html.twig index bd99347fe..cbf6c72bd 100644 --- a/Resources/views/Participation/new.html.twig +++ b/Resources/views/Participation/new.html.twig @@ -2,6 +2,8 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} +{% block title 'Participation creation'|trans %} + {% block event_content -%}

{{ 'Participation creation'|trans }}

From 3ac192d34cde31672eb6d89fbebc3913e50ba4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 24 Mar 2016 14:30:08 +0100 Subject: [PATCH 2/2] remove empty default controller --- Controller/DefaultController.php | 13 ------------- Resources/views/Default/index.html.twig | 1 - Tests/Controller/DefaultControllerTest.php | 17 ----------------- 3 files changed, 31 deletions(-) delete mode 100644 Controller/DefaultController.php delete mode 100644 Resources/views/Default/index.html.twig delete mode 100644 Tests/Controller/DefaultControllerTest.php diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php deleted file mode 100644 index 6d455c21a..000000000 --- a/Controller/DefaultController.php +++ /dev/null @@ -1,13 +0,0 @@ -render('ChillEventBundle:Default:index.html.twig', array('name' => $name)); - } -} diff --git a/Resources/views/Default/index.html.twig b/Resources/views/Default/index.html.twig deleted file mode 100644 index 4ce626e9b..000000000 --- a/Resources/views/Default/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -Hello {{ name }}! diff --git a/Tests/Controller/DefaultControllerTest.php b/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 5c2a813f4..000000000 --- a/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -}