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

Improved RIS export #3954

Merged
merged 19 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
19 changes: 18 additions & 1 deletion module/VuFind/src/VuFind/RecordDriver/DefaultRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ public function getAllSubjectHeadings($extended = false)
return array_map($callback, array_unique($headings));
}

/**
* Get the subject headings as a flat array of strings.
*
* @return array Subject headings
*/
public function getAllSubjectHeadingsFlattened()
{
$headings = [];
$subjects = $this->getAllSubjectHeadings();
if (is_array($subjects)) {
foreach ($subjects as $subj) {
$headings[] = implode(' -- ', $subj);
}
}
return $headings;
}

/**
* Get all record links related to the current record. Each link is returned as
* array.
Expand Down Expand Up @@ -243,7 +260,7 @@ public function getCallNumber()
*/
public function getCallNumbers()
{
return (array)($this->fields['callnumber-raw'] ?? []);
return array_unique((array)($this->fields['callnumber-raw'] ?? []));
}

/**
Expand Down
12 changes: 12 additions & 0 deletions module/VuFind/src/VuFind/RecordDriver/EDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ public function getItemsAbstract()
return $abstract[0]['Data'] ?? '';
}

/**
* Get the abstract and summary notes.
damien-git marked this conversation as resolved.
Show resolved Hide resolved
* For EDS, returns the abstract in an array or an empty array.
*
* @return array
*/
public function getAbstractAndSummaryNotes()
{
$abstract = $this->getItems(null, null, 'Ab');
return (array)($abstract[0]['Data'] ?? []);
}

/**
* Get the access level of the record.
*
Expand Down
68 changes: 68 additions & 0 deletions module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

namespace VuFind\RecordDriver;

use function array_key_exists;
use function in_array;

/**
* Model for MARC records in Solr.
*
Expand Down Expand Up @@ -72,4 +75,69 @@ public function getURLs()
$this->getIlsURLs()
);
}

/**
damien-git marked this conversation as resolved.
Show resolved Hide resolved
* Takes a Marc field that notes are stored in (ex: 950) and a list of
* sub fields (ex: ['a','b']) optionally as well as what indicator
* numbers and values to filter for and concatenates the subfields
* together and returns the fields back as an array
* (ex: ['subA subB subC', 'field2SubA field2SubB'])
*
* @param string $field Marc field to search within
* @param array $subfield Sub-fields to return or empty for all
damien-git marked this conversation as resolved.
Show resolved Hide resolved
* @param array $indData Array containing the indicator number as the key
* and the value as an array of strings for the
damien-git marked this conversation as resolved.
Show resolved Hide resolved
* allowed indicator values
* ex: [['1' => '1', '2', '2' => '']]
damien-git marked this conversation as resolved.
Show resolved Hide resolved
* would filter ind1 = 1 or 2 and ind2 = blank
*
* @return array The values within the subfields under the field
*/
public function getMarcFieldWithInd(
string $field,
?array $subfield = null,
array $indData = []
) {
$vals = [];
$marc = $this->getMarcReader();
$marc_fields = $marc->getFields($field, $subfield);
foreach ($marc_fields as $marc_data) {
$field_vals = [];
// Check if that field has either indicator (MARC only has up to 2 indicators)
foreach (range(1, 2) as $indNum) {
damien-git marked this conversation as resolved.
Show resolved Hide resolved
if (array_key_exists($indNum, $indData)) {
if (in_array(trim(($marc_data['i' . $indNum] ?? '')), $indData[$indNum])) {
$subfields = $marc_data['subfields'];
foreach ($subfields as $subfield) {
$field_vals[] = $subfield['data'];
}
}
}
}
if (!empty($field_vals)) {
$vals[] = implode(' ', $field_vals);
}
}
return array_unique($vals);
}

