Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Last active December 14, 2015 08:19
Show Gist options
  • Save charlycoste/5057116 to your computer and use it in GitHub Desktop.
Save charlycoste/5057116 to your computer and use it in GitHub Desktop.
eZ Publish export tools
<?php
$dom = new DOMDocument();
$dom->formatOutput = true;
$node = eZContentObjectTreeNode::fetch(1);
function export($eznode, $parent, $dom) {
$element = $dom->createElement('node');
$attributes = array('node_id', 'remote_id', 'contentobject_id', 'contentobject_version', 'is_hidden', 'name', 'is_main');
foreach ($attributes as $attr) {
$element->setAttribute($attr, $eznode->attribute($attr));
}
$parent->appendChild($element);
foreach ($eznode->children() as $child) {
export($child, $element, $dom);
}
}
export($node, $dom, $dom);
echo $dom->saveXML();
<?php
$dom = new DOMDocument();
$dom->formatOutput = true;
$element = $dom->createElement('object');
$dom->appendChild($element);
$object = eZContentObject::fetch(1);
$attributes = array('id','section_id','owner_id','contentclass_id','name','published',
'modified','current_version','status','remote_id','default_language',
'language_mask','initial_language_code','current_language','class_identifier');
foreach ($attributes as $attribute) {
$element->setAttribute($attribute, $object->attribute($attribute));
}
foreach ($object->dataMap() as $attribute) {
$elem = $dom->createElement('attribute', $attribute->toString());
$elem->setAttribute('data_type_string', $attribute->attribute('data_type_string'));
$element->appendChild($elem);
}
echo $dom->saveXML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment