Skip to content
Permalink
Browse files

FIX GridFieldExportButton should honour can method.

  • Loading branch information...
wilr committed Feb 3, 2015
1 parent 5219cb0 commit abd1e6b856ffcd4487d80424cb7aa350b33dd462
@@ -132,26 +132,28 @@ public function generateExportFileData($gridField) {
}
foreach($items->limit(null) as $item) {
$columnData = array();
foreach($csvColumns as $columnSource => $columnHeader) {
if(!is_string($columnHeader) && is_callable($columnHeader)) {
if($item->hasMethod($columnSource)) {
$relObj = $item->{$columnSource}();
if($item->hasMethod('canView') && $item->canView()) {
$columnData = array();
foreach($csvColumns as $columnSource => $columnHeader) {
if(!is_string($columnHeader) && is_callable($columnHeader)) {
if($item->hasMethod($columnSource)) {
$relObj = $item->{$columnSource}();
} else {
$relObj = $item->relObject($columnSource);
}
$value = $columnHeader($relObj);
} else {
$relObj = $item->relObject($columnSource);
$value = $gridField->getDataFieldValue($item, $columnSource);
}
$value = $columnHeader($relObj);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
$value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '\"', $value) . '"';
}
$value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '\"', $value) . '"';
$fileData .= implode($separator, $columnData);
$fileData .= "\n";
}
$fileData .= implode($separator, $columnData);
$fileData .= "\n";
$item->destroy();
}
@@ -1,4 +1,9 @@
<?php
/**
* @package framework
* @subpackage tests
*/
class GridFieldExportButtonTest extends SapphireTest {
protected $list;
@@ -10,7 +15,8 @@ class GridFieldExportButtonTest extends SapphireTest {
protected static $fixture_file = 'GridFieldExportButtonTest.yml';
protected $extraDataObjects = array(
'GridFieldExportButtonTest_Team'
'GridFieldExportButtonTest_Team',
'GridFieldExportButtonTest_NoView'
);
public function setUp() {
@@ -22,6 +28,21 @@ public function setUp() {
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
}
public function testCanView() {
$list = new DataList('GridFieldExportButtonTest_NoView');
$button = new GridFieldExportButton();
$button->setExportColumns(array('Name' => 'My Name'));
$config = GridFieldConfig::create()->addComponent(new GridFieldExportButton());
$gridField = new GridField('testfield', 'testfield', $list, $config);
$this->assertEquals(
"\"My Name\"\n",
$button->generateExportFileData($gridField)
);
}
public function testGenerateFileDataBasicFields() {
$button = new GridFieldExportButton();
$button->setExportColumns(array('Name' => 'My Name'));
@@ -94,8 +115,12 @@ public function testArrayListInput() {
$button->generateExportFileData($this->gridField)
);
}
}
/**
* @package framework
* @subpackage tests
*/
class GridFieldExportButtonTest_Team extends DataObject implements TestOnly {
private static $db = array(
@@ -109,3 +134,20 @@ public function canView($member = null) {
}
/**
* @package framework
* @subpackage tests
*/
class GridFieldExportButtonTest_NoView extends DataObject implements TestOnly {
private static $db = array(
'Name' => 'Varchar',
'City' => 'Varchar'
);
public function canView($member = null) {
return false;
}
}
@@ -6,3 +6,6 @@ GridFieldExportButtonTest_Team:
Name: Test2
City: City2

GridFieldExportButtonTest_NoView:
item1:
Name: Foo

0 comments on commit abd1e6b

Please sign in to comment.
You can’t perform that action at this time.