/**
* Get the abstract and summary notes
*
* @return array Note fields from the MARC record
*/
public function getAbstractAndSummaryNotes()
{
return $this->getMarcFieldWithInd('520', null, [1 => ['', '0', '2', '3', '8']]);
damien-git marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Get the location of other archival materials notes
*
* @return array Note fields from the MARC record
*/
public function getLocationOfArchivalMaterialsNotes()
{
return $this->getMarcFieldWithInd('544', null, [1 => ['', '0']]);
damien-git marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 3 additions & 0 deletions module/VuFind/tests/fixtures/marc/marctraits.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<datafield tag="538" ind1=" " ind2=" ">
<subfield code="a">Data in UTF-8</subfield>
</datafield>
<datafield tag="544" ind1=" " ind2=" ">
<subfield code="a">Location of archival materials</subfield>
</datafield>
<datafield tag="555" ind1="0" ind2=" ">
<subfield code="a">Finding aid available</subfield>
</datafield>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,168 @@ public function testBug2(): void
$this->assertEquals('2, pt. 1.', $series[0]['number']);
}

/**
* Test getMarcFieldWithInd when a single indicator value is sent
*
* @return void
*/
public function testGetMarcFieldWithIndOneValue(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getMarcFieldWithInd');
$getFieldArray->setAccessible(true);

// Test getting 024 fields where the 1st indicator value is 1
$this->assertEquals(
['upc'],
$getFieldArray->invokeArgs($obj, ['024', null, ['1' => ['1']]])
);
}

/**
* Test getMarcFieldWithInd when multiple values for the indicator are sent
*
* @return void
*/
public function testGetMarcFieldWithIndTwoValues(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getMarcFieldWithInd');
$getFieldArray->setAccessible(true);

// Test getting 024 fields where the 1st indicator value is 1 or 2
$this->assertEquals(
['upc', 'ismn'],
$getFieldArray->invokeArgs($obj, ['024', null, ['1' => ['1', '2']]])
);
}

/**
* Test getMarcFieldWithInd when multiple indicators are requested
*
* @return void
*/
public function testGetMarcFieldWithIndMultInds(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getMarcFieldWithInd');
$getFieldArray->setAccessible(true);

// Test getting 024 fields where the 1st indicator value is 1 or 2
$this->assertEquals(
['ger', 'spa'],
$getFieldArray->invokeArgs($obj, ['041', null, ['1' => ['0'], '2' => ['7']]])
);
}

/**
* Test getMarcFieldWithInd when no indicator filters are sent
*
* @return void
*/
public function testGetMarcFieldWithIndNoValues(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getMarcFieldWithInd');
$getFieldArray->setAccessible(true);

// Test when no indicator is passed
$this->assertEquals(
[],
$getFieldArray->invokeArgs($obj, ['024', null, []])
);
}

/**
* Test calling getAbstractAndSummaryNotes to get expected marc data
*
* @return void
*/
public function testGetAbstractAndSummaryNotes(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getAbstractAndSummaryNotes');
$getFieldArray->setAccessible(true);

// Test when no indicator is passed
$this->assertEquals(
['Summary. Expanded.'],
$getFieldArray->invokeArgs($obj, [])
);
}

/**
* Test calling getLocationOfArchivalMaterialsNotes to get expected marc data
*
* @return void
*/
public function testGetLocationOfArchivalMaterialsNotes(): void
{
$xml = $this->getFixture('marc/marctraits.xml');
$record = new \VuFind\Marc\MarcReader($xml);
$obj = $this->getMockBuilder(\VuFind\RecordDriver\SolrMarc::class)
->onlyMethods(['getMarcReader'])->getMock();
$obj->expects($this->any())
->method('getMarcReader')
->willReturn($record);

$reflection = new \ReflectionObject($obj);

$getFieldArray = $reflection->getMethod('getLocationOfArchivalMaterialsNotes');
$getFieldArray->setAccessible(true);

// Test when no indicator is passed
$this->assertEquals(
['Location of archival materials'],
$getFieldArray->invokeArgs($obj, [])
);
}

/**
* Test regular and extended subject heading support.
*
Expand Down
49 changes: 47 additions & 2 deletions themes/root/templates/RecordDriver/AbstractBase/export-ris.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ if (!empty($title)) {
echo 'TI - ' . "$title\r\n";
}

$shortTitle = $this->driver->getShortTitle();
if (!empty($shortTitle)) {
$shortTitle = rtrim(rtrim($shortTitle, ' /'), ' :');
echo 'ST - ' . "$shortTitle\r\n";
}

if (!empty($journalTitle)) {
if (empty($title)) {
echo 'TI - ' . "$journalTitle\r\n";
Expand Down Expand Up @@ -111,11 +117,20 @@ if (is_array($genres)) {
}
}

$topics = $this->driver->tryMethod('getTopics');
$topics = $this->driver->tryMethod('getAllSubjectHeadingsFlattened');
if (is_array($topics)) {
foreach ($topics as $topic) {
echo 'KW - ' . "$topic\r\n";
}
} else {
// For EDS
$topics = $this->driver->tryMethod('getItemsSubjects');
damien-git marked this conversation as resolved.
Show resolved Hide resolved
if (is_string($topics)) {
$topics = strip_tags($topics);
foreach (explode(', ', $topics) as $topic) {
echo 'KW - ' . "$topic\r\n";
}
}
}

$start_page = $this->driver->tryMethod('getContainerStartPage');
Expand Down Expand Up @@ -149,12 +164,42 @@ if (is_array($notes)) {
}
}

echo 'L4 - ' . $this->serverUrl($this->recordLinker()->getUrl($this->driver)) . "\r\n";

foreach ($this->record($this->driver)->getUrlList() as $url) {
echo 'UR - ' . "$url\r\n";
}

if ($doi = $this->driver->tryMethod('getCleanDOI')) {
echo "DO - $doi\r\n";
echo 'DO - ' . strip_tags($doi) . "\r\n";
damien-git marked this conversation as resolved.
Show resolved Hide resolved
}

$abstract = $this->driver->tryMethod('getAbstractAndSummaryNotes');
if (is_array($abstract)) {
foreach ($abstract as $note) {
echo 'AB - ' . "$note\r\n";
}
}

$notes = $this->driver->tryMethod('getLocationOfArchivalMaterialsNotes');
if (is_array($notes)) {
foreach ($notes as $note) {
echo 'AV - ' . "$note\r\n";
}
}

$call_numbers = $this->driver->tryMethod('getCallNumbers');
if (is_array($call_numbers)) {
foreach ($call_numbers as $call_number) {
echo 'CN - ' . "$call_number\r\n";
}
}

$results = $this->driver->tryMethod('getFullTitlesAltScript');
if (is_array($results)) {
foreach ($results as $result) {
echo 'J2 - ' . "$result\r\n";
}
}

// End of Record:
Expand Down
Loading