public function exportCollection(BaseCollection $collection)
{
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('export');
$dom->appendChild($root);
// $this->appendRecord($dom, $root, $record, NULL, true);
$schema = $collection->getSchema();
$relations = $schema->getRelations();
// find foreign many-to-many schema
foreach ($relations as $rel) {
if ($rel['type'] === Relationship::MANY_TO_MANY) {
$junctionRel = $relations[$rel['relation_junction']];
$junctionSchema = $junctionRel->newForeignSchema();
$foreignRel = $junctionSchema->getRelation($rel['relation_foreign']);
$foreignCollection = $foreignRel->newForeignCollection();
$foreignSchema = $foreignRel->newForeignSchema();
$collectionRoot = $dom->createElement('collection');
$collectionRoot->setAttribute('schema', get_class($foreignSchema));
$collectionRoot->setAttribute('class', get_class($foreignCollection));
$root->appendChild($collectionRoot);
foreach ($foreignCollection as $record) {
$this->appendRecord($dom, $collectionRoot, $record, $foreignSchema, true);
}
}
}
$collectionRoot = $dom->createElement('collection');
$collectionRoot->setAttribute('schema', get_class($schema));
$collectionRoot->setAttribute('class', get_class($collection));
$root->appendChild($collectionRoot);
foreach ($collection as $record) {
$this->appendRecord($dom, $collectionRoot, $record, $schema, true);
}
$dom->formatOutput = true;
return $dom;
}