Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust CopyInformation to match MODS documentation #12

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Mods/Element/Specific/Location/HoldingSimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,25 @@ public function __construct(\SimpleXMLElement $xml)
}

/**
* Get the value of the <copyInformation> element.
* Get the the array of the <copyInformation> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#copyinformation
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?CopyInformation
* @return CopyInformation[]
*/
public function getCopyInformation(string $query = ''): ?CopyInformation
public function getCopyInformation(string $query = ''): array
{
$copyInformation = [];
$xpath = './mods:copyInformation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new CopyInformation($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$copyInformation[] = new CopyInformation($value);
}
}
return null;
return $copyInformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@
*/
public function getForm(string $query = ''): ?Form
{
$xpath = './mods:form' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}
return null;
return $this->getLanguageElement('./mods:form' . $query);

Check failure on line 58 in src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Slub\Mods\Element\Specific\Location\HoldingSimple\CopyInformation::getForm() should return Slub\Mods\Element\Specific\PhysicalDescription\Form|null but returns Slub\Mods\Element\Common\LanguageElement|null.
}

/**
Expand All @@ -75,52 +70,42 @@
*/
public function getSubLocations(string $query = ''): array
{
$subLocations = [];
$xpath = './mods:subLocation' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$subLocations[] = new LanguageElement($value);
}
}
return $subLocations;
return $this->getLanguageElements('./mods:subLocation' . $query);
}

/**
* Get the value of the <shelfLocator> element.
* Get the the array of the <shelfLocator> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#copyshelflocator
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return LanguageElement
* @return LanguageElement[]
*/
public function getShelfLocator(string $query = ''): LanguageElement
public function getShelfLocators(string $query = ''): array
{
$xpath = './mods:shelfLocator' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}
return null;
return $this->getLanguageElements('./mods:shelfLocator' . $query);
}

/**
* Get the value of the <electronicLocator> element.
* Get the array of the <electronicLocator> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#electroniclocator
*
* @access public
*
* @return string
* @return string[]
*/
public function getElectronicLocator(): string
public function getElectronicLocators(): array
{
$electronicLocators = [];
$element = new Element($this->xml, './mods:electronicLocator');
if ($element->exists()) {
return $element->getValues()[0];
foreach ($element->getValues() as $value) {
$electronicLocators[] = $value;
}
}
return '';
return $electronicLocators;
}

/**
Expand All @@ -147,42 +132,48 @@
}

/**
* Get the value of the <enumerationAndChronology> element.
* Get the array of the <enumerationAndChronology> element.
* @see https://www.loc.gov/standards/mods/userguide/location.html#enumerationandchronology
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?EnumerationAndChronology
* @return EnumerationAndChronology[]
*/
public function getEnumerationAndChronology(string $query = ''): ?EnumerationAndChronology
public function getEnumerationAndChronologies(string $query = ''): array
{
$enumerationAndChronologies = [];
$xpath = './mods:enumerationAndChronology' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new EnumerationAndChronology($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$enumerationAndChronologies[] = new EnumerationAndChronology($value);
}
}
return null;
return $enumerationAndChronologies;
}

/**
* Get the value of the <itemIdentifier> element.
* Get the the array of the <itemIdentifier> elements.
* @see https://www.loc.gov/standards/mods/userguide/location.html#itemidentifier
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return ?ItemIdentifier
* @return ItemIdentifier[]
*/
public function getItemIdentifier(string $query = ''): ?ItemIdentifier
public function getItemIdentifiers(string $query = ''): array
{
$itemIdentifiers = [];
$xpath = './mods:itemIdentifier' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new EnumerationAndChronology($element->getValues()[0]);
foreach ($element->getValues() as $value) {
$itemIdentifiers[] = new ItemIdentifier($value);
}
}
return null;
return $itemIdentifiers;
}
}
13 changes: 7 additions & 6 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,13 @@ public function testGetLocationsForBookDocument()
self::assertNotNull($holdingSimple);

$copyInformation = $holdingSimple->getCopyInformation();
self::assertNotNull($copyInformation);
self::assertNotEmpty($copyInformation->getSubLocations());
self::assertEquals('Reading room', $copyInformation->getSubLocations()[0]->getValue());
self::assertEquals('QH511.A1J68', $copyInformation->getShelfLocator()->getValue());
self::assertEquals('1', $copyInformation->getEnumerationAndChronology()->getUnitType());
self::assertEquals('v.1-v.2 1999-2002', $copyInformation->getEnumerationAndChronology()->getValue());
self::assertNotEmpty($copyInformation);
self::assertNotEmpty($copyInformation[0]->getSubLocations());
self::assertEquals('Reading room', $copyInformation[0]->getSubLocations()[0]->getValue());
self::assertNotEmpty($copyInformation[0]->getShelfLocators());
self::assertEquals('QH511.A1J68', $copyInformation[0]->getShelfLocators()[0]->getValue());
self::assertEquals('1', $copyInformation[0]->getEnumerationAndChronologies()[0]->getUnitType());
self::assertEquals('v.1-v.2 1999-2002', $copyInformation[0]->getEnumerationAndChronologies()[0]->getValue());
}

public function testGetLocationsByQueryForBookDocument()
Expand Down
Loading