mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
improve phpspreadsheet participations list export
This commit is contained in:
@@ -197,31 +197,37 @@ class EventController extends Controller
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
public function showAction($event_id)
|
||||
public function showAction(Event $event, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = $em->getRepository('ChillEventBundle:Event')->find($event_id);
|
||||
|
||||
if (!$entity) {
|
||||
if (!$event) {
|
||||
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");
|
||||
|
||||
$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(
|
||||
'event' => $entity,
|
||||
'form_add_participation_by_person' => $addParticipationByPersonForm->createView()
|
||||
'event' => $event,
|
||||
'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 Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return array
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
public function exportParticipationsAction(Event $event, Request $request)
|
||||
protected function exportParticipationsList(Event $event, Request $request)
|
||||
{
|
||||
$builder = $this->createFormBuilder()
|
||||
->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 = $this->createExportByFormatForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$data = $form->getData();
|
||||
$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) {
|
||||
case 'ods':
|
||||
@@ -499,10 +488,7 @@ class EventController extends Controller
|
||||
$writer = new Csv($spreadsheet);
|
||||
break;
|
||||
default:
|
||||
return $this->render('ChillEventBundle:Event:exportParticipations.html.twig', [
|
||||
'event' => $event,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
return [ 'form' => $form, 'response' => null ];
|
||||
}
|
||||
|
||||
$response = new StreamedResponse();
|
||||
@@ -515,13 +501,32 @@ class EventController extends Controller
|
||||
$writer->save('php://output');
|
||||
});
|
||||
|
||||
return $response;
|
||||
return [ 'form' => $form, 'response' => $response ];
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:exportParticipations.html.twig', [
|
||||
'event' => $event,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
return [ 'form' => $form, 'response' => null ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
*/
|
||||
protected function createSpreadsheet(Event $event)
|
||||
protected function createExportSpreadsheet(Event $event)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
@@ -544,7 +549,7 @@ class EventController extends Controller
|
||||
'A4' => 'Type',
|
||||
'B4' => $event->getType()->getName()['fr'], // TODO
|
||||
'A5' => 'Circle',
|
||||
'B5' => $event->getCircle()->getName()['fr'], // TODO
|
||||
'B5' => $event->getCircle()->getName()['fr'], // TODO
|
||||
'A6' => 'Moderator',
|
||||
'B6' => $event->getModerator(),
|
||||
];
|
||||
|
Reference in New Issue
Block a user