mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
APICHANGE: we move the filedata generation part of export() function to a new function generateExportFileData, so that, a child class could reuse the function when overload export function
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@70150 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ebed486bcd
commit
d3a5bcbb7f
@ -894,6 +894,8 @@ JS
|
||||
/**
|
||||
* Exports a given set of comma-separated IDs (from a previous search-query, stored in a HiddenField).
|
||||
* Uses {$csv_columns} if present, and falls back to {$result_columns}.
|
||||
* We move the most filedata generation code to the function {@link generateExportFileData()} so that a child class
|
||||
* could reuse the filedata generation code while overwrite export function.
|
||||
*
|
||||
* @todo Make relation-syntax available (at the moment you'll have to use custom sql)
|
||||
*/
|
||||
@ -901,6 +903,19 @@ JS
|
||||
$now = Date("d-m-Y-H-i");
|
||||
$fileName = "export-$now.csv";
|
||||
|
||||
if($fileData = $this->generateExportFileData($numColumns, $numRows)){
|
||||
return HTTPRequest::send_file($fileData, $fileName);
|
||||
}else{
|
||||
user_error("No records found", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the function is to generate string that will be used as
|
||||
* the content of exported file
|
||||
*/
|
||||
|
||||
function generateExportFileData(&$numColumns, &$numRows){
|
||||
$separator = $this->csvSeparator;
|
||||
$csvColumns = ($this->fieldListCsv) ? $this->fieldListCsv : $this->fieldList;
|
||||
$fileData = "";
|
||||
@ -955,9 +970,12 @@ JS
|
||||
$fileData .= implode($separator, $columnData);
|
||||
$fileData .= "\n";
|
||||
}
|
||||
return HTTPRequest::send_file($fileData, $fileName);
|
||||
|
||||
$numColumns = count($columnData);
|
||||
$numRows = $fieldItems->count();
|
||||
return $fileData;
|
||||
} else {
|
||||
user_error("No records found", E_USER_ERROR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user