From a7b807514b72c6906387e46a31a7d9331130651f Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 18 Feb 2015 15:47:27 +0100 Subject: [PATCH] First version of export person - 'rfs #400 --- Controller/PersonController.php | 22 +++++++++- Resources/config/routing.yml | 11 ++++- Resources/views/Person/export.csv.twig | 60 ++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 Resources/views/Person/export.csv.twig diff --git a/Controller/PersonController.php b/Controller/PersonController.php index d7bfdbbd4..b06d28c68 100644 --- a/Controller/PersonController.php +++ b/Controller/PersonController.php @@ -118,7 +118,7 @@ class PersonController extends Controller return $this->redirect($url); } } - + public function searchAction() { $q = $this->getRequest()->query->getAlnum('q', ''); @@ -176,6 +176,26 @@ class PersonController extends Controller 'pattern' => $q )); } + + /** + * Return a csv file with all the persons + * + * @return A csv file with all the persons + */ + public function exportAction() + { + $em = $this->getDoctrine()->getManager(); + $persons = $em->getRepository('ChillPersonBundle:Person')->findAll(); + + $response = $this->render('ChillPersonBundle:Person:export.csv.twig', + array( + 'persons' => $persons, + 'cf_group' => $this->getCFGroup())); + $response->headers->set('Content-Type', 'text/csv'); + $response->headers->set('Content-Disposition', 'attachment; filename="export.csv"'); + + return $response; + } public function newAction() { diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 2b1f45f15..6ac81cb2c 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -78,4 +78,13 @@ chill_person_admin: admin: order: 100 label: menu.person.admin.index - helper: menu.person.admin.helper \ No newline at end of file + helper: menu.person.admin.helper + +chill_person_export: + pattern: /{_locale}/person/export/ + defaults: { _controller: ChillPersonBundle:Person:export } + options: + menus: + export: + order: 200 + label: Export persons \ No newline at end of file diff --git a/Resources/views/Person/export.csv.twig b/Resources/views/Person/export.csv.twig new file mode 100644 index 000000000..f7c9cd3e7 --- /dev/null +++ b/Resources/views/Person/export.csv.twig @@ -0,0 +1,60 @@ +"{{ 'Person id'|trans }}",{# +#}"{{ 'First name'|trans }}",{# +#}"{{ 'Last name'|trans }}",{# +#}"{{ 'Gender'|trans }}",{# +#}"{{ 'Date of birth'|trans }}",{# +#}"{{ 'Place of birth'|trans }}",{# +#}"{{ 'Nationality'|trans }}",{# +#}"{{ 'Spoken languages'|trans }}",{# +#}"{{ 'Email'|trans }}",{# +#}"{{ 'Phonenumber'|trans }}",{# +#}{% if cf_group %}{# + #}{% for customField in cf_group.customFields %}{# + #}"{{ chill_custom_field_label(customField) }}"{% if not loop.last %},{% endif %}{# + #}{% endfor %}{# +#}{% endif %}{# +#} + +{% for person in persons %}{# + #}{{ person.id }},{# + #}"{{ person.firstName }}",{# + #}"{{ person.lastName }}",{# + #}"{{ person.genre }}",{# + #}"{{ person.dateOfBirth|localizeddate('short', 'none') }}",{# + #}"{# countryOfBirth + #}{% if person.countryOfBirth is not null %}{# + #}{{ person.countryOfBirth.name|localize_translatable_string }}{# + #}{% else %}{# + #}{{ 'Unknown country of birth'|trans }}{# + #}{% endif %}{# + #}",{# + #}"{# nationality + #}{% if person.nationality is not null %}{# + #}{{ person.nationality.name|localize_translatable_string }}{# + #}{% else %}{# + #}{{ 'Without nationality'|trans }}{# + #}{% endif %}{# + #}",{# + #}"{# spokenLanguages + #}{% if person.spokenLanguages|length == 0 %}{# + #}{{ 'Unknown spoken languages'|trans }}{# + #}{% else %}{# + #}{% for lang in person.spokenLanguages %}{# + #}{{ lang.name|localize_translatable_string }}{% if not loop.last %},{% endif %}{# + #}{% endfor %}{# + #}{% endif %}{# + #}",{# + #}"{{ person.email|csv_cell }}",{# + #}"{{ person.phonenumber|csv_cell }}",{# + #}{% if cf_group %}{# + #}{% for customField in cf_group.customFields %}{# + #}{% if customField.type == 'title' %}{# + #}""{# + #}{% else %}{# + #}"{{ chill_custom_field_widget(report.cFData , customField, 'csv') }}"{# + #}{% endif %}{# + #}{% if not loop.last %},{% endif %}{# + #}{% endfor %}{# + #}{% endif %} + +{% endfor %} \ No newline at end of file