public function exportCollection(BaseCollection $collection, array $intersectKeys = null)
{
$schema = $collection->getSchema();
$keys = $schema->getColumnNames();
if ($intersectKeys) {
$keys = array_intersect_key($keys, array_flip($intersectKeys));
}
$php54 = version_compare(phpversion(), '5.5.0') < 0;
if ($php54) {
fputcsv($this->fd, $keys, $this->delimiter, $this->enclosure);
} else {
fputcsv($this->fd, $keys, $this->delimiter, $this->enclosure, $this->escapeChar);
}
foreach ($collection as $record) {
$array = $record->toArray();
$fields = [];
foreach ($keys as $key) {
$fields[] = $array[$key];
}
if ($php54) {
fputcsv($this->fd, $fields, $this->delimiter, $this->enclosure);
} else {
fputcsv($this->fd, $fields, $this->delimiter, $this->enclosure, $this->escapeChar);
}
}
return true;
}