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 74fbffc commit 1cc21f8
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 314 deletions.
89 changes: 86 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 @@ -55,7 +57,7 @@ public function getValue(): string
/**
* Get the string value of attribute.
*
* @access public
* @access protected
*
* @param string $attribute name
*
Expand All @@ -76,7 +78,7 @@ protected function getStringAttribute($attribute): string
/**
* Get the int value of attribute.
*
* @access public
* @access protected
*
* @param string $attribute name
*
Expand All @@ -93,4 +95,85 @@ protected function getIntAttribute($attribute): int
}
return 0;
}
}

/**
* Get the array of the matching elements.
*
* @access protected
*
* @param string $xpath The XPath for metadata search
*
* @return AuthorityLanguageElement[]
*/
protected 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 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 1cc21f8

Please sign in to comment.