Skip to content
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
183 changes: 143 additions & 40 deletions src/RecordManager/Finna/Record/Ead3.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public function toSolrArray(?Database $db = null)
}

$data['author_variant'] = $this->getAuthorVariants();
$data['author2'] = $this->getSecondaryAuthors();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämä rivi on turha niin poistin. Ei liity tähän PR:ään muutoin mitenkään...


$data['author_facet'] = $this->createAuthorFacetArray($data);
$data['author2_id_str_mv']
Expand Down Expand Up @@ -394,6 +393,95 @@ public function getCorporateAuthorIds(): array
return array_values(array_unique($results));
}

/**
* Return record title in English
*
* @return string
*/
protected function getTitleEn(): string
{
return $this->getTitleByLanguage(false, 'en');
}

/**
* Return record title in Finnish
*
* @return string
*/
protected function getTitleFi(): string
{
return $this->getTitleByLanguage(false, 'fi');
}

/**
* Return record title in Northern Sami
*
* @return string
*/
protected function getTitleSe(): string
{
return $this->getTitleByLanguage(false, 'se');
}

/**
* Return record title in Swedish
*
* @return string
*/
protected function getTitleSv(): string
{
return $this->getTitleByLanguage(false, 'sv');
}

/**
* Get alternate titles
*
* @return array
*/
protected function getAltTitles()
{
return array_unique(
array_filter([$this->getTitleFi(), $this->getTitleSv(), $this->getTitleEn(), $this->getTitleSe()])
);
}

/**
* Add hierarchy titles.
*
* @param array $data Reference to the target array
* @param string $sequenceUnitId Id to be added
*
* @return void
*/
protected function addHierarchyTitles(array &$data, string $sequenceUnitId): void
{
// Note: title_in_hierarchy is only needed if it differs from title.
if ($this->getDriverParam('addIdToHierarchyTitle', true)) {
$data['title_in_hierarchy'] = trim("$sequenceUnitId " . $data['title']);
foreach (['fi', 'sv', 'en', 'se'] as $language) {
if ('' !== ($langTitle = $data['title_' . $language . '_txt'] ?? '')) {
$data['title_in_hierarchy_' . $language . '_str'] = trim("$sequenceUnitId $langTitle");
}
}
}
}

/**
* Add additional titles.
*
* @param array $data Reference to the target array
*
* @return void
*/
protected function addAdditionalTitles(array &$data): void
{
// Language specific title fields
$data['title_en_txt'] = $this->getTitleEn();
$data['title_fi_txt'] = $this->getTitleFi();
$data['title_se_txt'] = $this->getTitleSe();
$data['title_sv_txt'] = $this->getTitleSv();
}

/**
* Enrich titles with year ranges.
*
Expand All @@ -420,50 +508,65 @@ protected function enrichTitlesWithYearRanges(
'enrichTitleWithYearRange',
'no_match_exists'
);
if ('never' === $type) {
if ('never' === $type || $unitDateRange['startDateUnknown']) {
return $data;
}
if (!$unitDateRange['startDateUnknown']) {
$range = $unitDateRange['date'];
$startYear
= $this->metadataUtils->extractYear($range[0]);
$endYear = $this->metadataUtils->extractYear($range[1]);
$yearRange[] = $startYear !== '-9999' ? $startYear : '';
$yearRange[] = $endYear !== '9999' ? $endYear : '';
$ndash = html_entity_decode('–', ENT_NOQUOTES, 'UTF-8');
$yearRangeStr = trim(implode($ndash, array_unique($yearRange)));
if (!$yearRangeStr) {
return $data;
}
// Append with LTR mark first to ensure correct text direction
$yearRangeStr = "\u{200E} ($yearRangeStr)";
foreach (
['title_full', 'title_sort', 'title', 'title_short'] as $field
) {
$yearsFound = $this->getYearsFromString($data[$field]);
switch ($type) {
case 'always':
$data[$field] .= $yearRangeStr;
break;
case 'no_year_exists':
if (!$yearsFound) {
$data[$field] .= $yearRangeStr;
}
break;
case 'no_match_exists':
if (!array_intersect($yearRange, $yearsFound)) {
$data[$field] .= $yearRangeStr;
}
break;
case 'no_matches_exist':
$yearRange = array_filter(array_unique($yearRange));
if (array_intersect($yearRange, $yearsFound) !== $yearRange) {
$data[$field] .= $yearRangeStr;
}
break;
$range = $unitDateRange['date'];
$startYear
= $this->metadataUtils->extractYear($range[0]);
$endYear = $this->metadataUtils->extractYear($range[1]);
$yearRange[] = $startYear !== '-9999' ? $startYear : '';
$yearRange[] = $endYear !== '9999' ? $endYear : '';
$ndash = html_entity_decode('–', ENT_NOQUOTES, 'UTF-8');
$yearRangeStr = trim(implode($ndash, array_unique($yearRange)));
if (!$yearRangeStr) {
return $data;
}
// Append with LTR mark first to ensure correct text direction
$yearRangeStr = "\u{200E} ($yearRangeStr)";

$appendYear = function (string $title) use ($type, $yearRangeStr, $yearRange): string {
if ('' === $title) {
return $title;
}
$yearsFound = $this->getYearsFromString($title);
if ($type === 'always') {
return $title .= $yearRangeStr;
} elseif ($type === 'no_year_exists') {
if (!$yearsFound) {
return $title .= $yearRangeStr;
}
} elseif ($type === 'no_match_exists') {
if (!array_intersect($yearRange, $yearsFound)) {
return $title .= $yearRangeStr;
}
} elseif ($type === 'no_matches_exist') {
$yearRange = array_filter(array_unique($yearRange));
if (array_intersect($yearRange, $yearsFound) !== $yearRange) {
return $title .= $yearRangeStr;
}
}
return $title;
};

foreach (
[
'title_full',
'title_sort',
'title',
'title_en_txt',
'title_fi_txt',
'title_se_txt',
'title_sv_txt',
'title_short',
] as $field
) {
$data[$field] = $data[$field] ? $appendYear($data[$field]) : '';
}
$data['title_alt'] = array_map(
$appendYear,
$data['title_alt'] ?? []
);
return $data;
}

Expand Down
92 changes: 91 additions & 1 deletion src/RecordManager/Finna/Record/Lido.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ class Lido extends \RecordManager\Base\Record\Lido
'kiinteistörekisteri' => 'kiinteistötunnus',
];

/**
* Hierarchy fields included in allfields.
*
* @var array
*/
protected $hierarchyFieldsInAllFields = [
'is_hierarchy_title', 'hierarchy_parent_title', 'hierarchy_top_title', 'title_in_hierarchy',
'title_in_hierarchy_en_str_', 'title_in_hierarchy_fi_str', 'title_in_hierarchy_se_str',
'title_in_hierarchy_sv_str',
];

