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 @@
{{ 'Associated person'|trans }} | +{{ person_macro.render(participation.person) }} | +
---|---|
{{ 'Associated event'|trans }} | +{{ participation.event.label }} | +
{{ 'Date'|trans }} | +{{ participation.event.date|localizeddate('long', 'none') }} | +