Skip to content

Commit

Permalink
Merge pull request #9 from beatrycze-volk/implement-record-info
Browse files Browse the repository at this point in the history
Implement functions in RecordInfo class and its child element classes
  • Loading branch information
beatrycze-volk authored Apr 12, 2024
2 parents 87ae6eb + a283dbe commit 74fbffc
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 85 deletions.
208 changes: 181 additions & 27 deletions src/Mods/Element/RecordInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
use Slub\Mods\Element\Specific\RecordInfo\LanguageOfCataloging;
use Slub\Mods\Element\Specific\RecordInfo\RecordIdentifier;
use Slub\Mods\Element\Specific\RecordInfo\RecordInfoNote;
use Slub\Mods\Element\Xml\Element;

/**
* RecordInfo MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html
*
* @access public
*/
Expand All @@ -38,61 +40,213 @@ class RecordInfo extends BaseElement
* @access private
* @var AuthorityLanguageElement
*/
private AuthorityLanguageElement $recordContentSource;
private AuthorityLanguageElement $descriptionStandard;

Check failure on line 43 in src/Mods/Element/RecordInfo.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Slub\Mods\Element\RecordInfo::$descriptionStandard is unused.

/**
* @access private
* @var DateElement
* This extracts the essential MODS metadata from XML
*
* @access public
*
* @param \SimpleXMLElement $xml The XML to extract the metadata from
*
* @return void
*/
private DateElement $recordCreationDate;
public function __construct(\SimpleXMLElement $xml)
{
parent::__construct($xml);
}

/**
* @access private
* @var DateElement
* Get the array of the <recordContentSource> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordcontentsource
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return AuthorityLanguageElement[]
*/
private DateElement $recordChangeDate;
public function getRecordContentSources(string $query = ''): array
{
return $this->getAuthorityLanguageElements('./mods:recordContentSource' . $query);
}

/**
* @access private
* @var RecordIdentifier
* Get the array of the <recordCreationDate> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordcreationdate
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return DateElement[]
*/
private RecordIdentifier $recordIdentifier;
public function getRecordCreationDates(string $query = ''): array
{
return $this->getDateElements('./mods:recordCreationDate' . $query);
}

/**
* @access private
* @var LanguageElement
* Get the array of the <recordChangeDate> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordchangedate
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return DateElement[]
*/
private LanguageElement $recordOrigin;
public function getRecordChangeDates(string $query = ''): array
{
return $this->getDateElements('./mods:recordChangeDate' . $query);
}

/**
* @access private
* @var RecordInfoNote
* Get the array of the <recordIdentifier> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return RecordIdentifier[]
*/
private RecordInfoNote $recordInfoNote;
public function getRecordIdentifiers(string $query = ''): array
{
$recordIdentifiers = [];
$xpath = './mods:recordIdentifier' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordIdentifiers[] = new RecordIdentifier($value);
}
}
return $recordIdentifiers;
}

/**
* @access private
* @var LanguageOfCataloging
* Get the array of the <recordOrigin> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordorigin
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return LanguageElement[]
*/
private LanguageOfCataloging $languageOfCataloging;
public function getRecordOrigins(string $query = ''): array
{
$recordOrigins = [];
$xpath = './mods:recordOrigin' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordOrigins[] = new LanguageElement($value);
}
}
return $recordOrigins;
}

/**
* @access private
* @var AuthorityLanguageElement
* Get the array of the <recordIdentifier> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return RecordIdentifier[]
*/
private AuthorityLanguageElement $descriptionStandard;
public function getRecordInfoNotes(string $query = ''): array
{
$recordInfoNotes = [];
$xpath = './mods:recordInfoNote' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$recordInfoNotes[] = new RecordInfoNote($value);
}
}
return $recordInfoNotes;

Check failure on line 170 in src/Mods/Element/RecordInfo.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Slub\Mods\Element\RecordInfo::getRecordInfoNotes() should return array<Slub\Mods\Element\Specific\RecordInfo\RecordIdentifier> but returns array<int<0, max>, Slub\Mods\Element\Specific\RecordInfo\RecordInfoNote>.
}

