diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php
index e2eaa3fa2..ca2a5f953 100644
--- a/Controller/ParticipationController.php
+++ b/Controller/ParticipationController.php
@@ -526,4 +526,124 @@ class ParticipationController extends Controller
return $form;
}
+ /**
+ * show a form to edit multiple participation for the same event.
+ *
+ * @param int $event_id
+ */
+ public function editMultipleAction($event_id)
+ {
+ $event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
+ ->find($event_id);
+
+ if ($event === null) {
+ throw $this->createNotFoundException("The event with id $event_id is not found");
+ }
+
+ // check for ACL, on Event level and on Participation Level
+ $this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
+ . "to see this event");
+ foreach ($event->getParticipations() as $participation) {
+ $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
+ "You are not allowed to update participation with id ".$participation->getId());
+ }
+
+
+ switch ($event->getParticipations()->count()) {
+
+ case 0:
+ // if there aren't any participation, redirect to the 'show' view with an add flash
+ $this->addFlash('warning', $this->get('translator')
+ ->trans( "There are no participation to edit for this event"));
+
+ return $this->redirectToRoute('chill_event__event_show',
+ array('event_id' => $event->getId()));
+
+ case 1:
+ // redirect to the form for a single participation
+ return $this->redirectToRoute('chill_event_participation_edit', array(
+ 'participation_id' => $event->getParticipations()->first()->getId()
+ ));
+ }
+
+ $form = $this->createEditFormMultiple($event->getParticipations(), $event);
+
+ return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
+ 'event' => $event,
+ 'participations' => $event->getParticipations(),
+ 'form' => $form->createView()
+ ));
+ }
+
+ public function updateMultipleAction($event_id, Request $request)
+ {
+ /* @var $event \Chill\EventBundle\Entity\Event */
+ $event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
+ ->find($event_id);
+
+ if ($event === null) {
+ throw $this->createNotFoundException("The event with id $event_id is not found");
+ }
+
+ $this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
+ . "to see this event");
+ foreach ($event->getParticipations() as $participation) {
+ $this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
+ "You are not allowed to update participation with id ".$participation->getId());
+ }
+
+ $form = $this->createEditFormMultiple($event->getParticipations(), $event);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->getDoctrine()->getManager()->flush();
+
+ $this->addFlash('success', $this->get('translator')->trans("The participations "
+ . "have been successfully updated."));
+
+ return $this->redirectToRoute('chill_event__event_show',
+ array('event_id' => $event->getId()));
+ }
+
+ return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
+ 'event' => $event,
+ 'participations' => $event->getParticipations(),
+ 'form' => $form->createView()
+ ));
+ }
+
+ /**
+ *
+ * @param \Doctrine\Common\Collections\Collectionn $participations contains object of Participation type
+ * @param \Chill\EventBundle\Entity\Event $event
+ * @return \Symfony\Component\Form\FormInterface
+ */
+ protected function createEditFormMultiple(
+ \Doctrine\Common\Collections\Collection $participations,
+ \Chill\EventBundle\Entity\Event $event
+ ) {
+ $form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
+ array('participations' => $participations), array(
+ 'method' => 'POST',
+ 'action' => $this->generateUrl('chill_event_participation_update_multiple', array(
+ 'event_id' => $event->getId()
+ ))
+ ));
+
+ $form->add('participations', CollectionType::class, array(
+ 'entry_type' => ParticipationType::class,
+ 'entry_options' => array(
+ 'event_type' => $event->getType()
+ ),
+ )
+ );
+
+ $form->add('submit', SubmitType::class, array(
+ 'label' => 'Update'
+ ));
+
+ return $form;
+ }
+
}
diff --git a/Resources/config/routing/participation.yml b/Resources/config/routing/participation.yml
index 54d18fb71..bbb727382 100644
--- a/Resources/config/routing/participation.yml
+++ b/Resources/config/routing/participation.yml
@@ -14,3 +14,12 @@ chill_event_participation_update:
path: /{participation_id}/update
defaults: { _controller: ChillEventBundle:Participation:update }
methods: [POST]
+
+chill_event_participation_edit_multiple:
+ path: /{event_id}/edit_multiple
+ defaults: { _controller: ChillEventBundle:Participation:editMultiple }
+
+chill_event_participation_update_multiple:
+ path: /{event_id}/update_multiple
+ defaults: { _controller: ChillEventBundle:Participation:updateMultiple }
+ methods: [POST]
diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml
index 3d1d9c4ca..4af7a2b83 100644
--- a/Resources/translations/messages.fr.yml
+++ b/Resources/translations/messages.fr.yml
@@ -8,6 +8,7 @@ Event: Événement
Events: Événements
'Event : %label%': Événement "%label%"
Participation: Participation
+Participations: Participations
Status: Statut
Last update: Dernière mise à jour
'%count% participations to this event': '{0} Aucun participant à l''événement | {1} Un participant à l''événement | ]1,Inf] %count% participants à l''événement'
@@ -34,6 +35,8 @@ The participation was updated: La participation a été mise à jour
Participation Edit: Modifier une participation
'Any of the requested people may be added on the event: they are maybe already participating.': 'Aucune des personnes suggérées ne peut être ajoutée à l''événement: elles sont peut-être déjà inscrites comme participantes.'
'The following people have been ignored because they are already participating on the event': '{1} La personne suivante a été ignorée parce qu''elle participe déjà à l''événement | ]1,Inf] Les personnes suivantes ont été ignorées parce qu''elles participent déjà à l''événement'
+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.
#search
Event search: Recherche d'événements
diff --git a/Resources/views/Event/show.html.twig b/Resources/views/Event/show.html.twig
index a94d7e1ba..e2aa9caf3 100644
--- a/Resources/views/Event/show.html.twig
+++ b/Resources/views/Event/show.html.twig
@@ -80,7 +80,7 @@
diff --git a/Resources/views/Participation/edit-multiple.html.twig b/Resources/views/Participation/edit-multiple.html.twig
new file mode 100644
index 000000000..747b53260
--- /dev/null
+++ b/Resources/views/Participation/edit-multiple.html.twig
@@ -0,0 +1,60 @@
+{% extends 'ChillEventBundle::layout.html.twig' %}
+
+{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %}
+
+{% block event_content -%}
+ {{ 'Participation Edit'|trans }}
+
+
+
+
+ {{ 'Associated event'|trans }} |
+ {{ event.name }} |
+
+
+ {{ 'Date'|trans }} |
+ {{ event.date|localizeddate('long', 'none') }} |
+
+
+
+
+ {{ 'Participations'|trans }}
+
+ {{ form_start(form) }}
+
+
+
+
+ {{ 'Person'|trans }} |
+ {{ 'Role'|trans }} |
+ {{ 'Status'|trans }} |
+ {{ 'Last update'|trans }} |
+ |
+
+
+
+ {% for participation in form.participations %}
+
+ {{ person_macro.render(participation.vars.value.person) }} |
+ {{ form_widget(participation.role) }} |
+ {{ form_widget(participation.status) }} |
+ {{ participation.vars.value.lastUpdate|time_diff }} |
+
+ {% endfor %}
+
+
+
+
+
+ {{ form_end(form) }}
+{% endblock %}
diff --git a/Tests/Controller/ParticipationControllerTest.php b/Tests/Controller/ParticipationControllerTest.php
index d912b206f..a51fae197 100644
--- a/Tests/Controller/ParticipationControllerTest.php
+++ b/Tests/Controller/ParticipationControllerTest.php
@@ -341,7 +341,7 @@ class ParticipationControllerTest extends WebTestCase
$this->assertEquals($nbParticipations + 2, $event->getParticipations()->count());
}
- public function testMultipleWithAllPeopleParticipating()
+ public function testNewMultipleWithAllPeopleParticipating()
{
$event = $this->getRandomEventWithMultipleParticipations();
@@ -359,7 +359,7 @@ class ParticipationControllerTest extends WebTestCase
"test that /fr/event/participation/new is redirecting");
}
- public function testMultipleWithSomePeopleParticipating()
+ public function testNewMultipleWithSomePeopleParticipating()
{
$event = $this->getRandomEventWithMultipleParticipations();
// record the number of participation for the event (used later in this test)
@@ -419,5 +419,30 @@ class ParticipationControllerTest extends WebTestCase
"Test we have persisted a new participation associated to the test");
}
+ public function testEditMultipleAction()
+ {
+ /* @var $event \Chill\EventBundle\Entity\Event */
+ $event = $this->getRandomEventWithMultipleParticipations();
+
+ $crawler = $this->client->request('GET', '/fr/event/participation/'.$event->getId().
+ '/edit_multiple');
+
+ $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+ $button = $crawler->selectButton('Mettre à jour');
+ $this->assertEquals(1, $button->count(), "test the form with button 'mettre à jour' exists ");
+
+
+ $this->client->submit($button->form(), array(
+ 'form[participations][0][role]' => $event->getType()->getRoles()->first()->getId(),
+ 'form[participations][0][status]' => $event->getType()->getStatuses()->first()->getId(),
+ 'form[participations][1][role]' => $event->getType()->getRoles()->last()->getId(),
+ 'form[participations][1][status]' => $event->getType()->getStatuses()->last()->getId(),
+ ));
+
+ $this->assertTrue($this->client->getResponse()
+ ->isRedirect('/fr/event/event/'.$event->getId().'/show'));
+ }
+
}