adding remove participation method

This commit is contained in:
2019-11-28 16:38:03 +01:00
parent 6fe4594d3c
commit 8618efc35a
5 changed files with 103 additions and 3 deletions

View File

@@ -19,6 +19,8 @@
namespace Chill\EventBundle\Controller;
use Chill\EventBundle\Entity\Event;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -551,8 +553,9 @@ class ParticipationController extends Controller
/**
* show a form to edit multiple participation for the same event.
*
*
* @param int $event_id
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function editMultipleAction($event_id)
{
@@ -637,8 +640,8 @@ class ParticipationController extends Controller
}
/**
*
* @param \Doctrine\Common\Collections\Collectionn $participations contains object of Participation type
*
* @param \Doctrine\Common\Collections\Collection $participations contains object of Participation type
* @param \Chill\EventBundle\Entity\Event $event
* @return \Symfony\Component\Form\FormInterface
*/
@@ -669,4 +672,65 @@ class ParticipationController extends Controller
return $form;
}
/**
* @param integer $participation_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function deleteAction($participation_id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$participation = $em->getRepository('ChillEventBundle:Participation')->findOneBy([
'id' => $participation_id
]);
if (! $participation) {
throw $this->createNotFoundException('Unable to find participation.');
}
/** @var Event $event */
$event = $participation->getEvent();
$form = $this->createDeleteForm($participation_id);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$em->remove($participation);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The participation has been sucessfully removed")
);
return $this->redirectToRoute('chill_event__event_show', [
'event_id' => $event->getId()
]);
}
}
return $this->render('ChillEventBundle:Event:confirm_delete.html.twig', [
'event_id' => $event->getId(),
'delete_form' => $form->createView()
]);
}
/**
* @param $participation_id
* @return \Symfony\Component\Form\FormInterface
*/
private function createDeleteForm($participation_id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('chill_event_participation_delete', [
'participation_id' => $participation_id
]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm()
;
}
}