adding remove event feature

This commit is contained in:
Tchama 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()
]);

View File

@ -41,3 +41,9 @@ chill_event__list_by_person:
defaults: { _controller: "ChillEventBundle:Event:listByPerson" }
methods: [ GET ]
chill_event__event_delete:
path: /{event_id}/delete
requirements:
event_id: \d+
defaults: { _controller: "ChillEventBundle:Event:delete" }
methods: [ GET, DELETE ]

View File

@ -44,11 +44,13 @@ The participation was updated: La participation a été mise à jour
There are no participation to edit for this event: Il n'y a pas de participation pour cet événement
The participations have been successfully updated.: Les participations ont été mises à jour.
The participation has been sucessfully removed: La participation a été correctement supprimée.
The event has been sucessfully removed: L'événement et toutes les participations associées ont été correctement supprimées.
The participations were created: Les participations ont été créées
Events participation: Participation aux événements
Remove participation: Supprimer la participation
Delete event: Supprimer l'événement
Are you sure you want to remove that participation ?: Êtes-vous certain de vouloir supprimer cette participation ?
Are you sure you want to remove that event ?: Êtes-vous certain de vouloir supprimer cet événement, ainsi que toutes les participations associées ?
#search
Event search: Recherche d'événements

View File

@ -2,14 +2,14 @@
{% set activeRouteKey = 'chill_event__event_show' %}
{% block title 'Remove participation'|trans %}
{% block title 'Delete event'|trans %}
{% block event_content %}
{{ include('ChillMainBundle:Util:confirmation_template.html.twig',
{
'title' : 'Remove participation'|trans,
'confirm_question' : 'Are you sure you want to remove that participation ?'|trans,
'title' : 'Delete event'|trans,
'confirm_question' : 'Are you sure you want to remove that event ?'|trans,
'cancel_route' : activeRouteKey,
'cancel_parameters' : { 'event_id' : event_id },
'form' : delete_form

View File

@ -57,6 +57,10 @@
</a>
</li>
{% endif %}
<li>
<a href="{{ path('chill_event__event_delete', {'event_id' : event.id } ) }}"
class="sc-button bt-delete">{{ 'Delete event'|trans }}</a>
</li>
</ul>
@ -87,13 +91,11 @@
{% if is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %}
<li>
<a href="{{ path('chill_event_participation_edit', { 'participation_id' : participation.id } ) }}"
class="sc-button bt-edit">
{{ 'Edit'|trans }}
</a>
class="sc-button bt-edit" title="{{ 'Edit'|trans }}"></a>
</li>
<li>
<a href="{{ path('chill_event_participation_delete', {'participation_id' : participation.id } ) }}"
class="sc-button bt-delete"></a>
class="sc-button bt-delete" title="{{ 'Delete'|trans }}"></a>
</li>
{% endif %}
</ul>

View File

@ -0,0 +1,20 @@
{% extends 'ChillEventBundle::layout.html.twig' %}
{% set activeRouteKey = 'chill_event__event_show' %}
{% block title 'Remove participation'|trans %}
{% block event_content %}
{{ include('ChillMainBundle:Util:confirmation_template.html.twig',
{
'title' : 'Remove participation'|trans,
'confirm_question' : 'Are you sure you want to remove that participation ?'|trans,
'cancel_route' : activeRouteKey,
'cancel_parameters' : { 'event_id' : event_id },
'form' : delete_form
}
) }}
{% endblock %}