mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
adding remove participation method
This commit is contained in:
@@ -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()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user