From 43ef9cc474c4d7078cc7cb12144e16269cd8ccdc Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 25 Nov 2019 17:46:21 +1300 Subject: [PATCH] Extract function to export header row --- CRM/Core/Report/Excel.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/CRM/Core/Report/Excel.php b/CRM/Core/Report/Excel.php index c194ddc537..18749398b3 100644 --- a/CRM/Core/Report/Excel.php +++ b/CRM/Core/Report/Excel.php @@ -42,18 +42,8 @@ class CRM_Core_Report_Excel { $seperator = $config->fieldSeparator; $add_character = "\015\012"; - $schema_insert = ''; - foreach ($header as $field) { - $schema_insert .= '"' . str_replace('"', '""', stripslashes($field)) . '"'; - $schema_insert .= $seperator; - } - // end while - if ($outputHeader) { - // need to add PMA_exportOutputHandler functionality out here, rather than - // doing it the moronic way of assembling a buffer - $out = trim(substr($schema_insert, 0, -1)) . $add_character; - echo $out; + self::outputHeaderRow($header); } $fields_cnt = count($header); @@ -101,6 +91,26 @@ class CRM_Core_Report_Excel { } } + /** + * Output the header row for a csv file. + * + * @param array $header + * Array of field names. + */ + public static function outputHeaderRow($header) { + $schema_insert = ''; + $separator = Civi::settings()->get('fieldSeparator'); + foreach ($header as $field) { + $schema_insert .= '"' . str_replace('"', '""', stripslashes($field)) . '"'; + $schema_insert .= $separator; + } + // end while + // need to add PMA_exportOutputHandler functionality out here, rather than + // doing it the moronic way of assembling a buffer + // We append a hex newline at the end. + echo trim(substr($schema_insert, 0, -1)) . "\015\012"; + } + /** * @param string $fileName * @param $header -- 2.25.1