diff --git a/src/Mods/ModsReader.php b/src/Mods/ModsReader.php index 0a299e2..6fae14d 100644 --- a/src/Mods/ModsReader.php +++ b/src/Mods/ModsReader.php @@ -12,27 +12,27 @@ namespace Slub\Mods; -use Slub\Mods\Element\AbstractElement; -use Slub\Mods\Element\AccessCondition; -use Slub\Mods\Element\Classification; -use Slub\Mods\Element\Extension; -use Slub\Mods\Element\Genre; -use Slub\Mods\Element\Identifier; -use Slub\Mods\Element\Language; -use Slub\Mods\Element\Location; -use Slub\Mods\Element\Name; -use Slub\Mods\Element\Note; -use Slub\Mods\Element\OriginInfo; -use Slub\Mods\Element\Part; -use Slub\Mods\Element\PhysicalDescription; -use Slub\Mods\Element\RecordInfo; -use Slub\Mods\Element\RelatedItem; -use Slub\Mods\Element\Subject; -use Slub\Mods\Element\TableOfContents; -use Slub\Mods\Element\TargetAudience; -use Slub\Mods\Element\TitleInfo; -use Slub\Mods\Element\TypeOfResource; use Slub\Mods\Element\Xml\Element; +use Slub\Mods\Reader\AbstractReader; +use Slub\Mods\Reader\AccessConditionReader; +use Slub\Mods\Reader\ClassificationReader; +use Slub\Mods\Reader\ExtensionReader; +use Slub\Mods\Reader\GenreReader; +use Slub\Mods\Reader\IdentifierReader; +use Slub\Mods\Reader\LanguageReader; +use Slub\Mods\Reader\LocationReader; +use Slub\Mods\Reader\NameReader; +use Slub\Mods\Reader\NoteReader; +use Slub\Mods\Reader\OriginInfoReader; +use Slub\Mods\Reader\PartReader; +use Slub\Mods\Reader\PhysicalDescriptionReader; +use Slub\Mods\Reader\RecordInfoReader; +use Slub\Mods\Reader\RelatedItemReader; +use Slub\Mods\Reader\SubjectReader; +use Slub\Mods\Reader\TableOfContentsReader; +use Slub\Mods\Reader\TargetAudienceReader; +use Slub\Mods\Reader\TitleInfoReader; +use Slub\Mods\Reader\TypeOfResourceReader; /** * Metadata MODS reader class for the 'php-mods-reader' library. @@ -42,6 +42,9 @@ */ class ModsReader { + + use AbstractReader, AccessConditionReader, ClassificationReader, ExtensionReader, GenreReader, IdentifierReader, LanguageReader, LocationReader, NameReader, NoteReader, OriginInfoReader, PartReader, PhysicalDescriptionReader, RecordInfoReader, RelatedItemReader, SubjectReader, TableOfContentsReader, TargetAudienceReader, TitleInfoReader, TypeOfResourceReader; + /** * @access protected * @var \SimpleXMLElement The metadata XML @@ -63,1122 +66,17 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of the element. - * @see https://www.loc.gov/standards/mods/userguide/abstract.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?AbstractElement - */ - public function getAbstract(string $query = ''): ?AbstractElement - { - $xpath = './mods:abstract' . $query; - $element = new Element($this->xml, $xpath); - if ($element->exists()) { - return new AbstractElement($element->getValues()[0]); - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html - * - * @access public - * - * @param string $query for metadata search - * - * @return AccessCondition[] - */ - public function getAccessConditions(string $query = ''): array - { - $accessConditions = []; - $xpath = './mods:accessCondition' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $accessConditions[] = new AccessCondition($value); - } - return $accessConditions; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?AccessCondition - */ - public function getFirstAccessCondition(string $query = ''): ?AccessCondition - { - $elements = $this->getAccessConditions($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?AccessCondition - */ - public function getLastAccessCondition(string $query = ''): ?AccessCondition - { - $elements = $this->getAccessConditions($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/classification.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Classification[] - */ - public function getClassifications(string $query = ''): array - { - $classifications = []; - $xpath = './mods:classification' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $classifications[] = new Classification($value); - } - return $classifications; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/classification.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Classification - */ - public function getFirstClassification(string $query = ''): ?Classification - { - $elements = $this->getClassifications($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/classification.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Classification - */ - public function getLastClassification(string $query = ''): ?Classification - { - $elements = $this->getClassifications($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/extension.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Extension[] - */ - public function getExtensions(string $query = ''): array - { - $extensions = []; - $xpath = './mods:extension' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $extensions[] = new Extension($value); - } - return $extensions; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/extension.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Extension - */ - public function getFirstExtension(string $query = ''): ?Extension - { - $elements = $this->getExtensions($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/extension.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Extension - */ - public function getLastExtension(string $query = ''): ?Extension - { - $elements = $this->getExtensions($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/genre.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Genre[] - */ - public function getGenres(string $query = ''): array - { - $genres = []; - $xpath = './mods:genre' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $genres[] = new Genre($value); - } - return $genres; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/genre.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Genre - */ - public function getFirstGenre(string $query = ''): ?Genre - { - $elements = $this->getGenres($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/genre.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Genre - */ - public function getLastGenre(string $query = ''): ?Genre - { - $elements = $this->getGenres($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/identifier.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Identifier[] - */ - public function getIdentifiers(string $query = ''): array - { - $identifiers = []; - $xpath = './mods:identifier' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $identifiers[] = new Identifier($value); - } - return $identifiers; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/identifier.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Identifier - */ - public function getFirstIdentifier(string $query = ''): ?Identifier - { - $elements = $this->getIdentifiers($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/identifier.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Identifier - */ - public function getLastIdentifier(string $query = ''): ?Identifier - { - $elements = $this->getIdentifiers($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/language.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Language[] - */ - public function getLanguages(string $query = ''): array - { - $languages = []; - $xpath = './mods:language' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $languages[] = new Language($value); - } - return $languages; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/language.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Language - */ - public function getFirstLanguage(string $query = ''): ?Language - { - $elements = $this->getLanguages($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/language.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Language - */ - public function getLastLanguage(string $query = ''): ?Language - { - $elements = $this->getLanguages($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/location.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Location[] - */ - public function getLocations(string $query = ''): array - { - $locations = []; - $xpath = './mods:location' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $locations[] = new Location($value); - } - return $locations; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/location.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Location - */ - public function getFirstLocation(string $query = ''): ?Location - { - $elements = $this->getLocations($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/location.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Location - */ - public function getLastLocation(string $query = ''): ?Location - { - $elements = $this->getLocations($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/name.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Name[] - */ - public function getNames(string $query = ''): array - { - $names = []; - $xpath = './mods:name' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $names[] = new Name($value); - } - return $names; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/name.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Name - */ - public function getFirstName(string $query = ''): ?Name - { - $elements = $this->getNames($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/name.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Name - */ - public function getLastName(string $query = ''): ?Name - { - $elements = $this->getNames($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/note.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Note[] - */ - public function getNotes(string $query = ''): array - { - $notes = []; - $xpath = './mods:note' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $notes[] = new Note($value); - } - return $notes; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/note.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Note - */ - public function getFirstNote(string $query = ''): ?Note - { - $elements = $this->getNotes($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/note.html + * Get array of values for read element. * - * @access public + * @access private * - * @param string $query for metadata search - * - * @return ?Note - */ - public function getLastNote(string $query = ''): ?Note - { - $elements = $this->getNotes($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/origininfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return OriginInfo[] - */ - public function getOriginInfos(string $query = ''): array - { - $originInfos = []; - $xpath = './mods:originInfo' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $originInfos[] = new OriginInfo($value); - } - return $originInfos; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/origininfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?OriginInfo - */ - public function getFirstOriginInfo(string $query = ''): ?OriginInfo - { - $elements = $this->getOriginInfos($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/origininfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?OriginInfo - */ - public function getLastOriginInfo(string $query = ''): ?OriginInfo - { - $elements = $this->getOriginInfos($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/part.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Part[] - */ - public function getParts(string $query = ''): array - { - $parts = []; - $xpath = './mods:part' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $parts[] = new Part($value); - } - return $parts; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/part.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Part - */ - public function getFirstPart(string $query = ''): ?Part - { - $elements = $this->getParts($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/part.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Part - */ - public function getLastPart(string $query = ''): ?Part - { - $elements = $this->getParts($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html - * - * @access public - * - * @param string $query for metadata search - * - * @return PhysicalDescription[] - */ - public function getPhysicalDescriptions(string $query = ''): array - { - $physicalDescriptions = []; - $xpath = './mods:physicalDescription' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $physicalDescriptions[] = new PhysicalDescription($value); - } - return $physicalDescriptions; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?PhysicalDescription - */ - public function getFirstPhysicalDescription(string $query = ''): ?PhysicalDescription - { - $elements = $this->getPhysicalDescriptions($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?PhysicalDescription - */ - public function getLastPhysicalDescription(string $query = ''): ?PhysicalDescription - { - $elements = $this->getPhysicalDescriptions($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return RecordInfo[] - */ - public function getRecordInfos(string $query = ''): array - { - $recordInfos = []; - $xpath = './mods:recordInfo' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $recordInfos[] = new RecordInfo($value); - } - return $recordInfos; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?RecordInfo - */ - public function getFirstRecordInfo(string $query = ''): ?RecordInfo - { - $elements = $this->getRecordInfos($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?RecordInfo - */ - public function getLastRecordInfo(string $query = ''): ?RecordInfo - { - $elements = $this->getRecordInfos($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/relateditem.html - * - * @access public - * - * @param string $query for metadata search - * - * @return RelatedItem[] - */ - public function getRelatedItems(string $query = ''): array - { - $relatedItems = []; - $xpath = './mods:relatedItem' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $relatedItems[] = new RelatedItem($value); - } - return $relatedItems; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/relateditem.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?RelatedItem - */ - public function getFirstRelatedItem(string $query = ''): ?RelatedItem - { - $elements = $this->getRelatedItems($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/relateditem.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?RelatedItem - */ - public function getLastRelatedItem(string $query = ''): ?RelatedItem - { - $elements = $this->getRelatedItems($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/subject.html - * - * @access public - * - * @param string $query for metadata search - * - * @return Subject[] - */ - public function getSubjects(string $query = ''): array - { - $subjects = []; - $xpath = './mods:subject' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $subjects[] = new Subject($value); - } - return $subjects; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/subject.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Subject - */ - public function getFirstSubject(string $query = ''): ?Subject - { - $elements = $this->getSubjects($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/subject.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?Subject - */ - public function getLastSubject(string $query = ''): ?Subject - { - $elements = $this->getSubjects($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html - * - * @access public - * - * @param string $query for metadata search - * - * @return TableOfContents[] - */ - public function getTableOfContents(string $query = ''): array - { - $tableOfContents = []; - $xpath = './mods:tableOfContents' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $tableOfContents[] = new TableOfContents($value); - } - return $tableOfContents; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TableOfContents - */ - public function getFirstTableOfContents(string $query = ''): ?TableOfContents - { - $elements = $this->getTableOfContents($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TableOfContents - */ - public function getLastTableOfContents(string $query = ''): ?TableOfContents - { - $elements = $this->getTableOfContents($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html - * - * @access public - * - * @param string $query for metadata search - * - * @return TargetAudience[] - */ - public function getTargetAudiences(string $query = ''): array - { - $targetAudiences = []; - $xpath = './mods:targetAudience' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $targetAudiences[] = new TargetAudience($value); - } - return $targetAudiences; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TargetAudience - */ - public function getFirstTargetAudience(string $query = ''): ?TargetAudience - { - $elements = $this->getTargetAudiences($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TargetAudience - */ - public function getLastTargetAudience(string $query = ''): ?TargetAudience - { - $elements = $this->getTargetAudiences($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the the array of the elements. - * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return TitleInfo[] - */ - public function getTitleInfos(string $query = ''): array - { - $titleInfos = []; - $xpath = './mods:titleInfo' . $query; - $element = new Element($this->xml, $xpath); - foreach ($element->getValues() as $value) { - $titleInfos[] = new TitleInfo($value); - } - return $titleInfos; - } - - /** - * Get the the first matching element. - * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TitleInfo - */ - public function getFirstTitleInfo(string $query = ''): ?TitleInfo - { - $elements = $this->getTitleInfos($query); - if (count($elements) > 0) { - return $elements[0]; - } - return null; - } - - /** - * Get the the last matching element. - * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html - * - * @access public - * - * @param string $query for metadata search - * - * @return ?TitleInfo - */ - public function getLastTitleInfo(string $query = ''): ?TitleInfo - { - $elements = $this->getTitleInfos($query); - $count = count($elements); - if ($count > 0) { - return $elements[$count - 1]; - } - return null; - } - - /** - * Get the value of the element. - * @see https://www.loc.gov/standards/mods/userguide/typeofresource.html - * - * @access public - * - * @param string $query for metadata search + * @param string $xpath for metadata search * - * @return ?TypeOfResource + * @return array */ - public function getTypeOfResource(string $query = ''): ?TypeOfResource + private function getValues(string $xpath): array { - $xpath = './mods:typeOfResource' . $query; $element = new Element($this->xml, $xpath); - if ($element->exists()) { - return new TypeOfResource($element->getValues()[0]); - } - return null; + return $element->getValues(); } } diff --git a/src/Mods/Reader/AbstractReader.php b/src/Mods/Reader/AbstractReader.php new file mode 100644 index 0000000..db4a034 --- /dev/null +++ b/src/Mods/Reader/AbstractReader.php @@ -0,0 +1,43 @@ + element. + * @see https://www.loc.gov/standards/mods/userguide/abstract.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?AbstractElement + */ + public function getAbstract(string $query = ''): ?AbstractElement + { + $xpath = './mods:abstract' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new AbstractElement($element->getFirstValue()); + } + return null; + } +} diff --git a/src/Mods/Reader/AccessConditionReader.php b/src/Mods/Reader/AccessConditionReader.php new file mode 100644 index 0000000..df74a57 --- /dev/null +++ b/src/Mods/Reader/AccessConditionReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html + * + * @access public + * + * @param string $query for metadata search + * + * @return AccessCondition[] + */ + public function getAccessConditions(string $query = ''): array + { + $accessConditions = []; + $values = $this->getValues('./mods:accessCondition' . $query); + foreach ($values as $value) { + $accessConditions[] = new AccessCondition($value); + } + return $accessConditions; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?AccessCondition + */ + public function getAccessCondition(int $index, string $query = ''): ?AccessCondition + { + $values = $this->getValues('./mods:accessCondition' . $query); + if (array_key_exists($index, $values)) { + return new AccessCondition($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?AccessCondition + */ + public function getFirstAccessCondition(string $query = ''): ?AccessCondition + { + return $this->getAccessCondition(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/accesscondition.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?AccessCondition + */ + public function getLastAccessCondition(string $query = ''): ?AccessCondition + { + $elements = $this->getAccessConditions($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/ClassificationReader.php b/src/Mods/Reader/ClassificationReader.php new file mode 100644 index 0000000..49df63b --- /dev/null +++ b/src/Mods/Reader/ClassificationReader.php @@ -0,0 +1,96 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/classification.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Classification[] + */ + public function getClassifications(string $query = ''): array + { + $classifications = []; + $values = $this->getValues('./mods:classification' . $query); + foreach ($values as $value) { + $classifications[] = new Classification($value); + } + return $classifications; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/classification.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Classification + */ + public function getClassification(int $index, string $query = ''): ?Classification + { + $values = $this->getValues('./mods:classification' . $query); + if (array_key_exists($index, $values)) { + return new Classification($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/classification.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Classification + */ + public function getFirstClassification(string $query = ''): ?Classification + { + return $this->getClassification(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/classification.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Classification + */ + public function getLastClassification(string $query = ''): ?Classification + { + $elements = $this->getClassifications($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/ExtensionReader.php b/src/Mods/Reader/ExtensionReader.php new file mode 100644 index 0000000..557eff8 --- /dev/null +++ b/src/Mods/Reader/ExtensionReader.php @@ -0,0 +1,98 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/extension.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Extension[] + */ + public function getExtensions(string $query = ''): array + { + $extensions = []; + $values = $this->getValues('./mods:extension' . $query); + foreach ($values as $value) { + $extensions[] = new Extension($value); + } + return $extensions; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/extension.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Extension + */ + public function getExtension(int $index, string $query = ''): ?Extension + { + $values = $this->getValues('./mods:extension' . $query); + if (array_key_exists($index, $values)) { + return new Extension($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/extension.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Extension + */ + public function getFirstExtension(string $query = ''): ?Extension + { + return $this->getExtension(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/extension.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Extension + */ + public function getLastExtension(string $query = ''): ?Extension + { + $elements = $this->getExtensions($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/GenreReader.php b/src/Mods/Reader/GenreReader.php new file mode 100644 index 0000000..ba08f17 --- /dev/null +++ b/src/Mods/Reader/GenreReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/genre.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Genre[] + */ + public function getGenres(string $query = ''): array + { + $genres = []; + $values = $this->getValues('./mods:genre' . $query); + foreach ($values as $value) { + $genres[] = new Genre($value); + } + return $genres; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/genre.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Genre + */ + public function getGenre(int $index, string $query = ''): ?Genre + { + $values = $this->getValues('./mods:genre' . $query); + if (array_key_exists($index, $values)) { + return new Genre($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/genre.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Genre + */ + public function getFirstGenre(string $query = ''): ?Genre + { + return $this->getGenre(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/genre.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Genre + */ + public function getLastGenre(string $query = ''): ?Genre + { + $elements = $this->getGenres($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/IdentifierReader.php b/src/Mods/Reader/IdentifierReader.php new file mode 100644 index 0000000..8bc6bea --- /dev/null +++ b/src/Mods/Reader/IdentifierReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/identifier.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Identifier[] + */ + public function getIdentifiers(string $query = ''): array + { + $identifiers = []; + $values = $this->getValues('./mods:identifier' . $query); + foreach ($values as $value) { + $identifiers[] = new Identifier($value); + } + return $identifiers; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/identifier.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Identifier + */ + public function getIdentifier(int $index, string $query = ''): ?Identifier + { + $values = $this->getValues('./mods:identifier' . $query); + if (array_key_exists($index, $values)) { + return new Identifier($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/identifier.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Identifier + */ + public function getFirstIdentifier(string $query = ''): ?Identifier + { + return $this->getIdentifier(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/identifier.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Identifier + */ + public function getLastIdentifier(string $query = ''): ?Identifier + { + $elements = $this->getIdentifiers($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/LanguageReader.php b/src/Mods/Reader/LanguageReader.php new file mode 100644 index 0000000..87d9b82 --- /dev/null +++ b/src/Mods/Reader/LanguageReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/language.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Language[] + */ + public function getLanguages(string $query = ''): array + { + $languages = []; + $values = $this->getValues('./mods:language' . $query); + foreach ($values as $value) { + $languages[] = new Language($value); + } + return $languages; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/language.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Language + */ + public function getLanguage(int $index, string $query = ''): ?Language + { + $values = $this->getValues('./mods:language' . $query); + if (array_key_exists($index, $values)) { + return new Language($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/language.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Language + */ + public function getFirstLanguage(string $query = ''): ?Language + { + return $this->getLanguage(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/language.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Language + */ + public function getLastLanguage(string $query = ''): ?Language + { + $elements = $this->getLanguages($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/LocationReader.php b/src/Mods/Reader/LocationReader.php new file mode 100644 index 0000000..1d1a55c --- /dev/null +++ b/src/Mods/Reader/LocationReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/location.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Location[] + */ + public function getLocations(string $query = ''): array + { + $locations = []; + $values = $this->getValues('./mods:location' . $query); + foreach ($values as $value) { + $locations[] = new Location($value); + } + return $locations; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/location.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Location + */ + public function getLocation(int $index, string $query = ''): ?Location + { + $values = $this->getValues('./mods:location' . $query); + if (array_key_exists($index, $values)) { + return new Location($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/location.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Location + */ + public function getFirstLocation(string $query = ''): ?Location + { + return $this->getLocation(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/location.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Location + */ + public function getLastLocation(string $query = ''): ?Location + { + $elements = $this->getLocations($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/NameReader.php b/src/Mods/Reader/NameReader.php new file mode 100644 index 0000000..0a04275 --- /dev/null +++ b/src/Mods/Reader/NameReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/name.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Name[] + */ + public function getNames(string $query = ''): array + { + $names = []; + $values = $this->getValues('./mods:name' . $query); + foreach ($values as $value) { + $names[] = new Name($value); + } + return $names; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/name.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Name + */ + public function getName(int $index, string $query = ''): ?Name + { + $values = $this->getValues('./mods:name' . $query); + if (array_key_exists($index, $values)) { + return new Name($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/name.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Name + */ + public function getFirstName(string $query = ''): ?Name + { + return $this->getName(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/name.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Name + */ + public function getLastName(string $query = ''): ?Name + { + $elements = $this->getNames($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/NoteReader.php b/src/Mods/Reader/NoteReader.php new file mode 100644 index 0000000..3a94415 --- /dev/null +++ b/src/Mods/Reader/NoteReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/note.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Note[] + */ + public function getNotes(string $query = ''): array + { + $notes = []; + $values = $this->getValues('./mods:note' . $query); + foreach ($values as $value) { + $notes[] = new Note($value); + } + return $notes; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/note.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Note + */ + public function getNote(int $index, string $query = ''): ?Note + { + $values = $this->getValues('./mods:note' . $query); + if (array_key_exists($index, $values)) { + return new Note($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/note.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Note + */ + public function getFirstNote(string $query = ''): ?Note + { + return $this->getNote(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/note.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Note + */ + public function getLastNote(string $query = ''): ?Note + { + $elements = $this->getNotes($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/OriginInfoReader.php b/src/Mods/Reader/OriginInfoReader.php new file mode 100644 index 0000000..9737975 --- /dev/null +++ b/src/Mods/Reader/OriginInfoReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return OriginInfo[] + */ + public function getOriginInfos(string $query = ''): array + { + $originInfos = []; + $values = $this->getValues('./mods:originInfo' . $query); + foreach ($values as $value) { + $originInfos[] = new OriginInfo($value); + } + return $originInfos; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?OriginInfo + */ + public function getOriginInfo(int $index, string $query = ''): ?OriginInfo + { + $values = $this->getValues('./mods:originInfo' . $query); + if (array_key_exists($index, $values)) { + return new OriginInfo($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?OriginInfo + */ + public function getFirstOriginInfo(string $query = ''): ?OriginInfo + { + return $this->getOriginInfo(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/origininfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?OriginInfo + */ + public function getLastOriginInfo(string $query = ''): ?OriginInfo + { + $elements = $this->getOriginInfos($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/PartReader.php b/src/Mods/Reader/PartReader.php new file mode 100644 index 0000000..e88c71a --- /dev/null +++ b/src/Mods/Reader/PartReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Part[] + */ + public function getParts(string $query = ''): array + { + $parts = []; + $values = $this->getValues('./mods:part' . $query); + foreach ($values as $value) { + $parts[] = new Part($value); + } + return $parts; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/part.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Part + */ + public function getPart(int $index, string $query = ''): ?Part + { + $values = $this->getValues('./mods:part' . $query); + if (array_key_exists($index, $values)) { + return new Part($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/part.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Part + */ + public function getFirstPart(string $query = ''): ?Part + { + return $this->getPart(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/part.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Part + */ + public function getLastPart(string $query = ''): ?Part + { + $elements = $this->getParts($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/PhysicalDescriptionReader.php b/src/Mods/Reader/PhysicalDescriptionReader.php new file mode 100644 index 0000000..978526b --- /dev/null +++ b/src/Mods/Reader/PhysicalDescriptionReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html + * + * @access public + * + * @param string $query for metadata search + * + * @return PhysicalDescription[] + */ + public function getPhysicalDescriptions(string $query = ''): array + { + $physicalDescriptions = []; + $values = $this->getValues('./mods:physicalDescription' . $query); + foreach ($values as $value) { + $physicalDescriptions[] = new PhysicalDescription($value); + } + return $physicalDescriptions; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?PhysicalDescription + */ + public function getPhysicalDescription(int $index, string $query = ''): ?PhysicalDescription + { + $values = $this->getValues('./mods:physicalDescription' . $query); + if (array_key_exists($index, $values)) { + return new PhysicalDescription($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?PhysicalDescription + */ + public function getFirstPhysicalDescription(string $query = ''): ?PhysicalDescription + { + return $this->getPhysicalDescription(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?PhysicalDescription + */ + public function getLastPhysicalDescription(string $query = ''): ?PhysicalDescription + { + $elements = $this->getPhysicalDescriptions($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/RecordInfoReader.php b/src/Mods/Reader/RecordInfoReader.php new file mode 100644 index 0000000..fca905a --- /dev/null +++ b/src/Mods/Reader/RecordInfoReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return RecordInfo[] + */ + public function getRecordInfos(string $query = ''): array + { + $recordInfos = []; + $values = $this->getValues('./mods:recordInfo' . $query); + foreach ($values as $value) { + $recordInfos[] = new RecordInfo($value); + } + return $recordInfos; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?RecordInfo + */ + public function getRecordInfo(int $index, string $query = ''): ?RecordInfo + { + $values = $this->getValues('./mods:recordInfo' . $query); + if (array_key_exists($index, $values)) { + return new RecordInfo($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?RecordInfo + */ + public function getFirstRecordInfo(string $query = ''): ?RecordInfo + { + return $this->getRecordInfo(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/recordinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?RecordInfo + */ + public function getLastRecordInfo(string $query = ''): ?RecordInfo + { + $elements = $this->getRecordInfos($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/RelatedItemReader.php b/src/Mods/Reader/RelatedItemReader.php new file mode 100644 index 0000000..f3ebba3 --- /dev/null +++ b/src/Mods/Reader/RelatedItemReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/relateditem.html + * + * @access public + * + * @param string $query for metadata search + * + * @return RelatedItem[] + */ + public function getRelatedItems(string $query = ''): array + { + $relatedItems = []; + $values = $this->getValues('./mods:relatedItem' . $query); + foreach ($values as $value) { + $relatedItems[] = new RelatedItem($value); + } + return $relatedItems; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/relateditem.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?RelatedItem + */ + public function getRelatedItem(int $index, string $query = ''): ?RelatedItem + { + $values = $this->getValues('./mods:relatedItem' . $query); + if (array_key_exists($index, $values)) { + return new RelatedItem($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/relateditem.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?RelatedItem + */ + public function getFirstRelatedItem(string $query = ''): ?RelatedItem + { + return $this->getRelatedItem(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/relateditem.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?RelatedItem + */ + public function getLastRelatedItem(string $query = ''): ?RelatedItem + { + $elements = $this->getRelatedItems($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/SubjectReader.php b/src/Mods/Reader/SubjectReader.php new file mode 100644 index 0000000..1b71164 --- /dev/null +++ b/src/Mods/Reader/SubjectReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html + * + * @access public + * + * @param string $query for metadata search + * + * @return Subject[] + */ + public function getSubjects(string $query = ''): array + { + $subjects = []; + $values = $this->getValues('./mods:subject' . $query); + foreach ($values as $value) { + $subjects[] = new Subject($value); + } + return $subjects; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/subject.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?Subject + */ + public function getSubject(int $index, string $query = ''): ?Subject + { + $values = $this->getValues('./mods:subject' . $query); + if (array_key_exists($index, $values)) { + return new Subject($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/subject.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Subject + */ + public function getFirstSubject(string $query = ''): ?Subject + { + return $this->getSubject(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/subject.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?Subject + */ + public function getLastSubject(string $query = ''): ?Subject + { + $elements = $this->getSubjects($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/TableOfContentsReader.php b/src/Mods/Reader/TableOfContentsReader.php new file mode 100644 index 0000000..dff031c --- /dev/null +++ b/src/Mods/Reader/TableOfContentsReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html + * + * @access public + * + * @param string $query for metadata search + * + * @return TableOfContents[] + */ + public function getTablesOfContents(string $query = ''): array + { + $tableOfContents = []; + $values = $this->getValues('./mods:tableOfContents' . $query); + foreach ($values as $value) { + $tableOfContents[] = new TableOfContents($value); + } + return $tableOfContents; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?TableOfContents + */ + public function getTableOfContents(int $index, string $query = ''): ?TableOfContents + { + $values = $this->getValues('./mods:tableOfContents' . $query); + if (array_key_exists($index, $values)) { + return new TableOfContents($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TableOfContents + */ + public function getFirstTableOfContents(string $query = ''): ?TableOfContents + { + return $this->getTableOfContents(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/tableofcontents.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TableOfContents + */ + public function getLastTableOfContents(string $query = ''): ?TableOfContents + { + $elements = $this->getTablesOfContents($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/TargetAudienceReader.php b/src/Mods/Reader/TargetAudienceReader.php new file mode 100644 index 0000000..4924bf7 --- /dev/null +++ b/src/Mods/Reader/TargetAudienceReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html + * + * @access public + * + * @param string $query for metadata search + * + * @return TargetAudience[] + */ + public function getTargetAudiences(string $query = ''): array + { + $targetAudiences = []; + $values = $this->getValues('./mods:targetAudience' . $query); + foreach ($values as $value) { + $targetAudiences[] = new TargetAudience($value); + } + return $targetAudiences; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?TargetAudience + */ + public function getTargetAudience(int $index, string $query = ''): ?TargetAudience + { + $values = $this->getValues('./mods:targetAudience' . $query); + if (array_key_exists($index, $values)) { + return new TargetAudience($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TargetAudience + */ + public function getFirstTargetAudience(string $query = ''): ?TargetAudience + { + return $this->getTargetAudience(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/targetaudience.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TargetAudience + */ + public function getLastTargetAudience(string $query = ''): ?TargetAudience + { + $elements = $this->getTargetAudiences($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/TitleInfoReader.php b/src/Mods/Reader/TitleInfoReader.php new file mode 100644 index 0000000..99221e0 --- /dev/null +++ b/src/Mods/Reader/TitleInfoReader.php @@ -0,0 +1,97 @@ + elements. + * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return TitleInfo[] + */ + public function getTitleInfos(string $query = ''): array + { + $titleInfos = []; + $values = $this->getValues('./mods:titleInfo' . $query); + foreach ($values as $value) { + $titleInfos[] = new TitleInfo($value); + } + return $titleInfos; + } + + /** + * Get the matching element. + * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html + * + * @access public + * + * @param int $index of the searched element + * @param string $query for metadata search + * + * @return ?TitleInfo + */ + public function getTitleInfo(int $index, string $query = ''): ?TitleInfo + { + $values = $this->getValues('./mods:titleInfo' . $query); + if (array_key_exists($index, $values)) { + return new TitleInfo($values[$index]); + } + return null; + } + + /** + * Get the the first matching element. + * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TitleInfo + */ + public function getFirstTitleInfo(string $query = ''): ?TitleInfo + { + return $this->getTitleInfo(0, $query); + } + + /** + * Get the the last matching element. + * @see https://www.loc.gov/standards/mods/userguide/titleinfo.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TitleInfo + */ + public function getLastTitleInfo(string $query = ''): ?TitleInfo + { + $elements = $this->getTitleInfos($query); + $count = count($elements); + if ($count > 0) { + return $elements[$count - 1]; + } + return null; + } +} diff --git a/src/Mods/Reader/TypeOfResourceReader.php b/src/Mods/Reader/TypeOfResourceReader.php new file mode 100644 index 0000000..0df38df --- /dev/null +++ b/src/Mods/Reader/TypeOfResourceReader.php @@ -0,0 +1,43 @@ + element. + * @see https://www.loc.gov/standards/mods/userguide/typeofresource.html + * + * @access public + * + * @param string $query for metadata search + * + * @return ?TypeOfResource + */ + public function getTypeOfResource(string $query = ''): ?TypeOfResource + { + $xpath = './mods:typeOfResource' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return new TypeOfResource($element->getFirstValue()); + } + return null; + } +}