/**
* Constructor
*
Expand Down Expand Up @@ -555,6 +566,46 @@ public function getRelatedISBNs(): array
return array_unique($results);
}

/**
* Return record title in English
*
* @return string
*/
protected function getTitleEn(): string
{
return $this->getTitles('en')['preferred'];
}

/**
* Return record title in Finnish
*
* @return string
*/
protected function getTitleFi(): string
{
return $this->getTitles('fi')['preferred'];
}

/**
* Return record title in Northern Sami
*
* @return string
*/
protected function getTitleSe(): string
{
return $this->getTitles('se')['preferred'];
}

/**
* Return record title in Swedish
*
* @return string
*/
protected function getTitleSv(): string
{
return $this->getTitles('sv')['preferred'];
}

/**
* Get all author ids and roles
*
Expand Down Expand Up @@ -2197,6 +2248,7 @@ protected function getSecondaryAuthors(): array
*/
protected function addHierarchyFields(array &$data): void
{
parent::addHierarchyFields($data);
// Add additional related work titles
if ($furtherTitles = $this->getRelatedWorks($this->relatedWorkRelationTypesExtended)) {
// Check that number of indexed parent titles and ids match
Expand All @@ -2210,9 +2262,47 @@ protected function addHierarchyFields(array &$data): void
...(array)($data['hierarchy_parent_title'] ?? []),
...$furtherTitles,
];
$data['allfields'] = [
...(array)($data['allfields'] ?? []),
...$furtherTitles,
];
}
}

parent::addHierarchyFields($data);
/**
* Add hierarchy titles.
*
* @param array $data Reference to the target array
*
* @return void
*/
protected function addHierarchyTitles(array &$data): void
{
// Note: title_in_hierarchy is only needed if it differs from title.
if ($this->getDriverParam('addIdToHierarchyTitle', true)) {
$data['title_in_hierarchy'] = trim($this->getIdentifier() . ' ' . $data['title']);
foreach (['fi', 'sv', 'en', 'se'] as $language) {
if ('' !== ($langTitle = $data['title_' . $language . '_txt'] ?? '')) {
$data['title_in_hierarchy_' . $language . '_str'] = trim($this->getIdentifier() . ' ' . $langTitle);
}
}
}
}

/**
* Add additional titles.
*
* @param array $data Reference to the target array
*
* @return void
*/
protected function addAdditionalTitles(array &$data): void
{
// Language specific title fields
$data['title_en_txt'] = $this->getTitleEn();
$data['title_fi_txt'] = $this->getTitleFi();
$data['title_se_txt'] = $this->getTitleSe();
$data['title_sv_txt'] = $this->getTitleSv();
}

/**
Expand Down
13 changes: 1 addition & 12 deletions src/RecordManager/Finna/Record/Lrmi.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,7 @@ public function getOnlineUrls(): array
*/
public function getTitle($forFiling = false)
{
$doc = $this->doc;
$title = (string)$doc->title;
foreach ($doc->title as $t) {
if ((string)$t->attributes()->lang === 'fi') {
$title = (string)$t;
break;
}
}
if ($forFiling) {
$title = $this->metadataUtils->createSortTitle($title);
}
return $title;
return $this->getTitleByLanguage($forFiling, 'fi') ?: $this->getTitleByLanguage($forFiling);
}

/**
Expand Down
Loading
Loading