mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 08:33:49 +00:00
feature: update an existing participation
The update allow to modify the status and role of a participation. ref #8
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user