Skip to content

Commit

Permalink
Merge pull request #17 from beatrycze-volk/implement-pd
Browse files Browse the repository at this point in the history
Implement `PhysicalDescription` element and its chilren
  • Loading branch information
beatrycze-volk authored Apr 30, 2024
2 parents 4bfd5ce + 8397c1a commit a2335db
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 104 deletions.
4 changes: 3 additions & 1 deletion src/Mods/Element/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/**
* Note MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/note.html
*
* @access public
*/
Expand All @@ -43,7 +44,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/note.html
*
* @access public
*
Expand Down
150 changes: 83 additions & 67 deletions src/Mods/Element/PhysicalDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,18 @@
use Slub\Mods\Element\Note;
use Slub\Mods\Element\Specific\PhysicalDescription\Extent;
use Slub\Mods\Element\Specific\PhysicalDescription\Form;
use Slub\Mods\Element\Xml\Element;

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

/**
* @access private
* @var Form
*/
private Form $form;

/**
* @access private
* @var string
*/
private string $reformattingQuality;

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

/**
* @access private
* @var Extent
*/
private Extent $extent;

/**
* @access private
* @var string
*/
private string $digitalOrigin;

/**
* @access private
* @var Note
*/
private Note $note;

/**
* This extracts the essential MODS metadata from XML
*
Expand All @@ -80,84 +46,134 @@ class PhysicalDescription extends BaseElement
public function __construct(\SimpleXMLElement $xml)
{
parent::__construct($xml);

$this->form = new Form($xml);
$this->reformattingQuality = '';
$this->internetMediaType = new LanguageElement($xml);
$this->extent = new Extent($xml);
$this->digitalOrigin = '';
$this->note = new Note($xml);
}

/**
* Get the value of form
* Get the array of the <form> elements.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#form
*
* @access public
*
* @return Form
* @param string $query The XPath query for metadata search
*
* @return Form[]
*/
public function getForm(): Form
public function getForms(string $query = ''): array
{
return $this->form;
$forms = [];
$xpath = './mods:form' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$forms[] = new Form($value);
}
}
return $forms;
}

/**
* Get the value of reformattingQuality
* Get the array of the <reformattingQuality> elements.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#reformattingquality
*
* @access public
*
* @return string
* @param string $query The XPath query for metadata search
*
* @return string[]
*/
public function getReformattingQuality(): string
public function getReformattingQualities(string $query = ''): array
{
return $this->reformattingQuality;
$reformattingQualities = [];
$xpath = './mods:reformattingQuality' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$reformattingQualities[] = $value;
}
}
return $reformattingQualities;
}

/**
* Get the value of internetMediaType
* Get the array of the <internetMediaType> elements.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#internetmediatype
*
* @access public
*
* @return LanguageElement
* @param string $query The XPath query for metadata search
*
* @return LanguageElement[]
*/
public function getInternetMediaType(): LanguageElement
public function getInternetMediaTypes(string $query = ''): array
{
return $this->internetMediaType;
return $this->getLanguageElements('./mods:internetMediaType' . $query);
}

/**
* Get the value of extent
* Get the array of the <extent> elements.
*
* @access public
*
* @return Extent
* @param string $query The XPath query for metadata search
*
* @return Extent[]
*/
public function getExtent(): Extent
public function getExtents(string $query = ''): array
{
return $this->extent;
$forms = [];
$xpath = './mods:extent' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$forms[] = new Extent($value);
}
}
return $forms;
}

/**
* Get the value of digitalOrigin
* Get the array of the <digitalOrigin> elements.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#digitalorigin
*
* @access public
*
* @return string
* @param string $query The XPath query for metadata search
*
* @return string[]
*/
public function getDigitalOrigin(): string
public function getDigitalOrigins(string $query = ''): array
{
return $this->digitalOrigin;
$digitalOrigins = [];
$xpath = './mods:digitalOrigin' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$digitalOrigins[] = $value;
}
}
return $digitalOrigins;
}

/**
* Get the value of note
* Get the array of the <note> elements.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#note
*
* @access public
*
* @return Note
* @param string $query The XPath query for metadata search
*
* @return Note[]
*/
public function getNote(): Note
public function getNotes(string $query = ''): array
{
return $this->note;
$notes = [];
$xpath = './mods:note' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
$notes[] = new Note($value);
}
}
return $notes;
}
}
13 changes: 5 additions & 8 deletions src/Mods/Element/Specific/PhysicalDescription/Extent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

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

if (!empty($value)) {
return $value;
}
return '';
return $this->getStringAttribute('unit');
}
}
}
13 changes: 5 additions & 8 deletions src/Mods/Element/Specific/PhysicalDescription/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* Form MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/physicaldescription.html#note
*
* @access public
*/
Expand All @@ -40,19 +41,15 @@ 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/physicaldescription.html#type
*
* @access public
*
* @return string
*/
public function getType(): string
{
$value = $this->xml->attributes()->type;

if (!empty($value)) {
return $value;
}
return '';
return $this->getStringAttribute('type');
}
}
}
60 changes: 40 additions & 20 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,16 @@ public function testGetPhysicalDescriptionsForBookDocument()
self::assertNotEmpty($physicalDescriptions);
self::assertEquals(1, count($physicalDescriptions));
self::assertNotEmpty($physicalDescriptions[0]->getValue());
//self::assertEquals('', $physicalDescriptions[0]->getValue());
//self::assertNotEmpty($physicalDescriptions[0]->getForm());
//self::assertNotEmpty($physicalDescriptions[0]->getExtent());

