mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 22:04:59 +00:00
adding remove event feature
This commit is contained in:
@@ -30,7 +30,6 @@ use PhpOffice\PhpSpreadsheet\Writer\Ods;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Chill\EventBundle\Security\Authorization\EventVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -49,6 +48,7 @@ use Chill\MainBundle\Entity\Center;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -210,7 +210,7 @@ class EventController extends Controller
|
||||
/**
|
||||
* Finds and displays a Event entity.
|
||||
*
|
||||
* @paramConverter("event", options={"id" = "event_id"})
|
||||
* @ParamConverter("event", options={"id" = "event_id"})
|
||||
* @param Event $event
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
@@ -604,4 +604,69 @@ class EventController extends Controller
|
||||
return $spreadsheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event_id
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteAction($event_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$event = $em->getRepository('ChillEventBundle:Event')->findOneBy([
|
||||
'id' => $event_id
|
||||
]);
|
||||
|
||||
if (! $event) {
|
||||
throw $this->createNotFoundException('Unable to find this event.');
|
||||
}
|
||||
|
||||
/** @var array $participations */
|
||||
$participations = $event->getParticipations();
|
||||
|
||||
$form = $this->createDeleteForm($event_id);
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
foreach ($participations as $participation) {
|
||||
$em->remove($participation);
|
||||
}
|
||||
|
||||
$em->remove($event);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans("The event has been sucessfully removed")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_main_search', [
|
||||
'name' => 'event_regular',
|
||||
'q' => '@event'
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->render('ChillEventBundle:Event:confirm_delete.html.twig', [
|
||||
'event_id' => $event->getId(),
|
||||
'delete_form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event_id
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createDeleteForm($event_id)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_event__event_delete', [
|
||||
'event_id' => $event_id
|
||||
]))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user