public function exportData($data, $header = false, $export_mapping = array())
{
if (!is_array($data) || count($data) == 0) {
return '';
}
$export = '';
$eol = "\n";
$head = array_keys(current($data));
if ($header) {
foreach ($head as $key) {
if (!empty($key)) {
if (isset($export_mapping[$key])) {
$key = $export_mapping[$key];
}
$export .= '"' . str_replace('"', '\\"', $key) . '"';
}
$export .= ',';
}
$export = substr($export, 0, -1) . $eol;
}
foreach ($data as $row) {
foreach ($head as $key) {
$cell = $row[$key];
if (!empty($cell) || $cell === 0) {
$export .= '"' . str_replace('"', '\\"', $cell) . '"';
}
$export .= ',';
}
$export = substr($export, 0, -1) . $eol;
}
return $export;
}