// TODO: implement reading of elements
self::assertNotEmpty($physicalDescriptions[0]->getForms());
self::assertEquals('marcform', $physicalDescriptions[0]->getForms()[0]->getAuthority());
self::assertEquals('print', $physicalDescriptions[0]->getForms()[0]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getExtents());
self::assertEquals('vii, 322 p. ; 23 cm.', $physicalDescriptions[0]->getExtents()[0]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getReformattingQualities());
self::assertEquals('replacement', $physicalDescriptions[0]->getReformattingQualities()[0]);
self::assertNotEmpty($physicalDescriptions[0]->getDigitalOrigins());
self::assertEquals('born digital', $physicalDescriptions[0]->getDigitalOrigins()[0]);
self::assertEmpty($physicalDescriptions[0]->getNotes());
}

public function testGetPhysicalDescriptionsByQueryForBookDocument()
Expand All @@ -861,11 +866,16 @@ public function testGetPhysicalDescriptionsByQueryForBookDocument()
self::assertNotEmpty($physicalDescriptions);
self::assertEquals(1, count($physicalDescriptions));
self::assertNotEmpty($physicalDescriptions[0]->getValue());
//self::assertEquals('', $physicalDescriptions[0]->getValue());
//self::assertNotEmpty($physicalDescriptions[0]->getForm());
//self::assertNotEmpty($physicalDescriptions[0]->getExtent());

// TODO: implement reading of elements
self::assertNotEmpty($physicalDescriptions[0]->getForms());
self::assertEquals('marcform', $physicalDescriptions[0]->getForms()[0]->getAuthority());
self::assertEquals('print', $physicalDescriptions[0]->getForms()[0]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getExtents());
self::assertEquals('vii, 322 p. ; 23 cm.', $physicalDescriptions[0]->getExtents()[0]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getReformattingQualities());
self::assertEquals('replacement', $physicalDescriptions[0]->getReformattingQualities()[0]);
self::assertNotEmpty($physicalDescriptions[0]->getDigitalOrigins());
self::assertEquals('born digital', $physicalDescriptions[0]->getDigitalOrigins()[0]);
self::assertEmpty($physicalDescriptions[0]->getNotes());
}

public function testGetNoPhysicalDescriptionsByQueryForBookDocument()
Expand All @@ -880,11 +890,16 @@ public function testGetPhysicalDescriptionsForSerialDocument()
self::assertNotEmpty($physicalDescriptions);
self::assertEquals(1, count($physicalDescriptions));
self::assertNotEmpty($physicalDescriptions[0]->getValue());
//self::assertEquals('', $physicalDescriptions[0]->getValue());
//self::assertNotEmpty($physicalDescriptions[0]->getForm());
//self::assertNotEmpty($physicalDescriptions[0]->getExtent());

// TODO: implement reading of elements
self::assertNotEmpty($physicalDescriptions[0]->getForms());
self::assertEquals(2, count($physicalDescriptions[0]->getForms()));
self::assertEquals('gmd', $physicalDescriptions[0]->getForms()[1]->getAuthority());
self::assertEquals('electronic resource', $physicalDescriptions[0]->getForms()[1]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getInternetMediaTypes());
self::assertEquals('text/html', $physicalDescriptions[0]->getInternetMediaTypes()[0]->getValue());
self::assertEmpty($physicalDescriptions[0]->getExtents());
self::assertEmpty($physicalDescriptions[0]->getReformattingQualities());
self::assertEmpty($physicalDescriptions[0]->getDigitalOrigins());
self::assertEmpty($physicalDescriptions[0]->getNotes());
}

public function testGetPhysicalDescriptionsByQueryForSerialDocument()
Expand All @@ -893,11 +908,16 @@ public function testGetPhysicalDescriptionsByQueryForSerialDocument()
self::assertNotEmpty($physicalDescriptions);
self::assertEquals(1, count($physicalDescriptions));
self::assertNotEmpty($physicalDescriptions[0]->getValue());
//self::assertEquals('', $physicalDescriptions[0]->getValue());
//self::assertNotEmpty($physicalDescriptions[0]->getForm());
//self::assertNotEmpty($physicalDescriptions[0]->getExtent());

// TODO: implement reading of elements
self::assertNotEmpty($physicalDescriptions[0]->getForms());
self::assertEquals(2, count($physicalDescriptions[0]->getForms()));
self::assertEquals('gmd', $physicalDescriptions[0]->getForms()[1]->getAuthority());
self::assertEquals('electronic resource', $physicalDescriptions[0]->getForms()[1]->getValue());
self::assertNotEmpty($physicalDescriptions[0]->getInternetMediaTypes());
self::assertEquals('text/html', $physicalDescriptions[0]->getInternetMediaTypes()[0]->getValue());
self::assertEmpty($physicalDescriptions[0]->getExtents());
self::assertEmpty($physicalDescriptions[0]->getReformattingQualities());
self::assertEmpty($physicalDescriptions[0]->getDigitalOrigins());
self::assertEmpty($physicalDescriptions[0]->getNotes());
}

public function testGetNoPhysicalDescriptionsByQueryForSerialDocument()
Expand Down

0 comments on commit a2335db

Please sign in to comment.