adding remove event feature

This commit is contained in:
2019-11-28 17:37:24 +01:00
parent 8618efc35a
commit 30e0c663dc
7 changed files with 135 additions and 26 deletions

View File

@@ -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()
;
}
}

View File

@@ -19,8 +19,8 @@
namespace Chill\EventBundle\Controller;
use ArrayIterator;
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;
@@ -31,8 +31,9 @@ use Chill\EventBundle\Security\Authorization\ParticipationVoter;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
/**
*
* Class ParticipationController
*
* @package Chill\EventBundle\Controller
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ParticipationController extends Controller
@@ -44,9 +45,9 @@ class ParticipationController extends Controller
* This function parse the person_id / persons_ids query argument
* and decide if it should process a single or multiple participation. Depending
* on this, the appropriate layout and form.
*
*
* @param Request $request
* @return Response
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function newAction(Request $request)
{
@@ -158,9 +159,9 @@ class ParticipationController extends Controller
*
* If all participations must be ignored, an error is shown and the method redirects
* to the event 'show' view with an appropriate flash message.
*
*
* @param Request $request
* @return Response
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
protected function newMultiple(Request $request)
{
@@ -224,6 +225,10 @@ class ParticipationController extends Controller
}
}
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function createAction(Request $request)
{
// test the request is correct
@@ -257,6 +262,10 @@ class ParticipationController extends Controller
. "'persons_ids' argument in query");
}
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function createSingle(Request $request)
{
$participation = $this->handleRequest($request, new Participation(), false);
@@ -295,6 +304,10 @@ class ParticipationController extends Controller
));
}
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function createMultiple(Request $request)
{
$participations = $this->handleRequest($request, new Participation(), true);
@@ -431,9 +444,8 @@ class ParticipationController extends Controller
}
/**
*
* @param array $participations
* @return type
* @return \Symfony\Component\Form\FormInterface
*/
public function createCreateFormMultiple(array $participations)
{
@@ -491,6 +503,11 @@ class ParticipationController extends Controller
));
}
/**
* @param $participation_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function updateAction($participation_id, Request $request)
{
/* @var $participation Participation */
@@ -640,15 +657,12 @@ class ParticipationController extends Controller
}
/**
*
* @param \Doctrine\Common\Collections\Collection $participations contains object of Participation type
* @param \Chill\EventBundle\Entity\Event $event
* @param ArrayIterator $participations
* @param Event $event
* @return \Symfony\Component\Form\FormInterface
*/
protected function createEditFormMultiple(
\Doctrine\Common\Collections\Collection $participations,
\Chill\EventBundle\Entity\Event $event
) {
protected function createEditFormMultiple(ArrayIterator $participations, Event $event)
{
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
array('participations' => $participations), array(
'method' => 'POST',
@@ -710,7 +724,7 @@ class ParticipationController extends Controller
]);
}
}
return $this->render('ChillEventBundle:Event:confirm_delete.html.twig', [
return $this->render('ChillEventBundle:Participation:confirm_delete.html.twig', [
'event_id' => $event->getId(),
'delete_form' => $form->createView()
]);