diff --git a/src/Mods/Element/Specific/Location/HoldingSimple.php b/src/Mods/Element/Specific/Location/HoldingSimple.php index 4eae5f3..a21bb2e 100644 --- a/src/Mods/Element/Specific/Location/HoldingSimple.php +++ b/src/Mods/Element/Specific/Location/HoldingSimple.php @@ -40,22 +40,25 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of the element. + * Get the the array of the 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; } } diff --git a/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php b/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php index 8838fd9..e717dc1 100644 --- a/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php +++ b/src/Mods/Element/Specific/Location/HoldingSimple/CopyInformation.php @@ -55,12 +55,7 @@ public function __construct(\SimpleXMLElement $xml) */ 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); } /** @@ -75,52 +70,42 @@ public function getForm(string $query = ''): ?Form */ 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 element. + * Get the the array of the 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 element. + * Get the array of the 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; } /** @@ -147,42 +132,48 @@ public function getNotes(string $query = ''): array } /** - * Get the value of the element. + * Get the array of the 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 element. + * Get the the array of the 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; } } diff --git a/tests/Mods/ModsReaderTest.php b/tests/Mods/ModsReaderTest.php index b34bed2..db909db 100644 --- a/tests/Mods/ModsReaderTest.php +++ b/tests/Mods/ModsReaderTest.php @@ -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()