mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
improve phpspreadsheet participations list export
This commit is contained in:
parent
59668f45a2
commit
be37d9d73a
@ -197,31 +197,37 @@ class EventController extends Controller
|
|||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and displays a Event entity.
|
* Finds and displays a Event entity.
|
||||||
*
|
*
|
||||||
* @param $event_id
|
* @paramConverter("event", options={"id" = "event_id"})
|
||||||
|
* @param Event $event
|
||||||
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||||
*/
|
*/
|
||||||
public function showAction($event_id)
|
public function showAction(Event $event, Request $request)
|
||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
if (!$event) {
|
||||||
|
|
||||||
$entity = $em->getRepository('ChillEventBundle:Event')->find($event_id);
|
|
||||||
|
|
||||||
if (!$entity) {
|
|
||||||
throw $this->createNotFoundException('Unable to find Event entity.');
|
throw $this->createNotFoundException('Unable to find Event entity.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $entity,
|
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE_DETAILS', $event,
|
||||||
"You are not allowed to see details on this event");
|
"You are not allowed to see details on this event");
|
||||||
|
|
||||||
$addParticipationByPersonForm = $this->createAddParticipationByPersonForm($entity);
|
$addParticipationByPersonForm = $this->createAddParticipationByPersonForm($event);
|
||||||
|
|
||||||
|
$exportParticipationsList = $this->exportParticipationsList($event, $request);
|
||||||
|
|
||||||
|
if ($exportParticipationsList['response']) {
|
||||||
|
return $exportParticipationsList['response'];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Event:show.html.twig', array(
|
return $this->render('ChillEventBundle:Event:show.html.twig', array(
|
||||||
'event' => $entity,
|
'event' => $event,
|
||||||
'form_add_participation_by_person' => $addParticipationByPersonForm->createView()
|
'form_add_participation_by_person' => $addParticipationByPersonForm->createView(),
|
||||||
|
'form_export' => $exportParticipationsList['form']->createView()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,40 +456,23 @@ class EventController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @paramConverter("event", options={"id" = "event_id"})
|
|
||||||
* @param Event $event
|
* @param Event $event
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return array
|
||||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||||
*/
|
*/
|
||||||
public function exportParticipationsAction(Event $event, Request $request)
|
protected function exportParticipationsList(Event $event, Request $request)
|
||||||
{
|
{
|
||||||
$builder = $this->createFormBuilder()
|
$form = $this->createExportByFormatForm();
|
||||||
->add('format', ChoiceType::class, [
|
|
||||||
'choices' => [
|
|
||||||
'xlsx' => 'xlsx',
|
|
||||||
'ods' => 'ods',
|
|
||||||
'csv' => 'csv'
|
|
||||||
],
|
|
||||||
'label' => false,
|
|
||||||
'placeholder' => 'Select a format',
|
|
||||||
'attr' => [ 'class' => 'custom-select' ]
|
|
||||||
])
|
|
||||||
->add('submit', SubmitType::class, [
|
|
||||||
'label' => 'Export',
|
|
||||||
'attr' => [ 'class' => 'btn btn-outline-secondary' ]
|
|
||||||
]);
|
|
||||||
|
|
||||||
$form = $builder->getForm();
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid())
|
if ($form->isSubmitted() && $form->isValid())
|
||||||
{
|
{
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
$format = $data['format'];
|
$format = $data['format'];
|
||||||
$filename = 'export_event_participations.' .$format;
|
$filename = 'export_event'. $event->getId() .'_participations.' .$format;
|
||||||
|
|
||||||
$spreadsheet = $this->createSpreadsheet($event);
|
$spreadsheet = $this->createExportSpreadsheet($event);
|
||||||
|
|
||||||
switch ($format) {
|
switch ($format) {
|
||||||
case 'ods':
|
case 'ods':
|
||||||
@ -499,10 +488,7 @@ class EventController extends Controller
|
|||||||
$writer = new Csv($spreadsheet);
|
$writer = new Csv($spreadsheet);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return $this->render('ChillEventBundle:Event:exportParticipations.html.twig', [
|
return [ 'form' => $form, 'response' => null ];
|
||||||
'event' => $event,
|
|
||||||
'form' => $form->createView(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new StreamedResponse();
|
$response = new StreamedResponse();
|
||||||
@ -515,13 +501,32 @@ class EventController extends Controller
|
|||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
});
|
});
|
||||||
|
|
||||||
return $response;
|
return [ 'form' => $form, 'response' => $response ];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Event:exportParticipations.html.twig', [
|
return [ 'form' => $form, 'response' => null ];
|
||||||
'event' => $event,
|
}
|
||||||
'form' => $form->createView(),
|
|
||||||
]);
|
/**
|
||||||
|
* @return \Symfony\Component\Form\FormInterface
|
||||||
|
*/
|
||||||
|
protected function createExportByFormatForm()
|
||||||
|
{
|
||||||
|
$builder = $this->createFormBuilder()
|
||||||
|
->add('format', ChoiceType::class, [
|
||||||
|
'choices' => [
|
||||||
|
'xlsx' => 'xlsx',
|
||||||
|
'ods' => 'ods',
|
||||||
|
'csv' => 'csv'
|
||||||
|
],
|
||||||
|
'label' => false,
|
||||||
|
'placeholder' => 'Select a format'
|
||||||
|
])
|
||||||
|
->add('submit', SubmitType::class, [
|
||||||
|
'label' => 'Export'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $builder->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -529,7 +534,7 @@ class EventController extends Controller
|
|||||||
* @return Spreadsheet
|
* @return Spreadsheet
|
||||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||||
*/
|
*/
|
||||||
protected function createSpreadsheet(Event $event)
|
protected function createExportSpreadsheet(Event $event)
|
||||||
{
|
{
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
@ -544,7 +549,7 @@ class EventController extends Controller
|
|||||||
'A4' => 'Type',
|
'A4' => 'Type',
|
||||||
'B4' => $event->getType()->getName()['fr'], // TODO
|
'B4' => $event->getType()->getName()['fr'], // TODO
|
||||||
'A5' => 'Circle',
|
'A5' => 'Circle',
|
||||||
'B5' => $event->getCircle()->getName()['fr'], // TODO
|
'B5' => $event->getCircle()->getName()['fr'], // TODO
|
||||||
'A6' => 'Moderator',
|
'A6' => 'Moderator',
|
||||||
'B6' => $event->getModerator(),
|
'B6' => $event->getModerator(),
|
||||||
];
|
];
|
||||||
|
@ -41,9 +41,3 @@ chill_event__list_by_person:
|
|||||||
defaults: { _controller: "ChillEventBundle:Event:listByPerson" }
|
defaults: { _controller: "ChillEventBundle:Event:listByPerson" }
|
||||||
methods: [ GET ]
|
methods: [ GET ]
|
||||||
|
|
||||||
chill_event__event_export_participations:
|
|
||||||
path: /{event_id}/export/participations
|
|
||||||
defaults: { _controller: "ChillEventBundle:Event:exportParticipations" }
|
|
||||||
requirements:
|
|
||||||
event_id: \d+
|
|
||||||
methods: [ GET, POST ]
|
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
{% extends 'ChillEventBundle::layout.html.twig' %}
|
|
||||||
|
|
||||||
{% block title 'Event : %label%'|trans({ '%label%' : event.name } ) %}
|
|
||||||
|
|
||||||
{% block event_content -%}
|
|
||||||
|
|
||||||
<table>
|
|
||||||
{% for participation in event.participations %}
|
|
||||||
<tr><td>
|
|
||||||
{{ participation.person.id }}
|
|
||||||
</td><td>
|
|
||||||
{{ participation.person.firstname }}
|
|
||||||
</td><td>
|
|
||||||
{{ participation.person.lastname }}
|
|
||||||
</td><td>
|
|
||||||
{{ participation.person.email }}
|
|
||||||
</td></tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table><br>
|
|
||||||
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.input-group {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
display: -ms-flexbox; display: flex;
|
|
||||||
-ms-flex-wrap: wrap; flex-wrap: wrap;
|
|
||||||
-ms-flex-align: stretch; align-items: stretch;
|
|
||||||
}
|
|
||||||
.custom-select {
|
|
||||||
padding: .375rem 1.75rem .375rem .75rem;
|
|
||||||
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e")
|
|
||||||
no-repeat right .75rem center/8px 10px;
|
|
||||||
border-radius: .25rem;
|
|
||||||
-webkit-appearance: none; -moz-appearance: none; appearance: none;
|
|
||||||
/*
|
|
||||||
display: inline-block;
|
|
||||||
width: 100%; height: calc(1.5em + .75rem + 2px);
|
|
||||||
font-size: 1rem; font-weight: 400; line-height: 1.5;
|
|
||||||
vertical-align: middle;
|
|
||||||
color: #495057; background-color: #fff;
|
|
||||||
border: 1px solid #ced4da;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
.input-group > .custom-select {
|
|
||||||
position: relative;
|
|
||||||
width: 1%;
|
|
||||||
margin-bottom: 0;
|
|
||||||
-ms-flex: 1 1 auto; flex: 1 1 auto;
|
|
||||||
}
|
|
||||||
.input-group > .custom-select:not(:last-child) {
|
|
||||||
border-top-right-radius: 0; border-bottom-right-radius: 0;
|
|
||||||
}
|
|
||||||
.input-group > .input-group-append > .btn {
|
|
||||||
border-top-left-radius: 0; border-bottom-left-radius: 0;
|
|
||||||
}
|
|
||||||
.input-group-append {
|
|
||||||
display: -ms-flexbox; display: flex; margin-left: -1px;
|
|
||||||
}
|
|
||||||
.input-group-append .btn {
|
|
||||||
position: relative; z-index: 2;
|
|
||||||
}
|
|
||||||
.btn {
|
|
||||||
display: inline-block;
|
|
||||||
text-align: center; vertical-align: middle;
|
|
||||||
padding: .375rem .75rem;
|
|
||||||
font-weight: 400; font-size: 1rem; line-height: 1.5;
|
|
||||||
color: #212529; background-color: transparent;
|
|
||||||
border: 1px solid transparent; border-radius: .25rem;
|
|
||||||
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
|
|
||||||
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
|
||||||
}
|
|
||||||
.btn-outline-secondary {
|
|
||||||
color: #6c757d; border-color: #6c757d;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
{{ form_start(form) }}
|
|
||||||
{{ form_errors(form) }}
|
|
||||||
<div class="input-group">
|
|
||||||
{{ form_widget(form.format) }}
|
|
||||||
<div class="input-group-append">
|
|
||||||
{{ form_widget(form.submit) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{ form_end(form) }}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -104,21 +104,92 @@
|
|||||||
|
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
{% if count > 0 %}
|
{% if count > 0 %}
|
||||||
<li><a href="{{ path('chill_event__event_export_participations', { 'event_id' : event.id } ) }}" class="sc-button btn-download">{{ 'Export participation list'|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>
|
<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 %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div style="margin-bottom: 1.5em;">
|
<style>
|
||||||
{{ form_start(form_add_participation_by_person) }}
|
|
||||||
{{ form_widget(form_add_participation_by_person.person_id, { 'attr' : { 'style' : 'width: 25em; display:inline-block; ' } } ) }}
|
/*
|
||||||
{{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }}
|
* REMARQUE ces styles règlent pour cette page le design des formulaires dropdown + submit
|
||||||
{{ form_rest(form_add_participation_by_person) }}
|
* ils surchargent notamment des styles plus généraux de Chill
|
||||||
{{ form_end(form_add_participation_by_person) }}
|
* -> devrait être ramené vers la feuille de style générale après vérifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
display: -ms-flexbox; display: flex;
|
||||||
|
-ms-flex-wrap: wrap; flex-wrap: wrap;
|
||||||
|
-ms-flex-align: stretch; align-items: stretch;
|
||||||
|
}
|
||||||
|
.custom-select {
|
||||||
|
padding: .375rem 1.75rem .375rem .75rem;
|
||||||
|
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e")
|
||||||
|
no-repeat right .75rem center/8px 10px;
|
||||||
|
border-radius: .25rem;
|
||||||
|
-webkit-appearance: none; -moz-appearance: none; appearance: none;
|
||||||
|
}
|
||||||
|
.input-group > .custom-select {
|
||||||
|
position: relative;
|
||||||
|
width: 1%;
|
||||||
|
margin-bottom: 0;
|
||||||
|
-ms-flex: 1 1 auto; flex: 1 1 auto;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.input-group > span.select2-container--default > span > span.select2-selection--single,
|
||||||
|
.input-group > .custom-select:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0;
|
||||||
|
height: 38px; padding: 8px;
|
||||||
|
}
|
||||||
|
/* override correction style */
|
||||||
|
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 38px; }
|
||||||
|
.select2-container--default .select2-selection--single .select2-selection__rendered { line-height: unset; }
|
||||||
|
|
||||||
|
.input-group > .input-group-append > .sc-button { border-top-left-radius: 0; border-bottom-left-radius: 0; }
|
||||||
|
.input-group-append { display: -ms-flexbox; display: flex; margin-left: -1px; }
|
||||||
|
.input-group-append .sc-button { position: relative; z-index: 2; }
|
||||||
|
.sc-button {
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center; vertical-align: middle;
|
||||||
|
padding: .375rem .75rem;
|
||||||
|
font-weight: 400; font-size: 1rem; line-height: 1.5;
|
||||||
|
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
|
||||||
|
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 10em;">
|
||||||
|
<div class="grid-8">
|
||||||
|
{{ form_start(form_add_participation_by_person) }}
|
||||||
|
<div class="input-group">
|
||||||
|
{{ form_widget(form_add_participation_by_person.person_id, { 'attr' : {
|
||||||
|
'class' : 'custom-select',
|
||||||
|
'style': 'min-width: 15em; max-width: 20em; display: inline-block;'
|
||||||
|
}} ) }}
|
||||||
|
<div class="input-group-append">
|
||||||
|
{{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'sc-button bt-create' } } ) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ form_rest(form_add_participation_by_person) }}
|
||||||
|
{{ form_end(form_add_participation_by_person) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid-4">
|
||||||
|
{{ form_start(form_export) }}
|
||||||
|
<div class="input-group">
|
||||||
|
{{ form_widget(form_export.format, { 'attr' : { 'class': 'custom-select' } }) }}
|
||||||
|
<div class="input-group-append">
|
||||||
|
{{ form_widget(form_export.submit, { 'attr' : { 'class': 'sc-button bt-save' } }) }}
|
||||||
|
</div>
|
||||||
|
<a class="bt-"></a>
|
||||||
|
</div>
|
||||||
|
{{ form_rest(form_export) }}
|
||||||
|
{{ form_end(form_export) }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="post_show">
|
<div class="post_show">
|
||||||
{{ chill_delegated_block('block_footer_show', { 'event': event }) }}
|
{{ chill_delegated_block('block_footer_show', { 'event': event }) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user