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 Location class and its child element classes #4

Merged
merged 16 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
27 changes: 27 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHPUnit

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: php-actions/composer@v6

- name: Tests
uses: php-actions/phpunit@v3
env:
TEST_NAME: Scarlett
with:
bootstrap: vendor/autoload.php
configuration: phpunit.xml
args: --coverage-text
version: 9
php_version: "7.4"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "~7.5"
"phpunit/phpunit": "~9.6"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<testsuites>
<testsuite name="MODS Reader Test Suite">
<directory>./tests/Mods/</directory>
<directory>./tests/Mods/Context</directory>
</testsuite>
</testsuites>
<filter>
Expand Down
2 changes: 1 addition & 1 deletion src/Mods/Attribute/Common/Linking/XlinkHrefAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ trait XlinkHrefAttribute
*/
public function getXlinkHref(): string
{
return $this->getStringAttribute('xlinkHref');
return $this->getStringAttribute('xlink:href');
}
}
116 changes: 67 additions & 49 deletions src/Mods/Element/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,18 @@
use Slub\Mods\Element\Specific\Location\HoldingSimple;
use Slub\Mods\Element\Specific\Location\PhysicalLocation;
use Slub\Mods\Element\Specific\Location\Url;
use Slub\Mods\Element\Xml\Element;

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

/**
* @access private
* @var PhysicalLocation
*/
private PhysicalLocation $physicalLocation;

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

/**
* @access private
* @var Url
*/
private Url $url;

/**
* @access private
* @var HoldingSimple
*/
private HoldingSimple $holdingSimple;

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

/**
* This extracts the essential MODS metadata from XML
*
Expand All @@ -76,62 +48,108 @@ public function __construct(\SimpleXMLElement $xml)
}

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

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

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

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

/**
* Get the value of holdingExternal
* Get the value of the <holdingExternal> element.
* @see https://www.loc.gov/standards/mods/userguide/location.html#holdingexternal
*
* @access public
*
* @param string $query The XPath query for metadata search
*
* @return string
*/
public function getHoldingExternal(): string
public function getHoldingExternal(string $query = ''): string
{
return $this->holdingExternal;
$xpath = './mods:holdingExternal' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
return $element->getValues()[0]->asXML();
}
return '';
}
}
24 changes: 14 additions & 10 deletions src/Mods/Element/Specific/Location/HoldingSimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@

use Slub\Mods\Element\Common\BaseElement;
use Slub\Mods\Element\Specific\Location\HoldingSimple\CopyInformation;
use Slub\Mods\Element\Xml\Element;

/**
* HoldingSimple MODS metadata element class for the 'php-mods-reader' library.
* @see https://www.loc.gov/standards/mods/userguide/location.html#holdingsimple
*
* @access public
*/
class HoldingSimple extends BaseElement
{

/**
* @access private
* @var CopyInformation
*/
private CopyInformation $copyInformation;

/**
* This extracts the essential MODS metadata from XML
*
Expand All @@ -44,14 +40,22 @@ public function __construct(\SimpleXMLElement $xml)
}

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