diff --git a/src/Mods/Element/Common/BaseElement.php b/src/Mods/Element/Common/BaseElement.php index 54e2378..b51f428 100644 --- a/src/Mods/Element/Common/BaseElement.php +++ b/src/Mods/Element/Common/BaseElement.php @@ -12,6 +12,8 @@ namespace Slub\Mods\Element\Common; +use Slub\Mods\Element\Xml\Element; + /** * MODS metadata element class for the 'php-mods-reader' library. * @@ -41,7 +43,7 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the text value of element + * Get the text value of element. * * @access public * @@ -53,7 +55,13 @@ public function getValue(): string } /** - * Get the string value of attribute + * Get the string value of attribute. + * + * @access protected + * + * @param string $attribute name + * + * @return string */ protected function getStringAttribute($attribute): string { @@ -66,4 +74,64 @@ protected function getStringAttribute($attribute): string } return ''; } -} \ No newline at end of file + + /** + * Get the the array of the matching elements. + * + * @access protected + * + * @param string $xpath The XPath for metadata search + * + * @return DateElement[] + */ + protected function getDateElements(string $xpath): array + { + $elements = []; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $elements[] = new DateElement($value); + } + } + return $elements; + } + + /** + * Get the matching element or null if there is not match. + * + * @access protected + * + * @param string $xpath The XPath for metadata search + * + * @return ?LanguageElement + */ + protected function getLanguageElement(string $xpath): ?LanguageElement + { + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new LanguageElement($element->getValues()[0]); + } + return null; + } + + /** + * Get the array of the matching elements. + * + * @access protected + * + * @param string $xpath The XPath for metadata search + * + * @return LanguageElement[] + */ + protected function getLanguageElements(string $xpath): array + { + $elements = []; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $elements[] = new LanguageElement($value); + } + } + return $elements; + } +} diff --git a/src/Mods/Element/OriginInfo.php b/src/Mods/Element/OriginInfo.php index d4b285a..e9698e6 100644 --- a/src/Mods/Element/OriginInfo.php +++ b/src/Mods/Element/OriginInfo.php @@ -24,9 +24,12 @@ use Slub\Mods\Element\Specific\OriginInfo\Edition; use Slub\Mods\Element\Specific\OriginInfo\Frequency; use Slub\Mods\Element\Specific\OriginInfo\Issuance; +use Slub\Mods\Element\Specific\OriginInfo\Place; +use Slub\Mods\Element\Xml\Element; /** * OriginInfo MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html * * @access public */ @@ -34,54 +37,6 @@ class OriginInfo extends BaseElement { use LanguageAttribute, IdAttribute, AltRepGroupAttribute, DisplayLabelAttribute; - /** - * @access private - * @var array - */ - private array $places; - - /** - * @access private - * @var Agent - */ - private Agent $agent; - - /** - * @access private - * @var DateElement - */ - private DateElement $dateIssued; - - /** - * @access private - * @var DateElement - */ - private DateElement $dateCreated; - - /** - * @access private - * @var DateElement - */ - private DateElement $dateCaptured; - - /** - * @access private - * @var DateElement - */ - private DateElement $dateValid; - - /** - * @access private - * @var DateElement - */ - private DateElement $dateModified; - - /** - * @access private - * @var DateElement - */ - private DateElement $copyrightDate; - /** * @access private * @var DateOther @@ -124,24 +79,11 @@ class OriginInfo extends BaseElement public function __construct(\SimpleXMLElement $xml) { parent::__construct($xml); - - $this->places = []; - $this->agent = new Agent($xml); - $this->dateIssued = new DateElement($xml); - $this->dateCreated = new DateElement($xml); - $this->dateCaptured = new DateElement($xml); - $this->dateValid = new DateElement($xml); - $this->dateModified = new DateElement($xml); - $this->copyrightDate = new DateElement($xml); - $this->dateOther = new DateOther($xml); - $this->displayDate = new DisplayDate($xml); - $this->edition = new Edition($xml); - $this->issuance = new Issuance($xml); - $this->frequency = new Frequency($xml); } /** - * Get the value of eventType + * Get the value of the 'eventType' attribute. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#eventType * * @access public * @@ -153,7 +95,8 @@ public function getEventType(): string } /** - * Get the value of eventTypeURI + * Get the value of the 'eventTypeURI' attribute. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#eventTypeURI * * @access public * @@ -165,158 +108,253 @@ public function getEventTypeURI(): string } /** - * Get the value of places + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#place * * @access public * - * @return array + * @param string $query The XPath query for metadata search + * + * @return Place[] */ - public function getPlaces(): array + public function getPlaces(string $query = ''): array { - return $this->places; + $places = []; + $xpath = './mods:place' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $places[] = new Place($value); + } + } + return $places; } /** - * Get the value of agent + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#agent * * @access public * - * @return Agent + * @param string $query The XPath query for metadata search + * + * @return Agent[] */ - public function getAgent(): Agent + public function getAgents(string $query = ''): array { - return $this->agent; + $agents = []; + $xpath = './mods:agent' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $agents[] = new Agent($value); + } + } + return $agents; } /** - * Get the value of dateIssued + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#dateissued * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDateIssued(): DateElement + public function getIssuedDates(string $query = ''): array { - return $this->dateIssued; + return $this->getDateElements('./mods:dateIssued' . $query); } /** - * Get the value of dateCreated + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#datecreated * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDateCreated(): DateElement + public function getCreatedDates(string $query = ''): array { - return $this->dateCreated; + return $this->getDateElements('./mods:dateCreated' . $query); } /** - * Get the value of dateCaptured + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#datecaptured * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDateCaptured(): DateElement + public function getCapturedDates(string $query = ''): array { - return $this->dateCaptured; + return $this->getDateElements('./mods:dateCaptured' . $query); } /** - * Get the value of dateValid + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#datevalid * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDateValid(): DateElement + public function getValidDates(string $query = ''): array { - return $this->dateValid; + return $this->getDateElements('./mods:dateValid' . $query); } /** - * Get the value of dateModified + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#datemodified * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDateModified(): DateElement + public function getModifiedDates(string $query = ''): array { - return $this->dateModified; + return $this->getDateElements('./mods:dateModified' . $query); } /** - * Get the value of copyrightDate + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#copyrightdate * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getCopyrightDate(): DateElement + public function getCopyrightDates(string $query = ''): array { - return $this->copyrightDate; + return $this->getDateElements('./mods:copyrightDate' . $query); } /** - * Get the value of dateOther + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#dateother * * @access public * - * @return DateOther + * @param string $query The XPath query for metadata search + * + * @return DateOther[] */ - public function getDateOther(): DateOther + public function getOtherDates(string $query = ''): array { - return $this->dateOther; + $otherDates = []; + $xpath = './mods:dateOther' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $otherDates[] = new DateOther($value); + } + } + return $otherDates; } /** - * Get the value of displayDate + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#displayDate * * @access public * - * @return DisplayDate + * @param string $query The XPath query for metadata search + * + * @return DisplayDate[] */ - public function getDisplayDate(): DisplayDate + public function getDisplayDates(string $query = ''): array { - return $this->displayDate; + $displayDates = []; + $xpath = './mods:displayDate' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $displayDates[] = new DisplayDate($value); + } + } + return $displayDates; } /** - * Get the value of edition + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#edition * * @access public * - * @return Edition + * @param string $query The XPath query for metadata search + * + * @return Edition[] */ - public function getEdition(): Edition + public function getEditions(string $query = ''): array { - return $this->edition; + $editions = []; + $xpath = './mods:edition' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $editions[] = new Edition($value); + } + } + return $editions; } /** - * Get the value of issuance + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#issuance * * @access public * - * @return Issuance + * @param string $query The XPath query for metadata search + * + * @return Issuance[] */ - public function getIssuance(): Issuance + public function getIssuances(string $query = ''): array { - return $this->issuance; + $issuances = []; + $xpath = './mods:issuance' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $issuances[] = new Issuance($value); + } + } + return $issuances; } /** - * Get the value of frequency + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#frequency * * @access public * - * @return Frequency + * @param string $query The XPath query for metadata search + * + * @return Frequency[] */ - public function getFrequency(): Frequency + public function getFrequencies(string $query = ''): array { - return $this->frequency; + $frequencies = []; + $xpath = './mods:frequency' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $frequencies[] = new Frequency($value); + } + } + return $frequencies; } } diff --git a/src/Mods/Element/Specific/OriginInfo/Place.php b/src/Mods/Element/Specific/OriginInfo/Place.php index bfb0f3f..7767724 100644 --- a/src/Mods/Element/Specific/OriginInfo/Place.php +++ b/src/Mods/Element/Specific/OriginInfo/Place.php @@ -15,10 +15,12 @@ use Slub\Mods\Attribute\Common\Miscellaneous\SuppliedAttribute; use Slub\Mods\Element\Common\BaseElement; use Slub\Mods\Element\Specific\OriginInfo\Place\Cartographics; -use Slub\Mods\Element\Specific\OriginInfo\Place\PlaceIdentifier; +use Slub\Mods\Element\Specific\OriginInfo\Place\PlaceTerm; +use Slub\Mods\Element\Xml\Element; /** * Place MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#place * * @access public */ @@ -26,24 +28,6 @@ class Place extends BaseElement { use SuppliedAttribute; - /** - * @access private - * @var array - */ - private array $placeTerms; - - /** - * @access private - * @var PlaceIdentifier - */ - private PlaceIdentifier $placeIdentifier; - - /** - * @access private - * @var Cartographics - */ - private Cartographics $cartographics; - /** * This extracts the essential MODS metadata from XML * @@ -59,38 +43,71 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of placeTerms + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#placeterm * * @access public * - * @return array + * @param string $query The XPath query for metadata search + * + * @return PlaceTerm[] */ - public function getPlaceTerms(): array + public function getPlaceTerms(string $query = ''): array { - return $this->placeTerms; + $placeTerms = []; + $xpath = './mods:placeTerm' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $placeTerms[] = new PlaceTerm($value); + } + } + return $placeTerms; } /** - * Get the value of placeIdentifier + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#placeidentifier * * @access public * - * @return PlaceIdentifier + * @param string $query The XPath query for metadata search + * + * @return BaseElement[] */ - public function getPlaceIdentifier(): PlaceIdentifier + public function getPlaceIdentifiers(string $query = ''): array { - return $this->placeIdentifier; + $placeIdentifiers = []; + $xpath = './mods:placeIdentifier' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $placeIdentifiers[] = new BaseElement($value); + } + } + return $placeIdentifiers; } /** - * Get the value of cartographics + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#oiplacecartographics * * @access public * - * @return Cartographics + * @param string $query The XPath query for metadata search + * + * @return Cartographics[] */ - public function getCartographics(): Cartographics + public function getCartographics(string $query = ''): array { - return $this->cartographics; + $cartographics = []; + $xpath = './mods:cartographics' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $cartographics[] = new Cartographics($value); + } + } + return $cartographics; } } diff --git a/src/Mods/Element/Specific/OriginInfo/Place/Cartographics.php b/src/Mods/Element/Specific/OriginInfo/Place/Cartographics.php index 29484fc..c24ee37 100644 --- a/src/Mods/Element/Specific/OriginInfo/Place/Cartographics.php +++ b/src/Mods/Element/Specific/OriginInfo/Place/Cartographics.php @@ -18,6 +18,7 @@ /** * Cartographics MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#oiplacecartographics * * @access public */ @@ -25,30 +26,6 @@ class Cartographics extends BaseElement { use AuthorityAttribute; - /** - * @access private - * @var array - */ - private array $coordinates; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $projection; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $scale; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $cartographicExtension; - /** * This extracts the essential MODS metadata from XML * @@ -61,57 +38,63 @@ class Cartographics extends BaseElement public function __construct(\SimpleXMLElement $xml) { parent::__construct($xml); - - $this->projection = new LanguageElement($xml); - $this->scale = new LanguageElement($xml); - $this->cartographicExtension = new LanguageElement($xml); } /** - * Get the value of coordinates + * Get the value of the element. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#projection * * @access public * - * @return array + * @return ?LanguageElement */ - public function getCoordinates(): array + public function getProjection(string $query = ''): ?LanguageElement { - return $this->coordinates; + return $this->getLanguageElement('./mods:projection' . $query); } /** - * Get the value of projection + * Get the value of the element. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#scale * * @access public * - * @return LanguageElement + * @param string $query The XPath query for metadata search + * + * @return ?LanguageElement */ - public function getProjection(): LanguageElement + public function getScale(string $query = ''): ?LanguageElement { - return $this->projection; + return $this->getLanguageElement('./mods:scale' . $query); } /** - * Get the value of scale + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#coordinates * * @access public * - * @return LanguageElement + * @param string $query The XPath query for metadata search + * + * @return LanguageElement[] */ - public function getScale(): LanguageElement + public function getCoordinates(string $query = ''): array { - return $this->scale; + return $this->getLanguageElements('./mods:coordinates' . $query); } /** - * Get the value of cartographicExtension + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#cartographicextension * * @access public * - * @return LanguageElement + * @param string $query The XPath query for metadata search + * + * @return LanguageElement[] */ - public function getCartographicExtension(): LanguageElement + public function getCartographicExtensions(string $query = ''): array { - return $this->cartographicExtension; + return $this->getLanguageElements('./mods:cartographicExtension' . $query); } -} \ No newline at end of file +} diff --git a/src/Mods/Element/Specific/OriginInfo/Place/PlaceIdentifier.php b/src/Mods/Element/Specific/OriginInfo/Place/PlaceIdentifier.php deleted file mode 100644 index 656a46a..0000000 --- a/src/Mods/Element/Specific/OriginInfo/Place/PlaceIdentifier.php +++ /dev/null @@ -1,38 +0,0 @@ -