/**
* This extracts the essential MODS metadata from XML
* Get the array of the <languageOfCataloging> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging
*
* @access public
*
* @param \SimpleXMLElement $xml The XML to extract the metadata from
* @param string $query The XPath query for metadata search
*
* @return void
* @return LanguageOfCataloging[]
*/
public function __construct(\SimpleXMLElement $xml)
public function getLanguageOfCatalogings(string $query = ''): array
{
parent::__construct($xml);
$languageOfCatalogings = [];
$xpath = './mods:languageOfCataloging' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$languageOfCatalogings[] = new LanguageOfCataloging($value);
}
}
return $languageOfCatalogings;
}

/**
* Get the array of the <descriptionStandard> elements.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#descriptionstandard
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return AuthorityLanguageElement[]
*/
public function getDescriptionStandards(string $query = ''): array
{
return $this->getAuthorityLanguageElements('./mods:descriptionStandard' . $query);
}

/**
* Get the array of the matching elements.
*
* @access public
*
* @param string $xpath The XPath for metadata search
*
* @return AuthorityLanguageElement[]
*/
private 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 array of the matching elements.
*
* @access public
*
* @param string $xpath The XPath for metadata search
*
* @return DateElement[]
*/
private 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;
}
}
52 changes: 28 additions & 24 deletions src/Mods/Element/Specific/RecordInfo/LanguageOfCataloging.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,18 @@
use Slub\Mods\Element\Common\BaseElement;
use Slub\Mods\Element\Specific\Language\LanguageTerm;
use Slub\Mods\Element\Specific\Language\ScriptTerm;
use Slub\Mods\Element\Xml\Element;

/**
* LanguageOfCataloging MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging
*
* @access public
*/
class LanguageOfCataloging extends BaseElement
{
use IdAttribute, AltRepGroupAttribute, DisplayLabelAttribute, UsageAttribute;

/**
* @access private
* @var LanguageTerm
*/
private LanguageTerm $languageTerm;

/**
* @access private
* @var ScriptTerm
*/
private ScriptTerm $scriptTerm;

/**
* This extracts the essential MODS metadata from XML
*
Expand All @@ -53,13 +43,11 @@ class LanguageOfCataloging extends BaseElement
public function __construct(\SimpleXMLElement $xml)
{
parent::__construct($xml);

$this->languageTerm = new LanguageTerm($xml);
$this->scriptTerm = new ScriptTerm($xml);
}

/**
* Get the value of objectPart
* Get the value of 'objectPart' attribute.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#objectpart
*
* @access public
*
Expand All @@ -71,26 +59,42 @@ public function getObjectPart(): string
}

/**
* Get the value of languageTerm
* Get the value of the <languageTerm> element.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#languageterm
*
* @access public
*
* @return LanguageTerm
* @param string $query The XPath query for metadata search
*
* @return ?LanguageTerm
*/
public function getLanguageTerm(): LanguageTerm
public function getLanguageTerm(string $query = ''): ?LanguageTerm
{
return $this->languageTerm;
$xpath = './mods:languageTerm' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new LanguageTerm($element->getValues()[0]);
}
return null;
}

/**
* Get the value of scriptTerm
* Get the value of the <scriptTerm> element.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#scriptterm
*
* @access public
*
* @return ScriptTerm
* @param string $query The XPath query for metadata search
*
* @return ?ScriptTerm
*/
public function getScriptTerm(): ScriptTerm
public function getScriptTerm(string $query = ''): ?ScriptTerm
{
return $this->scriptTerm;
$xpath = './mods:scriptTerm' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return new ScriptTerm($element->getValues()[0]);
}
return null;
}
}
11 changes: 4 additions & 7 deletions src/Mods/Element/Specific/RecordInfo/RecordIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* RecordIdentifier MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#recordidentifier
*
* @access public
*/
Expand All @@ -39,19 +40,15 @@ public function __construct(\SimpleXMLElement $xml)
}

/**
* Get the value of source
* Get the value of the 'source' attribute.
* @see https://www.loc.gov/standards/mods/userguide/recordinfo.html#source
*
* @access public
*
* @return string
*/
public function getSource(): string
{
$value = $this->xml->attributes()->source;

if (!empty($value)) {
return $value;
}
return '';
return $this->getStringAttribute('source');
}
}
3 changes: 2 additions & 1 deletion src/Mods/Element/Specific/RecordInfo/RecordInfoNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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/recordinfo.html#type
*
* @access public
*
Expand Down
Loading

0 comments on commit 74fbffc

Please sign in to comment.