mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Remove export function from List behavior
This commit is contained in:
parent
d0742653d1
commit
46bfa78cef
@ -1,3 +1,6 @@
|
||||
* **Build 28x** (2015-07-xx)
|
||||
- The `export` action has been moved from ListController behavior to Import / Export behavior (see Backend > Importing & Exporting docs).
|
||||
|
||||
* **Build 279** (2015-07-14)
|
||||
- Plugins can now be frozen to prevent them from receiving updates via the plugin management area.
|
||||
- A plugin version can now be flagged as "Important" by prepending `!!!` to the version history comment.
|
||||
|
@ -247,15 +247,6 @@ class ListController extends ControllerBehavior
|
||||
$this->makeLists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Export Controller action.
|
||||
* @return void
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
return $this->listExportCsv();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the widget collection.
|
||||
* @param string $definition Optional list definition.
|
||||
@ -317,73 +308,6 @@ class ListController extends ControllerBehavior
|
||||
return array_get($this->listWidgets, $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list results as a CSV export.
|
||||
*/
|
||||
public function listExportCsv($options = [], $definition = null)
|
||||
{
|
||||
/*
|
||||
* Locate widget
|
||||
*/
|
||||
if (!count($this->listWidgets)) {
|
||||
$this->makeLists();
|
||||
}
|
||||
|
||||
if (!$definition || !isset($this->listDefinitions[$definition])) {
|
||||
$definition = $this->primaryDefinition;
|
||||
}
|
||||
|
||||
$widget = $this->listWidgets[$definition];
|
||||
|
||||
/*
|
||||
* Parse options
|
||||
*/
|
||||
$defaultOptions = [
|
||||
'filename' => 'export.csv',
|
||||
'delimiter' => ',',
|
||||
'enclosure' => '"'
|
||||
];
|
||||
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
extract($options);
|
||||
|
||||
/*
|
||||
* Prepare CSV
|
||||
*/
|
||||
$csv = Writer::createFromFileObject(new SplTempFileObject);
|
||||
$csv->setDelimiter($options['delimiter']);
|
||||
$csv->setEnclosure($options['enclosure']);
|
||||
|
||||
/*
|
||||
* Add headers
|
||||
*/
|
||||
$headers = [];
|
||||
$columns = $widget->getVisibleColumns();
|
||||
foreach ($columns as $column) {
|
||||
$headers[] = Lang::get($column->label);
|
||||
}
|
||||
$csv->insertOne($headers);
|
||||
|
||||
/*
|
||||
* Add records
|
||||
*/
|
||||
$model = $widget->prepareModel();
|
||||
$results = $model->get();
|
||||
foreach ($results as $result) {
|
||||
$record = [];
|
||||
foreach ($columns as $column) {
|
||||
$record[] = $widget->getColumnValue($result, $column);
|
||||
}
|
||||
$csv->insertOne($record);
|
||||
}
|
||||
|
||||
/*
|
||||
* Output
|
||||
*/
|
||||
$csv->output($filename);
|
||||
exit;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user