Skip to content

Commit

Permalink
Implement functions in OriginInfo class and its child element classes
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 12, 2024
1 parent 01034c9 commit 951b2ec
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 233 deletions.
74 changes: 71 additions & 3 deletions src/Mods/Element/Common/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Slub\Mods\Element\Common;

use Slub\Mods\Element\Xml\Element;

/**
* MODS metadata element class for the 'php-mods-reader' library.
*
Expand Down Expand Up @@ -41,7 +43,7 @@ public function __construct(\SimpleXMLElement $xml)
}

/**
* Get the text value of element
* Get the text value of element.
*
* @access public
*
Expand All @@ -53,7 +55,13 @@ public function getValue(): string
}

/**
* Get the string value of attribute
* Get the string value of attribute.
*
* @access protected
*
* @param string $attribute name
*
* @return string
*/
protected function getStringAttribute($attribute): string
{
Expand All @@ -66,4 +74,64 @@ protected function getStringAttribute($attribute): string
}
return '';
}
}

/**
* Get the the array of the matching elements.
*
* @access protected
*
* @param string $xpath The XPath for metadata search
*
* @return DateElement[]
*/
protected function getDateElements(string $xpath): array
{
$elements = [];
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$elements[] = new DateElement($value);
}
}
return $elements;
}

/**
* Get the matching element or null if there is not match.
*
* @access protected
*
* @param string $xpath The XPath for metadata search
*
* @return ?LanguageElement
*/
protected function getLanguageElement(string $xpath): ?LanguageElement
{
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}
return null;
}

/**
* Get the array of the matching elements.
*
* @access protected
*
* @param string $xpath The XPath for metadata search
*
* @return LanguageElement[]
*/
protected function getLanguageElements(string $xpath): array
{
$elements = [];
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$elements[] = new LanguageElement($value);
}
}
return $elements;
}
}
Loading

0 comments on commit 951b2ec

Please sign in to comment.