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 Name class and its child element classes #6

Merged
merged 2 commits into from
Apr 10, 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
251 changes: 23 additions & 228 deletions src/Mods/Element/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,83 +20,21 @@
use Slub\Mods\Attribute\Common\Linking\XlinkHrefAttribute;
use Slub\Mods\Attribute\Common\Miscellaneous\DisplayLabelAttribute;
use Slub\Mods\Attribute\Common\Miscellaneous\UsageAttribute;
use Slub\Mods\Element\Common\AuthorityLanguageElement;
use Slub\Mods\Element\Common\BaseElement;
use Slub\Mods\Element\Common\LanguageElement;
use Slub\Mods\Element\Specific\Name\AlternativeName;
use Slub\Mods\Element\Specific\Name\NameIdentifier;
use Slub\Mods\Element\Specific\Name\NamePart;
use Slub\Mods\Element\Specific\Name\Role;
use Slub\Mods\Element\Specific\Name\BaseNameElement;
use Slub\Mods\Element\Xml\Element;

/**
* Name MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/name.html
*
* @access public
*/
class Name extends BaseElement
class Name extends BaseNameElement
{
use AuthorityAttribute, LanguageAttribute, IdAttribute, XlinkHrefAttribute, AltRepGroupAttribute, NameTitleGroupAttribute, UsageAttribute, DisplayLabelAttribute;

/**
* @access private
* @var array
*/
private array $allowedTypes = [
'personal',
'corporate',
'conference',
'family'
];

/**
* @access private
* @var array
*/
private array $nameParts = [];

/**
* @access private
* @var array
*/
private array $alternativeNames = [];

/**
* @access private
* @var array
*/
private array $nameIdentifiers = [];

/**
* @access private
* @var array
*/
private array $displayForms = [];

/**
* @access private
* @var array
*/
private array $affiliations = [];

/**
* @access private
* @var array
*/
private array $roles = [];

/**
* @access private
* @var array
*/
private array $descriptions = [];

/**
* @access private
* @var LanguageElement
*/
private LanguageElement $etal;

/**
* This extracts the essential MODS metadata from XML
*
Expand All @@ -112,7 +50,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/name.html#type
*
* @access public
*
Expand All @@ -124,32 +63,8 @@ public function getType(): string
}

/**
* Get the value of namePart
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return NamePart[]
*/
public function getNameParts(string $query = ''): array
{
if (empty($this->nameParts)) {
$xpath = './mods:namePart' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->nameParts[] = new NamePart($value);
}
}
}

return $this->nameParts;
}

/**
* Get the value of alternativeName
* Get the the array of the <alternativeName> elements.
* @see https://www.loc.gov/standards/mods/userguide/name.html#alternativename
*
* @access public
*
Expand All @@ -159,154 +74,34 @@ public function getNameParts(string $query = ''): array
*/
public function getAlternativeNames(string $query = ''): array
{
if (empty($this->alternativeNames)) {
$xpath = './mods:alternativeName' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->alternativeNames[] = new AlternativeName($value);
}
}
}

return $this->alternativeNames;
}

/**
* Get the value of nameIdentifier
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return NameIdentifier
*/
public function getNameIdentifier(string $query): array
{
if (empty($this->nameIdentifiers)) {
$xpath = './mods:nameIdentifier' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->nameIdentifiers[] = new NameIdentifier($value);
}
}
}

return $this->nameIdentifiers;
}

/**
* Get the value of displayForm
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return LanguageElement[]
*/
public function getDisplayForms(string $query = ''): array
{
if (empty($this->displayForms)) {
$xpath = './mods:displayForm' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->displayForms[] = new LanguageElement($value);
}
$alternativeNames = [];
$xpath = './mods:alternativeName' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$alternativeNames[] = new AlternativeName($value);
}
}

return $this->displayForms;
return $alternativeNames;
}

/**
* Get the value of affiliation
* Get the value of the <etal> element.
* @see https://www.loc.gov/standards/mods/userguide/name.html#etal
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return AuthorityLanguageElement[]
* @return ?LanguageElement
*/
public function getAffiliations(string $query = ''): array
public function getEtal(string $query = ''): ?LanguageElement
{
if (empty($this->affiliations)) {
$xpath = './mods:affiliation' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->affiliations[] = new AuthorityLanguageElement($value);
}
}
$xpath = './mods:etal' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageElement($element->getValues()[0]);
}

return $this->affiliations;
}

/**
* Get the array of roles
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return Role[]
*/
public function getRoles(string $query = ''): array
{
if (empty($this->roles)) {
$xpath = './mods:role' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->roles[] = new AuthorityLanguageElement($value);
}
}
}

return $this->roles;
}

/**
* Get the value of description
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return LanguageElement[]
*/
public function getDescriptions(string $query = ''): array
{
if (empty($this->descriptions)) {
$xpath = './mods:description' . $query;
$element = new Element($this->xml, $xpath);

if ($element->exists()) {
foreach ($element->getValues() as $value) {
$this->descriptions[] = new LanguageElement($value);
}
}
}

return $this->descriptions;
}

/**
* Get the value of etal
*
* @access public
*
* @return LanguageElement
*/
public function getEtal(): LanguageElement
{
return $this->etal;
return null;
}
}
Loading
Loading