Source for file Abstract.php
Documentation is available at Abstract.php
const XMLNS_XSI =
'http://www.w3.org/2001/XMLSchema-instance';
const XMLNS =
'http://omeka.org/schemas/omeka-xml/v2';
* This class' contextual record(s).
* @var array|Omeka_Record
* The context of this DOMDocument. Determines how buildNode() builds the
* elements. Valid contexts include: item, file.
* The final document object.
* The node built and set in child::_buildNode()
* Abstract method. child::_buildNode() should set self::$_node.
* @param Omeka_Record|array$record
* @param string $context The context of this DOM document.
$this->_doc =
new DOMDocument('1.0', 'UTF-8');
$this->_doc->formatOutput =
true;
* Get the document object.
* Set an element as root.
* @param DOMElement $rootElement
* @return DOMElement The root element, including required attributes.
$rootElement->setAttribute('xmlns', self::XMLNS);
$rootElement->setAttribute('xmlns:xsi', self::XMLNS_XSI);
$rootElement->setAttribute('xsi:schemaLocation', self::XMLNS_SCHEMALOCATION);
$rootElement->setAttribute('uri', $this->_buildUrl());
$rootElement->setAttribute('accessDate', date('c'));
* @param string $name The name of the element.
* @param null|stringThe value of the element.
* @param null|intThe id attribute of the element.
* @param null|DOMElementThe parent element.
protected function _createElement($name, $value =
null, $id =
null, $parentElement =
null)
$element =
$this->_doc->createElement($name);
// Append the value, if given.
$textNode =
$this->_doc->createTextNode($value);
$element->appendChild($textNode);
// Set the @id attribute, if given.
$element->setAttribute("{
$name}Id", $id);
// Append to the parent element, if given.
$parentElement->appendChild($element);
* Set the pagination node for container elements
* @param DOMElement The parent container element.
// Return if the pagination data is not registered.
if (!Zend_Registry::isRegistered('pagination')) {
$pagination =
Zend_Registry::get('pagination');
$paginationElement =
$this->_createElement('pagination', null, null, $parentElement);
$this->_createElement('pageNumber', $pagination['page'], null, $paginationElement);
$this->_createElement('perPage', $pagination['per_page'], null, $paginationElement);
$this->_createElement('totalResults', $pagination['total_results'], null, $paginationElement);
* Get all element sets, elements, and element texts associated with the
* @param Omeka_Record $record The record from which to extract metadata.
* @param bool $getItemType Whether to get the item type metadata.
* @return stdClass A list of element sets or an item type.
$elementSets =
new stdClass;
$itemType =
new stdClass;
// Get all element texts associated with the provided record.
$elementTexts =
$record->getElementTextRecords();
foreach ($elementTexts as $elementText) {
// Get associated element and element set records.
$element =
get_db()->getTable('Element')->find($elementText->element_id);
$elementSet =
get_db()->getTable('ElementSet')->find($element->element_set_id);
// Differenciate between the element sets and the "Item Type
// Metadata" pseudo element set.
$itemType->elements[$element->id]->name =
$element->name;
$itemType->elements[$element->id]->description =
$element->description;
$itemType->elements[$element->id]->elementTexts[$elementText->id]->text =
$elementText->text;
$elementSets->elementSets[$elementSet->id]->name =
$elementSet->name;
$elementSets->elementSets[$elementSet->id]->description =
$elementSet->description;
$elementSets->elementSets[$elementSet->id]->elements[$element->id]->name =
$element->name;
$elementSets->elementSets[$elementSet->id]->elements[$element->id]->description =
$element->description;
$elementSets->elementSets[$elementSet->id]->elements[$element->id]->elementTexts[$elementText->id]->text =
$elementText->text;
// Return the item type metadata.
$itemType->id =
$record->Type->id;
$itemType->name =
$record->Type->name;
$itemType->description =
$record->Type->description;
// Return the element sets metadata.
* Build an elementSetContainer element in a record (item or file) context.
* @param Omeka_Record $record The record from which to build element sets.
* @param DOMElement $parentElement The element set container will append to
// Return if there are no element sets.
if (!count($elementSets->elementSets)) {
$elementSetContainerElement =
$this->_createElement('elementSetContainer');
foreach ($elementSets->elementSets as $elementSetId =>
$elementSet) {
$elementSetElement =
$this->_createElement('elementSet', null, $elementSetId);
$nameElement =
$this->_createElement('name', $elementSet->name, null, $elementSetElement);
$descriptionElement =
$this->_createElement('description', $elementSet->description, null, $elementSetElement);
foreach ($elementSet->elements as $elementId =>
$element) {
$nameElement =
$this->_createElement('name', $element->name, null, $elementElement);
$descriptionElement =
$this->_createElement('description', $element->description, null, $elementElement);
$elementTextContainerElement =
$this->_createElement('elementTextContainer');
foreach ($element->elementTexts as $elementTextId =>
$elementText) {
$elementTextElement =
$this->_createElement('elementText', null, $elementTextId);
$textElement =
$this->_createElement('text', $elementText->text, null, $elementTextElement);
$elementTextContainerElement->appendChild($elementTextElement);
$elementElement->appendChild($elementTextContainerElement);
$elementContainerElement->appendChild($elementElement);
$elementSetElement->appendChild($elementContainerElement);
$elementSetContainerElement->appendChild($elementSetElement);
$parentElement->appendChild($elementSetContainerElement);
* Build an itemType element in an item context.
* @param Item $item The item from which to build the item type.
* @param DOMElement $parentElement The item type will append to this element.
// Return if the item does not have an item type.
$itemTypeElement =
$this->_createElement('itemType', null, $itemType->id);
$nameElement =
$this->_createElement('name', $itemType->name, null, $itemTypeElement);
$descriptionElement =
$this->_createElement('description', $itemType->description, null, $itemTypeElement);
// Do not append elements if no element texts exist for this item type.
if (count($itemType->elements)) {
foreach ($itemType->elements as $elementId =>
$element) {
$nameElement =
$this->_createElement('name', $element->name, null, $elementElement);
$descriptionElement =
$this->_createElement('description', $element->description, null, $elementElement);
$elementTextContainerElement =
$this->_createElement('elementTextContainer');
foreach ($element->elementTexts as $elementTextId =>
$elementText) {
$elementTextElement =
$this->_createElement('elementText', null, $elementTextId);
$textElement =
$this->_createElement('text', $elementText->text, null, $elementTextElement);
$elementTextContainerElement->appendChild($elementTextElement);
$elementElement->appendChild($elementTextContainerElement);
$elementContainerElement->appendChild($elementElement);
$itemTypeElement->appendChild($elementContainerElement);
$parentElement->appendChild($itemTypeElement);
* Build a fileContainer element in an item context.
* @param Item $item The item from which to build the file container.
* @param DOMElement $parentElement The file container will append to this
// Return if the item has no files.
if (!count($item->Files)) {
foreach ($item->Files as $file) {
$fileElement =
$this->_doc->importNode($fileOmekaXml->_node, true);
$fileContainerElement->appendChild($fileElement);
$parentElement->appendChild($fileContainerElement);
* Build a collection element in an item context.
* @param Item $item The item from which to build the collection.
* @param DOMElement $parentElement The collection will append to this
// Return if the item has no collection.
if (!$item->Collection) {
$collectionElement =
$this->_createElement('collection', null, $item->Collection->id);
$nameElement =
$this->_createElement('name', $item->Collection->name, null, $collectionElement);
$descriptionElement =
$this->_createElement('description', $item->Collection->description, null, $collectionElement);
$parentElement->appendChild($collectionElement);
* Build a tagContainer element in an item context.
* @param Item $item The item from which to build the tag container.
* @param DOMElement $parentElement The tag container will append to this
// Return if the item has no tags.
if (!count($item->Tags)) {
foreach ($item->Tags as $tag) {
$tagContainerElement->appendChild($tagElement);
$parentElement->appendChild($tagContainerElement);
$uri =
Zend_Uri::factory(abs_uri());
$tagUri =
'tag:' .
$uri->getHost() .
',' .
date('Y-m-d') .
':' .
$uri->getPath();
$uri =
Zend_Uri::factory(abs_uri());
Documentation generated on Thu, 15 Oct 2009 15:35:08 -0400 by phpDocumentor 1.4.2