diff --git a/src/Mods/Element/RecordInfo.php b/src/Mods/Element/RecordInfo.php index 28b528a..f5c481e 100644 --- a/src/Mods/Element/RecordInfo.php +++ b/src/Mods/Element/RecordInfo.php @@ -24,9 +24,11 @@ use Slub\Mods\Element\Specific\RecordInfo\LanguageOfCataloging; use Slub\Mods\Element\Specific\RecordInfo\RecordIdentifier; use Slub\Mods\Element\Specific\RecordInfo\RecordInfoNote; +use Slub\Mods\Element\Xml\Element; /** * RecordInfo MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html * * @access public */ @@ -38,61 +40,213 @@ class RecordInfo extends BaseElement * @access private * @var AuthorityLanguageElement */ - private AuthorityLanguageElement $recordContentSource; + private AuthorityLanguageElement $descriptionStandard; /** - * @access private - * @var DateElement + * This extracts the essential MODS metadata from XML + * + * @access public + * + * @param \SimpleXMLElement $xml The XML to extract the metadata from + * + * @return void */ - private DateElement $recordCreationDate; + public function __construct(\SimpleXMLElement $xml) + { + parent::__construct($xml); + } /** - * @access private - * @var DateElement + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordcontentsource + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] */ - private DateElement $recordChangeDate; + public function getRecordContentSources(string $query = ''): array + { + return $this->getAuthorityLanguageElements('./mods:recordContentSource' . $query); + } /** - * @access private - * @var RecordIdentifier + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordcreationdate + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - private RecordIdentifier $recordIdentifier; + public function getRecordCreationDates(string $query = ''): array + { + return $this->getDateElements('./mods:recordCreationDate' . $query); + } /** - * @access private - * @var LanguageElement + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordchangedate + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - private LanguageElement $recordOrigin; + public function getRecordChangeDates(string $query = ''): array + { + return $this->getDateElements('./mods:recordChangeDate' . $query); + } /** - * @access private - * @var RecordInfoNote + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return RecordIdentifier[] */ - private RecordInfoNote $recordInfoNote; + public function getRecordIdentifiers(string $query = ''): array + { + $recordIdentifiers = []; + $xpath = './mods:recordIdentifier' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $recordIdentifiers[] = new RecordIdentifier($value); + } + } + return $recordIdentifiers; + } /** - * @access private - * @var LanguageOfCataloging + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordorigin + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return LanguageElement[] */ - private LanguageOfCataloging $languageOfCataloging; + public function getRecordOrigins(string $query = ''): array + { + $recordOrigins = []; + $xpath = './mods:recordOrigin' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $recordOrigins[] = new LanguageElement($value); + } + } + return $recordOrigins; + } /** - * @access private - * @var AuthorityLanguageElement + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return RecordIdentifier[] */ - private AuthorityLanguageElement $descriptionStandard; + public function getRecordInfoNotes(string $query = ''): array + { + $recordInfoNotes = []; + $xpath = './mods:recordInfoNote' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $recordInfoNotes[] = new RecordInfoNote($value); + } + } + return $recordInfoNotes; + } /** - * This extracts the essential MODS metadata from XML + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging * * @access public * - * @param \SimpleXMLElement $xml The XML to extract the metadata from + * @param string $query The XPath query for metadata search * - * @return void + * @return LanguageOfCataloging[] */ - public function __construct(\SimpleXMLElement $xml) + public function getLanguageOfCatalogings(string $query = ''): array { - parent::__construct($xml); + $languageOfCatalogings = []; + $xpath = './mods:languageOfCataloging' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $languageOfCatalogings[] = new LanguageOfCataloging($value); + } + } + return $languageOfCatalogings; + } + + /** + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#descriptionstandard + * + * @access public + * + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] + */ + public function getDescriptionStandards(string $query = ''): array + { + return $this->getAuthorityLanguageElements('./mods:descriptionStandard' . $query); + } + + /** + * Get the array of the matching elements. + * + * @access public + * + * @param string $xpath The XPath for metadata search + * + * @return AuthorityLanguageElement[] + */ + private function getAuthorityLanguageElements(string $xpath): array + { + $elements = []; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $elements[] = new AuthorityLanguageElement($value); + } + } + return $elements; + } + + /** + * Get the array of the matching elements. + * + * @access public + * + * @param string $xpath The XPath for metadata search + * + * @return DateElement[] + */ + private 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; } } diff --git a/src/Mods/Element/Specific/RecordInfo/LanguageOfCataloging.php b/src/Mods/Element/Specific/RecordInfo/LanguageOfCataloging.php index 73307a8..4022d57 100644 --- a/src/Mods/Element/Specific/RecordInfo/LanguageOfCataloging.php +++ b/src/Mods/Element/Specific/RecordInfo/LanguageOfCataloging.php @@ -19,9 +19,11 @@ use Slub\Mods\Element\Common\BaseElement; use Slub\Mods\Element\Specific\Language\LanguageTerm; use Slub\Mods\Element\Specific\Language\ScriptTerm; +use Slub\Mods\Element\Xml\Element; /** * LanguageOfCataloging MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging * * @access public */ @@ -29,18 +31,6 @@ class LanguageOfCataloging extends BaseElement { use IdAttribute, AltRepGroupAttribute, DisplayLabelAttribute, UsageAttribute; - /** - * @access private - * @var LanguageTerm - */ - private LanguageTerm $languageTerm; - - /** - * @access private - * @var ScriptTerm - */ - private ScriptTerm $scriptTerm; - /** * This extracts the essential MODS metadata from XML * @@ -53,13 +43,11 @@ class LanguageOfCataloging extends BaseElement public function __construct(\SimpleXMLElement $xml) { parent::__construct($xml); - - $this->languageTerm = new LanguageTerm($xml); - $this->scriptTerm = new ScriptTerm($xml); } /** - * Get the value of objectPart + * Get the value of 'objectPart' attribute. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#objectpart * * @access public * @@ -71,26 +59,42 @@ public function getObjectPart(): string } /** - * Get the value of languageTerm + * Get the value of the element. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageterm * * @access public * - * @return LanguageTerm + * @param string $query The XPath query for metadata search + * + * @return ?LanguageTerm */ - public function getLanguageTerm(): LanguageTerm + public function getLanguageTerm(string $query = ''): ?LanguageTerm { - return $this->languageTerm; + $xpath = './mods:languageTerm' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new LanguageTerm($element->getValues()[0]); + } + return null; } /** - * Get the value of scriptTerm + * Get the value of the element. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#scriptterm * * @access public * - * @return ScriptTerm + * @param string $query The XPath query for metadata search + * + * @return ?ScriptTerm */ - public function getScriptTerm(): ScriptTerm + public function getScriptTerm(string $query = ''): ?ScriptTerm { - return $this->scriptTerm; + $xpath = './mods:scriptTerm' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new ScriptTerm($element->getValues()[0]); + } + return null; } } diff --git a/src/Mods/Element/Specific/RecordInfo/RecordIdentifier.php b/src/Mods/Element/Specific/RecordInfo/RecordIdentifier.php index 316ebb6..2131a9c 100644 --- a/src/Mods/Element/Specific/RecordInfo/RecordIdentifier.php +++ b/src/Mods/Element/Specific/RecordInfo/RecordIdentifier.php @@ -17,6 +17,7 @@ /** * RecordIdentifier MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier * * @access public */ @@ -39,7 +40,8 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of source + * Get the value of the 'source' attribute. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#source * * @access public * @@ -47,11 +49,6 @@ public function __construct(\SimpleXMLElement $xml) */ public function getSource(): string { - $value = $this->xml->attributes()->source; - - if (!empty($value)) { - return $value; - } - return ''; + return $this->getStringAttribute('source'); } } diff --git a/src/Mods/Element/Specific/RecordInfo/RecordInfoNote.php b/src/Mods/Element/Specific/RecordInfo/RecordInfoNote.php index 21cea7e..85d0195 100644 --- a/src/Mods/Element/Specific/RecordInfo/RecordInfoNote.php +++ b/src/Mods/Element/Specific/RecordInfo/RecordInfoNote.php @@ -45,7 +45,8 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of type + * Get the value of the 'type' attribute. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#type * * @access public *