Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement functions in OriginInfo class and its child element classes #10

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading