I'm working on a Silverstripe project which has a Batch > Item relationship.
A Batch can have up to 50,000 Items.
This is how the relationship is set-out:
class Item extends DataObject {
private static $has_one = array(
'Batch' => 'Batch'
);
class Batch extends DataObject {
private static $has_many = array(
'Items' => 'Item'
);
class BatchAdmin extends ModelAdmin {
private static $managed_models = array(
'Batch',
'Item'
);
This natively gives the CMS user the ability to download all Items as a CSV from the CMS.
I'm trying to work out two things:
How do I make sure that large downloads don't fail due to lack of memory/ script time etc?
How do I add an "Export to CSV" button to each Batch which downloads only the Items in that batch as a CSV?
To add an Export to CSV button to Batch
which exports the related Items
we add a GridFieldExportButton
to the Batch CMSFields:
class Batch extends DataObject {
private static $has_many = array(
'Items' => 'Item'
);
public function getCMSFields() {
$itemsConfig = GridFieldConfig_RelationEditor::create();
$itemsConfig->addComponent(new GridFieldExportButton());
$itemsField = new GridField(
'Items',
'Items',
$this->Items(),
$itemsConfig
);
$fields = new FieldList(
$itemsField
);
return $fields;
}
}