Skip to content

Commit

Permalink
Merge pull request #2 from Kungbib/feature/keywords-from-controlled-v…
Browse files Browse the repository at this point in the history
…ocabulary

Feature/keywords from controlled vocabulary
  • Loading branch information
lrosenstrom authored May 12, 2021
2 parents 6c8ea4f + 1c26529 commit 427c975
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
35 changes: 34 additions & 1 deletion fgsMetsMods/OAIMetadataFormat_FgsMetsMods.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,47 @@ function toXml($record, $format = null) {
}
}

$linkedKeywords = [];
$simpleKeywords = [];
foreach ($keywords as $locale => $kws) {
$lang = AppLocale::get3LetterIsoFromLocale($locale);
foreach ($kws as $kw) {
if (str_contains($kw, 'https://id.kb.se/term')) {
$prefLabelAndUri = explode('|', $kw);
$prefLabel = $prefLabelAndUri[0];
$uriDecoded = end($prefLabelAndUri);

$uriFragments = explode('/', $uriDecoded);
$label = end($uriFragments);
array_pop($uriFragments);
$authority = end($uriFragments);
array_push($uriFragments, rawurlencode($label));
$linkedKeywords[] =
[
'lang' => $lang,
'label' => $prefLabel,
'uri' => implode('/', $uriFragments),
'authority' => $authority
];
} else {
$simpleKeywords[] =
[
'lang' => $lang,
'keyword' => $kw
];
}
}
}

$templateMgr = TemplateManager::getManager();
$templateMgr->assign(array(
'journal' => $journal,
'article' => $article,
'articleUrl' => $articleUrl,
'issue' => $record->getData('issue'),
'section' => $record->getData('section'),
'keywords' => $keywords[$article->getLocale()],
'keywords' => $simpleKeywords,
'linkedKeywords' => $linkedKeywords,
'galleyProps' => $galleyProps,
'fileGroups' => $fileGroups,
'pluginName' => $plugin->getDisplayName(),
Expand Down
17 changes: 15 additions & 2 deletions fgsMetsMods/templates/record.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,23 @@
{/if}
</mods:relatedItem>
{foreach $keywords as $keyword}
<mods:subject lang="{$articleLanguage}">
<mods:topic>{$keyword|escape}</mods:topic>
<mods:subject lang="{$keyword.lang}">
<mods:topic>{$keyword.keyword|escape}</mods:topic>
</mods:subject>
{/foreach}
{* Remove when Mimer accepts the valueUri attribute *}
{foreach $linkedKeywords as $keyword}
<mods:subject lang="{$keyword.lang}" authority="{$keyword.authority}">
<mods:topic>{$keyword.label|escape}</mods:topic>
</mods:subject>
{/foreach}
{* Activate when Mimer accepts the valueUri attribute!
{foreach $linkedKeywords as $keyword}
<mods:subject lang="{$keyword.lang}">
<mods:topic valueUri="{$keyword.uri}">{$keyword.label}</mods:topic>
</mods:subject>
{/foreach}
*}
{if $abstract}
<mods:abstract lang="{$articleLanguage|escape}">{$abstract|escape}</mods:abstract>
{/if}
Expand Down

0 comments on commit 427c975

Please sign in to comment.