Skip to content

Commit

Permalink
Implement functions in Part class and its child element classes
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 15, 2024
1 parent 778da7b commit 2bd59a3
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 117 deletions.
100 changes: 58 additions & 42 deletions src/Mods/Element/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,18 @@
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
*/
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
*
Expand All @@ -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
*
Expand All @@ -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
*
Expand All @@ -94,50 +74,86 @@ public function getOrder(): int
}

/**
* Get the value of detail
* Get the array of the <detail> 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 <extent> 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 <date> 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 <text> 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;
}
}
52 changes: 23 additions & 29 deletions src/Mods/Element/Specific/Part/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand All @@ -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
*
Expand All @@ -80,38 +65,47 @@ public function getLevel(): int
}

/**
* Get the value of number
* Get the array of the <number> 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 <caption> 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 <title> 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);
}
}
Loading

0 comments on commit 2bd59a3

Please sign in to comment.