diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index be0fc6fb6..deca4f24e 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -538,7 +538,7 @@ class ImportExportController extends ControllerBehavior protected function checkUseListExportMode() { - if (!$listDefinition = $this->getConfig('export[useList]')) { + if (!$useList = $this->getConfig('export[useList]')) { return false; } @@ -546,6 +546,13 @@ class ImportExportController extends ControllerBehavior throw new ApplicationException(Lang::get('backend::lang.import_export.behavior_missing_uselist_error')); } + if (is_array($useList)) { + $listDefinition = array_get($useList, 'definition'); + } + else { + $listDefinition = $useList; + } + $this->exportFromList($listDefinition); } @@ -594,12 +601,20 @@ class ImportExportController extends ControllerBehavior /* * Add records */ + $getter = $this->getConfig('export[useList][raw]', false) + ? 'getColumnValueRaw' + : 'getColumnValue'; + $model = $widget->prepareModel(); $results = $model->get(); foreach ($results as $result) { $record = []; foreach ($columns as $column) { - $record[] = $widget->getColumnValue($result, $column); + $value = $widget->$getter($result, $column); + if (is_array($value)) { + $value = implode('|', $value); + } + $record[] = $value; } $csv->insertOne($record); } diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 1be7f0ac3..fece182ea 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -761,9 +761,10 @@ class Lists extends WidgetBase } /** - * Looks up the column value + * Returns a raw column value + * @return string */ - public function getColumnValue($record, $column) + public function getColumnValueRaw($record, $column) { $columnName = $column->columnName; @@ -810,6 +811,17 @@ class Lists extends WidgetBase } } + return $value; + } + + /** + * Returns a column value, with filters applied + * @return string + */ + public function getColumnValue($record, $column) + { + $value = $this->getColumnValueRaw($record, $column); + if (method_exists($this, 'eval'. studly_case($column->type) .'TypeValue')) { $value = $this->{'eval'. studly_case($column->type) .'TypeValue'}($record, $column, $value); }