public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
{
// get settings
$splitCharacter = Authentication::getUser()->getSetting('csv_split_character');
$lineEnding = Authentication::getUser()->getSetting('csv_line_ending');
// reformat
if ($lineEnding == '\\n') {
$lineEnding = "\n";
}
if ($lineEnding == '\\r\\n') {
$lineEnding = "\r\n";
}
// convert into CSV
$csv = \SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
// set headers for download
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
throw new RedirectException('Return the csv data', new Response($csv, Response::HTTP_OK, ['Content-type' => 'application/csv; charset=' . $charset, 'Content-Disposition' => 'attachment; filename="' . $filename . '"', 'Content-Length' => mb_strlen($csv), 'Pragma' => 'no-cache']));
}