diff --git a/src/OaiPmh/Metadata/AbstractMetadata.php b/src/OaiPmh/Metadata/AbstractMetadata.php index c1b1bdcdfe2e4f6359ceb21b8c39070d0dcd62d2..f6f4784f6d63074dac65fb76458d0c58673593a7 100644 --- a/src/OaiPmh/Metadata/AbstractMetadata.php +++ b/src/OaiPmh/Metadata/AbstractMetadata.php @@ -86,6 +86,7 @@ abstract class AbstractMetadata extends AbstractXmlGenerator implements Metadata public function appendHeader(DOMElement $parent, ItemRepresentation $item) { + $headerData = []; $headerData['identifier'] = OaiIdentifier::itemToOaiId($item->id()); $datestamp = $item->modified(); @@ -137,6 +138,12 @@ abstract class AbstractMetadata extends AbstractXmlGenerator implements Metadata } } + /** + * Appends a metadata element, a child element with the required format, and + * further children for each of the properties present in the item. + * + * {@inheritDoc} + */ abstract public function appendMetadata(DOMElement $parent, ItemRepresentation $item); abstract public function getMetadataPrefix(); diff --git a/src/OaiPmh/Metadata/CdwaLite.php b/src/OaiPmh/Metadata/CdwaLite.php index 6cacd848dfad3851a4f3da1f141ce6a5b10bf2b6..8b74c7c749a43e9f95ff3867541a3f83c1af68f4 100644 --- a/src/OaiPmh/Metadata/CdwaLite.php +++ b/src/OaiPmh/Metadata/CdwaLite.php @@ -13,7 +13,7 @@ use OaiPmhRepository\OaiPmh\Plugin\OaiIdentifier; use Omeka\Api\Representation\ItemRepresentation; /** - * Class implmenting metadata output CDWA Lite. + * Class implementing metadata output CDWA Lite. * * @link http://www.getty.edu/research/conducting_research/standards/cdwa/cdwalite.html */ @@ -31,12 +31,7 @@ class CdwaLite extends AbstractMetadata /** * Appends CDWALite metadata. * - * Appends a metadata element, an child element with the required format, - * and further children for each of the Dublin Core fields present in the - * item. - * * {@inheritDoc} - * @see \OaiPmhRepository\OaiPmh\Metadata\AbstractMetadata::appendMetadata() */ public function appendMetadata(DOMElement $metadataElement, ItemRepresentation $item) { @@ -65,7 +60,7 @@ class CdwaLite extends AbstractMetadata /* Type => objectWorkTypeWrap->objectWorkType * Required. Fill with 'Unknown' if omitted. */ - $types = $item->value('dcterms:type', ['all' => true]) ?: []; + $types = $item->value('dcterms:type', ['all' => true, 'default' => []]); $objectWorkTypeWrap = $this->appendNewElement($descriptive, 'cdwalite:objectWorkTypeWrap'); if (empty($types)) { $types[] = 'Unknown'; @@ -78,7 +73,7 @@ class CdwaLite extends AbstractMetadata /* Title => titleWrap->titleSet->title * Required. Fill with 'Unknown' if omitted. */ - $titles = $item->value('dcterms:title', ['all' => true]) ?: []; + $titles = $item->value('dcterms:title', ['all' => true, 'default' => []]); $titleWrap = $this->appendNewElement($descriptive, 'cdwalite:titleWrap'); foreach ($titles as $title) { @@ -90,7 +85,7 @@ class CdwaLite extends AbstractMetadata * Required. Fill with 'Unknown' if omitted. * Non-repeatable, implode for inclusion of many creators. */ - $creators = $item->value('dcterms:creator', ['all' => true]) ?: []; + $creators = $item->value('dcterms:creator', ['all' => true, 'default' => []]); $creatorTexts = []; foreach ($creators as $creator) { @@ -134,7 +129,7 @@ class CdwaLite extends AbstractMetadata * Required. Fill with 'Unknown' if omitted. */ $indexingDatesWrap = $this->appendNewElement($descriptive, 'cdwalite:indexingDatesWrap'); - $dates = $item->value('dcterms:date', ['all' => true]) ?: []; + $dates = $item->value('dcterms:date', ['all' => true, 'default' => []]); foreach ($dates as $date) { $indexingDatesSet = $this->appendNewElement($indexingDatesWrap, 'cdwalite:indexingDatesSet'); $this->appendNewElement($indexingDatesSet, 'cdwalite:earliestDate', (string) $date); @@ -151,7 +146,7 @@ class CdwaLite extends AbstractMetadata /* Subject => classWrap->classification * Not required. */ - $subjects = $item->value('dcterms:subject', ['all' => true]) ?: []; + $subjects = $item->value('dcterms:subject', ['all' => true, 'default' => []]); $classWrap = $this->appendNewElement($descriptive, 'cdwalite:classWrap'); foreach ($subjects as $subject) { $this->appendNewElement($classWrap, 'cdwalite:classification', (string) $subject); @@ -160,7 +155,7 @@ class CdwaLite extends AbstractMetadata /* Description => descriptiveNoteWrap->descriptiveNoteSet->descriptiveNote * Not required. */ - $descriptions = $item->value('dcterms:description', ['all' => true]) ?: []; + $descriptions = $item->value('dcterms:description', ['all' => true, 'default' => []]); if (!empty($descriptions)) { $descriptiveNoteWrap = $this->appendNewElement($descriptive, 'cdwalite:descriptiveNoteWrap'); foreach ($descriptions as $description) { @@ -179,7 +174,7 @@ class CdwaLite extends AbstractMetadata /* Rights => rightsWork * Not required. */ - $rights = $item->value('dcterms:rights', ['all' => true]) ?: []; + $rights = $item->value('dcterms:rights', ['all' => true, 'default' => []]); foreach ($rights as $right) { $this->appendNewElement($administrative, 'cdwalite:rightsWork', (string) $right); } diff --git a/src/OaiPmh/Metadata/MetadataInterface.php b/src/OaiPmh/Metadata/MetadataInterface.php index f0ccf732f3a6de9ca1a8418b9717a0a67d4b7b84..4ee84e1daafa1c5f83f28a1e7df01393a4202ce2 100644 --- a/src/OaiPmh/Metadata/MetadataInterface.php +++ b/src/OaiPmh/Metadata/MetadataInterface.php @@ -51,6 +51,7 @@ interface MetadataInterface * @uses appendMetadata * * @param DOMElement $parent + * @param ItemRepresentation $item */ public function appendRecord(DOMElement $parent, ItemRepresentation $item); @@ -61,6 +62,7 @@ interface MetadataInterface * appends in to the document. * * @param DOMElement $parent + * @param ItemRepresentation $item */ public function appendHeader(DOMElement $parent, ItemRepresentation $item); @@ -68,6 +70,7 @@ interface MetadataInterface * Appends the metadata for one Omeka item to the XML document. * * @param DOMElement $parent + * @param ItemRepresentation $item */ public function appendMetadata(DOMElement $parent, ItemRepresentation $item); } diff --git a/src/OaiPmh/Metadata/Mets.php b/src/OaiPmh/Metadata/Mets.php index 420425379cff4b48614df3a645861d49958e7b04..0db526e5dc0ccc59a7e0c1f453d0fe6f24f119a2 100755 --- a/src/OaiPmh/Metadata/Mets.php +++ b/src/OaiPmh/Metadata/Mets.php @@ -12,9 +12,9 @@ use DOMElement; use Omeka\Api\Representation\ItemRepresentation; /** - * Class implmenting MODS metadata output format. + * Class implementing METS metadata output format. * - * @link http://www.loc.gov/standards/mods/ + * @link https://www.loc.gov/standards/mets/ */ class Mets extends AbstractMetadata { @@ -31,14 +31,9 @@ class Mets extends AbstractMetadata const DC_NAMESPACE_URI = 'http://purl.org/dc/elements/1.1/'; /** - * Appends MODS metadata. - * - * Appends a metadata element, an child element with the required format, - * and further children for each of the Dublin Core fields present in the - * item. + * Appends METS metadata. * * {@inheritDoc} - * @see \OaiPmhRepository\OaiPmh\Metadata\AbstractMetadata::appendMetadata() */ public function appendMetadata(DOMElement $metadataElement, ItemRepresentation $item) { @@ -71,7 +66,7 @@ class Mets extends AbstractMetadata ]; foreach ($dcElementNames as $elementName) { - $values = $item->value("dcterms:$elementName", ['all' => true]) ?: []; + $values = $item->value("dcterms:$elementName", ['all' => true, 'default' => []]); foreach ($values as $value) { $this->appendNewElement($dcXml, "dc:$elementName", (string) $value); } diff --git a/src/OaiPmh/Metadata/Mods.php b/src/OaiPmh/Metadata/Mods.php index 5376c43c07a967e79b1da2f74b13f381866e1ab2..4279e360ec867db8e3226c863395d22d77ceea7b 100644 --- a/src/OaiPmh/Metadata/Mods.php +++ b/src/OaiPmh/Metadata/Mods.php @@ -12,9 +12,9 @@ use DOMElement; use Omeka\Api\Representation\ItemRepresentation; /** - * Class implmenting MODS metadata output format. + * Class implementing MODS metadata output format. * - * @link http://www.loc.gov/standards/mods/ + * @link https://www.loc.gov/standards/mods/ */ class Mods extends AbstractMetadata { @@ -30,14 +30,9 @@ class Mods extends AbstractMetadata /** * Appends MODS metadata. * - * Appends a metadata element, an child element with the required format, - * and further children for each of the Dublin Core fields present in the - * item. - * * @link http://www.loc.gov/standards/mods/dcsimple-mods.html * * {@inheritDoc} - * @see \OaiPmhRepository\OaiPmh\Metadata\AbstractMetadata::appendMetadata() */ public function appendMetadata(DOMElement $metadataElement, ItemRepresentation $item) { @@ -53,13 +48,13 @@ class Mods extends AbstractMetadata $mods->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA); - $titles = $item->value('dcterms:title', ['all' => true]) ?: []; + $titles = $item->value('dcterms:title', ['all' => true, 'default' => []]); foreach ($titles as $title) { $titleInfo = $this->appendNewElement($mods, 'titleInfo'); $this->appendNewElement($titleInfo, 'title', (string) $title); } - $creators = $item->value('dcterms:creator', ['all' => true]) ?: []; + $creators = $item->value('dcterms:creator', ['all' => true, 'default' => []]); foreach ($creators as $creator) { $name = $this->appendNewElement($mods, 'name'); $this->appendNewElement($name, 'namePart', (string) $creator); @@ -68,7 +63,7 @@ class Mods extends AbstractMetadata $roleTerm->setAttribute('type', 'text'); } - $contributors = $item->value('dcterms:contributor', ['all' => true]) ?: []; + $contributors = $item->value('dcterms:contributor', ['all' => true, 'default' => []]); foreach ($contributors as $contributor) { $name = $this->appendNewElement($mods, 'name'); $this->appendNewElement($name, 'namePart', (string) $contributor); @@ -77,41 +72,41 @@ class Mods extends AbstractMetadata $roleTerm->setAttribute('type', 'text'); } - $subjects = $item->value('dcterms:contributor', ['all' => true]) ?: []; + $subjects = $item->value('dcterms:contributor', ['all' => true, 'default' => []]); foreach ($subjects as $subject) { $subjectTag = $this->appendNewElement($mods, 'subject'); $this->appendNewElement($subjectTag, 'topic', (string) $subject); } - $descriptions = $item->value('dcterms:description', ['all' => true]) ?: []; + $descriptions = $item->value('dcterms:description', ['all' => true, 'default' => []]); foreach ($descriptions as $description) { $this->appendNewElement($mods, 'note', (string) $description); } - $formats = $item->value('dcterms:format', ['all' => true]) ?: []; + $formats = $item->value('dcterms:format', ['all' => true, 'default' => []]); foreach ($formats as $format) { $physicalDescription = $this->appendNewElement($mods, 'physicalDescription'); $this->appendNewElement($physicalDescription, 'form', (string) $format); } - $languages = $item->value('dcterms:language', ['all' => true]) ?: []; + $languages = $item->value('dcterms:language', ['all' => true, 'default' => []]); foreach ($languages as $language) { $languageElement = $this->appendNewElement($mods, 'language'); $languageTerm = $this->appendNewElement($languageElement, 'languageTerm', (string) $language); $languageTerm->setAttribute('type', 'text'); } - $rights = $item->value('dcterms:rights', ['all' => true]) ?: []; + $rights = $item->value('dcterms:rights', ['all' => true, 'default' => []]); foreach ($rights as $right) { $this->appendNewElement($mods, 'accessCondition', (string) $right); } - $types = $item->value('dcterms:type', ['all' => true]) ?: []; + $types = $item->value('dcterms:type', ['all' => true, 'default' => []]); foreach ($types as $type) { $this->appendNewElement($mods, 'genre', (string) $type); } - $identifiers = $item->value('dcterms:identifier', ['all' => true]) ?: []; + $identifiers = $item->value('dcterms:identifier', ['all' => true, 'default' => []]); foreach ($identifiers as $identifier) { $text = (string) $identifier; $idElement = $this->appendNewElement($mods, 'identifier', $text); @@ -122,12 +117,12 @@ class Mods extends AbstractMetadata } } - $sources = $item->value('dcterms:source', ['all' => true]) ?: []; + $sources = $item->value('dcterms:source', ['all' => true, 'default' => []]); foreach ($sources as $source) { $this->_addRelatedItem($mods, (string) $source, true); } - $relations = $item->value('dcterms:relation', ['all' => true]) ?: []; + $relations = $item->value('dcterms:relation', ['all' => true, 'default' => []]); foreach ($relations as $relation) { $this->_addRelatedItem($mods, (string) $relation); } @@ -150,8 +145,8 @@ class Mods extends AbstractMetadata $url = $this->appendNewElement($location, 'url', $url); $url->setAttribute('usage', 'primary display'); - $publishers = $item->value('dcterms:publisher', ['all' => true]) ?: []; - $dates = $item->value('dcterms:date', ['all' => true]) ?: []; + $publishers = $item->value('dcterms:publisher', ['all' => true, 'default' => []]); + $dates = $item->value('dcterms:date', ['all' => true, 'default' => []]); // Empty originInfo sections are illegal if (count($publishers) + count($dates) > 0) { @@ -177,8 +172,8 @@ class Mods extends AbstractMetadata * location subelement if so. Otherwise, a titleInfo is used. * * @param DomElement $mods - * @param string $text - * @param bool $original + * @param string $text + * @param bool $original */ private function _addRelatedItem($mods, $text, $original = false) { @@ -199,7 +194,6 @@ class Mods extends AbstractMetadata * Returns whether the given test is (looks like) a URL. * * @param string $text - * * @return bool */ private function _isUrl($text) diff --git a/src/OaiPmh/Metadata/OaiDc.php b/src/OaiPmh/Metadata/OaiDc.php index 0943d44c0babbe7fdaf80dbf4b2c3dce34e410ed..1a8299842bdaeb28c55fbcf70a255b00de90b1f6 100644 --- a/src/OaiPmh/Metadata/OaiDc.php +++ b/src/OaiPmh/Metadata/OaiDc.php @@ -12,7 +12,7 @@ use DOMElement; use Omeka\Api\Representation\ItemRepresentation; /** - * Class implmenting metadata output for the required oai_dc metadata format. + * Class implementing metadata output for the required oai_dc metadata format. * oai_dc is output of the 15 unqualified Dublin Core fields. */ class OaiDc extends AbstractMetadata @@ -32,12 +32,7 @@ class OaiDc extends AbstractMetadata /** * Appends Dublin Core metadata. * - * Appends a metadata element, an child element with the required format, - * and further children for each of the Dublin Core fields present in the - * item. - * * {@inheritDoc} - * @see \OaiPmhRepository\OaiPmh\Metadata\AbstractMetadata::appendMetadata() */ public function appendMetadata(DOMElement $metadataElement, ItemRepresentation $item) { @@ -54,7 +49,7 @@ class OaiDc extends AbstractMetadata $oai_dc->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA); - /* Each of the 16 unqualified Dublin Core elements, in the order + /* Each of the 15 unqualified Dublin Core elements, in the order * specified by the oai_dc XML schema */ $dcElementNames = [ @@ -68,7 +63,7 @@ class OaiDc extends AbstractMetadata * compliant per-node declarations. */ foreach ($dcElementNames as $elementName) { - $values = $item->value("dcterms:$elementName", ['all' => true]) ?: []; + $values = $item->value("dcterms:$elementName", ['all' => true, 'default' => []]); foreach ($values as $value) { $this->appendNewElement($oai_dc, "dc:$elementName", (string) $value); }