mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
parent
c1b9069138
commit
78c53fe7b0
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -80,7 +80,7 @@
|
||||
|
||||
<ul class="record_actions">
|
||||
{% if count > 0 %}
|
||||
<li><a href="#" class="sc-button bt-edit">{{ 'Edit all the participations'|trans }}</a></li>
|
||||
<li><a href="{{ path('chill_event_participation_edit_multiple', { 'event_id' : event.id } ) }}" class="sc-button bt-edit">{{ 'Edit all the participations'|trans }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
|
60
Resources/views/Participation/edit-multiple.html.twig
Normal file
60
Resources/views/Participation/edit-multiple.html.twig
Normal file
@ -0,0 +1,60 @@
|
||||
{% extends 'ChillEventBundle::layout.html.twig' %}
|
||||
|
||||
{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %}
|
||||
|
||||
{% block event_content -%}
|
||||
<h1>{{ 'Participation Edit'|trans }}</h1>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{{ 'Associated event'|trans }} </th>
|
||||
<td>{{ event.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{ 'Date'|trans }} </th>
|
||||
<td>{{ event.date|localizeddate('long', 'none') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>{{ 'Participations'|trans }}</h2>
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Person'|trans }}</th>
|
||||
<th>{{ 'Role'|trans }}</th>
|
||||
<th>{{ 'Status'|trans }}</th>
|
||||
<th>{{ 'Last update'|trans }}</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for participation in form.participations %}
|
||||
<tr>
|
||||
<td>{{ person_macro.render(participation.vars.value.person) }}</td>
|
||||
<td>{{ form_widget(participation.role) }}</td>
|
||||
<td>{{ form_widget(participation.status) }}</td>
|
||||
<td>{{ participation.vars.value.lastUpdate|time_diff }} <i class="fa fa-info-circle" title="{{ participation.vars.value.lastUpdate|localizeddate("long", "medium")|escape('html_attr') }}"></i></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('chill_event__event_show', { 'event_id' : event.id } ) }}" class="sc-button bt-cancel">
|
||||
<i class="fa fa-arrow-left"></i>
|
||||
{{ 'Back to the event'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button bt-edit' } } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
@ -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'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user