Skip to content

Commit

Permalink
[FINNA-1243] Add method to SolrMarc.php instead of SolrFinnaTrait.php
Browse files Browse the repository at this point in the history
  • Loading branch information
tmikkonen committed Apr 9, 2024
1 parent 34e282e commit 48526f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
27 changes: 1 addition & 26 deletions module/Finna/src/Finna/RecordDriver/Feature/SolrFinnaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace Finna\RecordDriver\Feature;

use Vufind\RecordDriver\Feature\MarcReaderTrait;
use VuFind\RecordDriver\Feature\VersionAwareInterface;
use VuFindSearch\Command\RetrieveCommand;
use VuFindSearch\Command\SearchCommand;
Expand Down Expand Up @@ -579,31 +578,7 @@ public function getOrganisationInfoId()
*/
public function getOriginalLanguages()
{
$languages = array_unique(array_filter(array_merge(
// 041h - language code of original
$this->getFieldArray('041', ['h'], false, true, true),
// 979i - component part original language
$this->getFieldArray('979', ['i'], false, true, true)
)));
if (!empty($languages)) {
foreach ($this->getMarcReader()->getFields('041') as $field) {
if ($field['i1'] != 0) {
$sortingArr = [];
foreach ($this->getLanguages() as $lang) {
$sortingArr[] = $lang;
}
uasort($languages, function ($a, $b) use ($sortingArr) {
return array_search($a, $sortingArr) <=> array_search($b, $sortingArr);
});
}
}
} else {
$result = [];
}
if (!isset($result)) {
$result = $languages;
}
return $result;
return $this->fields['original_lng_str_mv'] ?? [];
}

/**
Expand Down
34 changes: 34 additions & 0 deletions module/Finna/src/Finna/RecordDriver/SolrMarc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2541,4 +2541,38 @@ public function getAbstractLanguage()
{
return $this->stripTrailingPunctuation($this->getFieldArray('041', ['b']));
}

/**
* Get original languages from fields 041, subfield h and 979, subfield i
*
* @return array
*/
public function getOriginalLanguages()
{
$languages = array_unique(array_filter(array_merge(
// 041h - language code of original
$this->getFieldArray('041', ['h'], false, true, true),

Check failure on line 2554 in module/Finna/src/Finna/RecordDriver/SolrMarc.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method VuFind\RecordDriver\SolrMarc::getFieldArray() invoked with 5 parameters, 1-4 required.

Check failure on line 2554 in module/Finna/src/Finna/RecordDriver/SolrMarc.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method VuFind\RecordDriver\SolrMarc::getFieldArray() invoked with 5 parameters, 1-4 required.
// 979i - component part original language
$this->getFieldArray('979', ['i'], false, true, true)

Check failure on line 2556 in module/Finna/src/Finna/RecordDriver/SolrMarc.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method VuFind\RecordDriver\SolrMarc::getFieldArray() invoked with 5 parameters, 1-4 required.

Check failure on line 2556 in module/Finna/src/Finna/RecordDriver/SolrMarc.php

View workflow job for this annotation

GitHub Actions / Tests with PHP 8.3

Method VuFind\RecordDriver\SolrMarc::getFieldArray() invoked with 5 parameters, 1-4 required.
)));
if (!empty($languages)) {
foreach ($this->getMarcReader()->getFields('041') as $field) {
if ($field['i1'] != 0) {
$sortingArr = [];
foreach ($this->getLanguages() as $lang) {
$sortingArr[] = $lang;
}
uasort($languages, function ($a, $b) use ($sortingArr) {
return array_search($a, $sortingArr) <=> array_search($b, $sortingArr);
});
}
}
} else {
$result = [];
}
if (!isset($result)) {
$result = $languages;
}
return $result;
}
}

0 comments on commit 48526f9

Please sign in to comment.