Skip to content
Open
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
18 changes: 8 additions & 10 deletions classes/search/PreprintSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
use APP\core\Request;
use APP\facades\Repo;
use APP\server\Server;
use PKP\controlledVocab\ControlledVocab;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\plugins\Hook;
use PKP\search\SubmissionSearch;
use PKP\submission\PKPSubmission;
Expand Down Expand Up @@ -320,16 +318,16 @@ public function getSimilarityTerms($submissionId)
$preprint = Repo::submission()->get($submissionId);
if ($preprint->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
// Retrieve keywords (if any).
$allSearchTerms = array_filter(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
Application::ASSOC_TYPE_PUBLICATION,
$preprint->getId(),
[Locale::getLocale(), $preprint->getData('locale'), Locale::getPrimaryLocale()]
$allSearchTerms = collect($article->getCurrentPublication()->getData('keywords'))
->map(
fn (array $items): array => collect($items)
->pluck('name')
->all()
)
);
->all();

foreach ($allSearchTerms as $locale => $localeSearchTerms) {
$searchTerms += $localeSearchTerms;
$searchTerms = array_merge($searchTerms, $localeSearchTerms);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions classes/search/PreprintSearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,16 @@ protected function _updateTextIndex($preprintId, $type, $text, $assocId = null)
protected function _flattenLocalizedArray($arrayWithLocales)
{
$flattenedArray = [];

foreach ($arrayWithLocales as $localeArray) {
$flattenedArray = array_merge(
$flattenedArray,
$names = array_map(
static fn ($item) => $item['name'],
$localeArray
);

$flattenedArray = array_merge($flattenedArray, $names);
}

return $flattenedArray;
}
}
25 changes: 14 additions & 11 deletions plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use APP\oai\ops\OAIDAO;
use APP\plugins\PubIdPlugin;
use APP\submission\Submission;
use PKP\controlledVocab\ControlledVocab;
use PKP\db\DAORegistry;
use PKP\metadata\MetadataDataObjectAdapter;
use PKP\metadata\MetadataDescription;
Expand Down Expand Up @@ -87,16 +86,20 @@ public function &extractMetadataFromDataObject(&$submission)

// Subject
$subjects = array_merge_recursive(
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
),
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
)
collect($publication->getData('keywords'))
->map(
fn (array $items): array => collect($items)
->pluck('name')
->all()
)
->all(),
collect($publication->getData('subjects'))
->map(
fn (array $items): array => collect($items)
->pluck('name')
->all()
)
->all()
);
$this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);

Expand Down
53 changes: 40 additions & 13 deletions plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PKP\controlledVocab\ControlledVocab;
use PKP\controlledVocab\Repository as ControlledVocabRepository;
use PKP\core\Dispatcher;
use PKP\core\Registry;
Expand Down Expand Up @@ -96,6 +97,27 @@ public function testToXml()
]);
$author->setEmail('[email protected]');

/** @var ControlledVocabRepository|MockObject */
$controlledVocabRepoMock = Mockery::mock(ControlledVocabRepository::class)
->makePartial()
->shouldReceive('getBySymbolic')
->twice()
->andReturn(
[
'en' => [
['name' => 'preprint-keyword'],
]
],
[
'en' => [
['name' => 'preprint-subject'],
['name' => 'preprint-subject-class'],
]
]
)
->getMock();
app()->instance(ControlledVocabRepository::class, $controlledVocabRepoMock);

/** @var Publication|MockObject */
$publication = $this->getMockBuilder(Publication::class)
->onlyMethods([])
Expand All @@ -113,6 +135,24 @@ public function testToXml()
$publication->setData('copyrightYear', 'year');
$publication->setData('datePublished', '2010-11-05');
$publication->setData('authors', collect([$author]));
$publication->setData(
'keywords',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
0,
Application::ASSOC_TYPE_PUBLICATION
)['en'],
'en'
);
$publication->setData(
'subjects',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
0,
Application::ASSOC_TYPE_PUBLICATION
)['en'],
'en'
);

// Preprint
/** @var Submission|MockObject */
Expand Down Expand Up @@ -241,19 +281,6 @@ public function testToXml()
->willReturn(LazyCollection::wrap($galleys));
app()->instance(GalleyCollector::class, $mockGalleyCollector);

$controlledVocabRepoMock = Mockery::mock(ControlledVocabRepository::class)
->makePartial()
->shouldReceive('getBySymbolic')
->twice()
->withAnyArgs()
->andReturn(
['en' => ['preprint-keyword']],
['en' => ['preprint-subject', 'preprint-subject-class']]
)
->getMock();

app()->instance(ControlledVocabRepository::class, $controlledVocabRepoMock);

//
// Test
//
Expand Down
2 changes: 1 addition & 1 deletion templates/frontend/objects/preprint_details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</h2>
<span class="value">
{foreach name="keywords" from=$publication->getLocalizedData('keywords') item="keyword"}
{$keyword|escape}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if}
{$keyword.name|escape}{if $keyword.identifier} ({$keyword.identifier|escape}){/if}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if}
{/foreach}
</span>
</section>
Expand Down
2 changes: 1 addition & 1 deletion templates/frontend/objects/preprint_summary.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<div class="keywords">
<ul class="keyword_links">
{foreach name="keywords" from=$preprint->getCurrentPublication()->getLocalizedData('keywords') item="keyword"}
<li>{$keyword|escape}</li>
<li>{$keyword.name|escape}</li>
{/foreach}
</ul>
</div>
Expand Down