mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT Optionally getting all columns in ModelAdmin->getResultColumns() - not just the columns ticked in the UI (useful for CSV export)
ENHANCEMENT Defaulting to show all columns in ModelAdmin CSV export, ignoring user selection of result table columns (users can always limit CSV columns by manually deleting them e.g. in Excel) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@66596 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3aa7ad3212
commit
dde4a07058
@ -439,6 +439,8 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
$model = singleton($this->modelClass);
|
||||
|
||||
$source = $model->summaryFields();
|
||||
|
||||
// select all fields by default
|
||||
$value = array();
|
||||
if($source) foreach ($source as $fieldName => $label){
|
||||
$value[] = $fieldName;
|
||||
@ -535,18 +537,28 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
return $context->getQuery($searchCriteria);
|
||||
}
|
||||
|
||||
function getResultColumns($searchCriteria) {
|
||||
/**
|
||||
* Returns all columns used for tabular search results display.
|
||||
* Defaults to all fields specified in {@link DataObject->summaryFields()}.
|
||||
*
|
||||
* @param array $searchCriteria Limit fields by populating the 'ResultsAssembly' key
|
||||
* @param boolean $selectedOnly Limit by 'ResultsAssempty
|
||||
*/
|
||||
function getResultColumns($searchCriteria, $selectedOnly = true) {
|
||||
$model = singleton($this->modelClass);
|
||||
$summaryFields = $model->summaryFields();
|
||||
|
||||
if($selectedOnly) {
|
||||
$resultAssembly = $searchCriteria['ResultAssembly'];
|
||||
if(!is_array($resultAssembly)) {
|
||||
$explodedAssembly = split(' *, *', $resultAssembly);
|
||||
$resultAssembly = array();
|
||||
foreach($explodedAssembly as $item) $resultAssembly[$item] = true;
|
||||
}
|
||||
|
||||
return array_intersect_key($summaryFields, $resultAssembly);
|
||||
} else {
|
||||
return $summaryFields;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -569,6 +581,10 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
// @todo Remove records that can't be viewed by the current user
|
||||
$tf->setPermissions(array_merge(array('view','export'), TableListField::permissions_for_object($this->modelClass)));
|
||||
|
||||
// csv export settings (select all columns regardless of user checkbox settings in 'ResultsAssembly')
|
||||
$exportFields = $this->getResultColumns($searchCriteria, false);
|
||||
$tf->setFieldListCsv($exportFields);
|
||||
|
||||
$url = '<a href=\"' . $this->Link() . '/$ID/edit\">$value</a>';
|
||||
$tf->setFieldFormatting(array_combine(array_keys($summaryFields), array_fill(0,count($summaryFields), $url)));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user