Merge pull request #4164 from wilr/fixssreportarraylist

FIX: Modifications to GridFieldExportButton to allow ArrayList use in SS_Report
This commit is contained in:
Damian Mooyman 2015-05-11 19:17:40 +12:00
commit 3907688f7d

View File

@ -132,7 +132,7 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
} }
foreach($items->limit(null) as $item) { foreach($items->limit(null) as $item) {
if($item->hasMethod('canView') && $item->canView()) { if(!$item->hasMethod('canView') || $item->canView()) {
$columnData = array(); $columnData = array();
foreach($csvColumns as $columnSource => $columnHeader) { foreach($csvColumns as $columnSource => $columnHeader) {
@ -146,17 +146,24 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
$value = $columnHeader($relObj); $value = $columnHeader($relObj);
} else { } else {
$value = $gridField->getDataFieldValue($item, $columnSource); $value = $gridField->getDataFieldValue($item, $columnSource);
if(!$value) {
$value = $gridField->getDataFieldValue($item, $columnHeader);
}
} }
$value = str_replace(array("\r", "\n"), "\n", $value); $value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '""', $value) . '"'; $columnData[] = '"' . str_replace('"', '""', $value) . '"';
} }
$fileData .= implode($separator, $columnData); $fileData .= implode($separator, $columnData);
$fileData .= "\n"; $fileData .= "\n";
} }
if($item->hasMethod('destroy')) {
$item->destroy(); $item->destroy();
} }
}
return $fileData; return $fileData;
} }