diff --git a/src/Mods/Element/Part.php b/src/Mods/Element/Part.php index 65d4382..f88fdd8 100644 --- a/src/Mods/Element/Part.php +++ b/src/Mods/Element/Part.php @@ -21,9 +21,11 @@ use Slub\Mods\Element\Specific\Part\Detail; use Slub\Mods\Element\Specific\Part\Extent; use Slub\Mods\Element\Specific\Part\Text; +use Slub\Mods\Element\Xml\Element; /** * Part MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/part.html * * @access public */ @@ -31,30 +33,6 @@ class Part extends BaseElement { use LanguageAttribute, IdAttribute, AltRepGroupAttribute, DisplayLabelAttribute; - /** - * @access private - * @var Detail - */ - private Detail $detail; - - /** - * @access private - * @var Extent - */ - private Extent $extent; - - /** - * @access private - * @var DateElement - */ - private DateElement $date; - - /** - * @access private - * @var Text - */ - private Text $text; - /** * This extracts the essential MODS metadata from XML * @@ -70,7 +48,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/part.html#type * * @access public * @@ -82,7 +61,8 @@ public function getType(): string } /** - * Get the value of order + * Get the value of the 'order' attribute. + * @see https://www.loc.gov/standards/mods/userguide/part.html#order * * @access public * @@ -94,50 +74,86 @@ public function getOrder(): int } /** - * Get the value of detail + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#detail * * @access public * - * @return Detail + * @param string $query The XPath query for metadata search + * + * @return Detail[] */ - public function getDetail(): Detail + public function getDetails(string $query = ''): array { - return $this->detail; + $details = []; + $xpath = './mods:detail' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $details[] = new Detail($value); + } + } + return $details; } /** - * Get the value of extent + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#extent * * @access public * - * @return Extent + * @param string $query The XPath query for metadata search + * + * @return Extent[] */ - public function getExtent(): Extent + public function getExtents(string $query = ''): array { - return $this->extent; + $extents = []; + $xpath = './mods:extent' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $extents[] = new Extent($value); + } + } + return $extents; } /** - * Get the value of date + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#date * * @access public * - * @return DateElement + * @param string $query The XPath query for metadata search + * + * @return DateElement[] */ - public function getDate(): DateElement + public function getDates(string $query = ''): array { - return $this->date; + return $this->getDateElements('./mods:date' . $query); } /** - * Get the value of text + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#text * * @access public * - * @return Text + * @param string $query The XPath query for metadata search + * + * @return Text[] */ - public function getText(): Text + public function getTexts(string $query = ''): array { - return $this->text; + $texts = []; + $xpath = './mods:text' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $texts[] = new Text($value); + } + } + return $texts; } } diff --git a/src/Mods/Element/Specific/Part/Detail.php b/src/Mods/Element/Specific/Part/Detail.php index 60dc489..fcfb2de 100644 --- a/src/Mods/Element/Specific/Part/Detail.php +++ b/src/Mods/Element/Specific/Part/Detail.php @@ -17,30 +17,13 @@ /** * Detail MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/part.html#detail * * @access public */ class Detail extends BaseElement { - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $number; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $caption; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $title; - /** * This extracts the essential MODS metadata from XML * @@ -56,7 +39,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/part.html#detailtype * * @access public * @@ -68,7 +52,8 @@ public function getType(): string } /** - * Get the value of level + * Get the value of the 'level' attribute. + * @see https://www.loc.gov/standards/mods/userguide/part.html#level * * @access public * @@ -80,38 +65,47 @@ public function getLevel(): int } /** - * Get the value of number + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#number * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getNumber(): LanguageElement + public function getNumbers(string $query = ''): array { - return $this->number; + return $this->getLanguageElements('./mods:number' . $query); } /** - * Get the value of caption + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#caption * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getCaption(): LanguageElement + public function getCaptions(string $query = ''): array { - return $this->caption; + return $this->getLanguageElements('./mods:caption' . $query); } /** - * Get the value of title + * Get the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/part.html#title * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getTitle(): LanguageElement + public function getTitles(string $query = ''): array { - return $this->title; + return $this->getLanguageElements('./mods:title' . $query); } } diff --git a/src/Mods/Element/Specific/Part/Extent.php b/src/Mods/Element/Specific/Part/Extent.php index 1be1e2c..c95550d 100644 --- a/src/Mods/Element/Specific/Part/Extent.php +++ b/src/Mods/Element/Specific/Part/Extent.php @@ -14,39 +14,17 @@ use Slub\Mods\Element\Common\BaseElement; use Slub\Mods\Element\Common\LanguageElement; +use Slub\Mods\Element\Xml\Element; /** * Extent MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/part.html#extent * * @access public */ class Extent extends BaseElement { - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $start; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $end; - - /** - * @access private - * @var int - */ - private int $total; - - /** - * @access private - * @var LanguageElement - */ - private LanguageElement $list; - /** * This extracts the essential MODS metadata from XML * @@ -62,7 +40,8 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of unit + * Get the value of the 'unit' attribute. + * @see https://www.loc.gov/standards/mods/userguide/part.html#unit * * @access public * @@ -74,50 +53,67 @@ public function getUnit(): string } /** - * Get the value of start + * Get the value of the <start> element. + * @see https://www.loc.gov/standards/mods/userguide/part.html#start * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getStart(): LanguageElement + public function getStart(string $query = ''): LanguageElement { - return $this->start; + return $this->getLanguageElement('./mods:start' . $query); } /** - * Get the value of end + * Get the value of the <end> element. + * @see https://www.loc.gov/standards/mods/userguide/part.html#end * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getEnd(): LanguageElement + public function getEnd(string $query = ''): LanguageElement { - return $this->end; + return $this->getLanguageElement('./mods:end' . $query); } /** - * Get the value of total + * Get the value of the <total> element. + * @see https://www.loc.gov/standards/mods/userguide/part.html#total * * @access public * - * @return int + * @param string $query The XPath query for metadata search + * + * @return int value or 0 when no value found */ - public function getTotal(): int + public function getTotal(string $query = ''): int { - return $this->total; + $xpath = './mods:total' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + return (int) $element->getValues()[0]; + } + return 0; } /** - * Get the value of list + * Get the value of the <list> element. + * @see https://www.loc.gov/standards/mods/userguide/part.html#list * * @access public * + * @param string $query The XPath query for metadata search + * * @return LanguageElement */ - public function getList(): LanguageElement + public function getList(string $query = ''): LanguageElement { - return $this->list; + return $this->getLanguageElement('./mods:list' . $query); } } diff --git a/src/Mods/Element/Specific/Part/Text.php b/src/Mods/Element/Specific/Part/Text.php index d7340c2..6902017 100644 --- a/src/Mods/Element/Specific/Part/Text.php +++ b/src/Mods/Element/Specific/Part/Text.php @@ -18,6 +18,7 @@ /** * Text MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/part.html#text * * @access public */ @@ -39,9 +40,9 @@ public function __construct(\SimpleXMLElement $xml) parent::__construct($xml); } - /** - * Get the value of type + * Get the value of the 'type' attribute. + * @see https://www.loc.gov/standards/mods/userguide/part.html#texttype * * @access public * @@ -49,11 +50,6 @@ public function __construct(\SimpleXMLElement $xml) */ public function getType(): string { - $value = $this->xml->attributes()->type; - - if (!empty($value)) { - return $value; - } - return ''; + return $this->getStringAttribute('type'); } }