From b40a1595c16d0cc8bd75c17a3dc1078b2d89ca9d Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 18 Feb 2015 12:41:57 +0100 Subject: [PATCH] export raw string (no html conversion) and replace " by "" - refs #401 --- CustomFields/CustomFieldText.php | 14 ++++++++++---- .../views/CustomFieldsRendering/choice.csv.twig | 4 ++-- .../views/CustomFieldsRendering/text.csv.twig | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 Resources/views/CustomFieldsRendering/text.csv.twig diff --git a/CustomFields/CustomFieldText.php b/CustomFields/CustomFieldText.php index a8d58ac72..08e4ab58f 100644 --- a/CustomFields/CustomFieldText.php +++ b/CustomFields/CustomFieldText.php @@ -3,12 +3,13 @@ /* * Chill is a software for social workers * - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * , * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as + * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -92,8 +93,13 @@ class CustomFieldText implements CustomFieldInterface public function render($value, CustomField $customField, $documentType = 'html') { + $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig'; + if($documentType == 'csv') { + $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.csv.twig'; + } + return $this->templating - ->render('ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig', array('text' => $value)); + ->render($template, array('text' => $value)); } public function serialize($value, CustomField $customField) diff --git a/Resources/views/CustomFieldsRendering/choice.csv.twig b/Resources/views/CustomFieldsRendering/choice.csv.twig index 7c9c5ed1c..159ec3ce3 100644 --- a/Resources/views/CustomFieldsRendering/choice.csv.twig +++ b/Resources/views/CustomFieldsRendering/choice.csv.twig @@ -2,9 +2,9 @@ {%- for choice in choices -%} {% if choice['slug'] in selected %} {%- if choice['slug'] is not same as('_other') -%} - {{ choice['name']|localize_translatable_string }} + {{ choice['name']|localize_translatable_string|replace({'"':'""'})|raw }} {%- else -%} - {{ choice['name'] }} + {{ choice['name']|replace({'"':'""'})|raw }} {%- endif -%} {% endif %} {%- endfor -%} diff --git a/Resources/views/CustomFieldsRendering/text.csv.twig b/Resources/views/CustomFieldsRendering/text.csv.twig new file mode 100644 index 000000000..16dfb6f4d --- /dev/null +++ b/Resources/views/CustomFieldsRendering/text.csv.twig @@ -0,0 +1 @@ +{% if text is not empty %}{{ text|replace({'"':'""'})|raw }}{% else %}{{ 'None'|trans }}{% endif %} \ No newline at end of file