Skip to content

Commit 6e87bfe

Browse files
committed
#11557 Use single format for keywords in publication object
1 parent 7fa5813 commit 6e87bfe

File tree

10 files changed

+53
-57
lines changed

10 files changed

+53
-57
lines changed

api/v1/reviews/PKPReviewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function getHistory(Request $illuminateRequest): JsonResponse
181181
}
182182

183183
$publicationAbstract = $publication->getData('abstract');
184-
$publicationKeywords = $publication->getData('keywords');
184+
$publicationKeywords = array_map(fn($items) => array_column($items, 'name'), (array) $publication->getData('keywords'));
185185

186186
$declineEmail = null;
187187
if ($reviewAssignment->getDeclined()) {

classes/components/forms/publication/PKPMetadataForm.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ protected function getVocabEntryData(string $symbolic): array
167167
$symbolic,
168168
Application::ASSOC_TYPE_PUBLICATION,
169169
$this->publication->getId(),
170-
[],
171-
Repo::controlledVocab()::AS_ENTRY_DATA
170+
[]
172171
);
173172
}
174173
}

classes/controlledVocab/ControlledVocab.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class ControlledVocab extends Model
3434
public const CONTROLLED_VOCAB_SUBMISSION_AGENCY = 'submissionAgency';
3535
public const CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE = 'submissionDiscipline';
3636
public const CONTROLLED_VOCAB_SUBMISSION_KEYWORD = 'submissionKeyword';
37-
public const CONTROLLED_VOCAB_SUBMISSION_LANGUAGE = 'submissionLanguage';
3837
public const CONTROLLED_VOCAB_SUBMISSION_SUBJECT = 'submissionSubject';
3938

4039
/**
@@ -91,7 +90,6 @@ public static function getDefinedVocabSymbolic(): array
9190
static::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
9291
static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
9392
static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
94-
static::CONTROLLED_VOCAB_SUBMISSION_LANGUAGE,
9593
static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
9694
];
9795
}

classes/controlledVocab/Repository.php

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
class Repository
2424
{
25-
const AS_ENTRY_DATA = true;
26-
2725
/**
2826
* Fetch a Controlled Vocab by symbolic info, building it if needed.
2927
*/
@@ -51,9 +49,8 @@ public function getBySymbolic(
5149
int $assocType,
5250
?int $assocId,
5351
?array $locales = [],
54-
bool $asEntryData = !Repository::AS_ENTRY_DATA
55-
): array
56-
{
52+
bool $asStringOnly = false
53+
): array {
5754
$result = [];
5855

5956
ControlledVocabEntry::query()
@@ -63,12 +60,14 @@ public function getBySymbolic(
6360
)
6461
->when(!empty($locales), fn ($query) => $query->withLocales($locales))
6562
->get()
66-
->each(function ($entry) use (&$result, $asEntryData) {
63+
->each(function ($entry) use (&$result, $asStringOnly) {
6764
foreach ($entry->name as $locale => $value) {
68-
$result[$locale][] = $asEntryData ? $entry->getEntryData($locale) : $value;
65+
$result[$locale][] = $asStringOnly
66+
? $value
67+
: $entry->getEntryData($locale);
6968
}
7069
});
71-
70+
7271
return $result;
7372
}
7473

@@ -141,35 +140,4 @@ public function resequence(int $controlledVocabId): void
141140
});
142141
}
143142

144-
/**
145-
* Hydrate controlled vocab entries as entry data for a publication which will
146-
* include other meta information(e.g. source & identifier) in vocabs
147-
*/
148-
public function hydrateVocabsAsEntryData(PKPPublication $publication): PKPPublication
149-
{
150-
$mappings = [
151-
'keywords' => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
152-
'subjects' => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
153-
'disciplines' => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
154-
'supportingAgencies' => ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
155-
];
156-
157-
foreach ($mappings as $dataKey => $symbolic) {
158-
if (empty($publication->getData($dataKey))) {
159-
continue;
160-
}
161-
$publication->setData(
162-
$dataKey,
163-
$this->getBySymbolic(
164-
$symbolic,
165-
Application::ASSOC_TYPE_PUBLICATION,
166-
$publication->getId(),
167-
[],
168-
static::AS_ENTRY_DATA
169-
)
170-
);
171-
}
172-
173-
return $publication;
174-
}
175143
}

classes/publication/DAO.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ protected function deleteAuthors(int $publicationId)
360360
*/
361361
protected function setControlledVocab(Publication $publication)
362362
{
363+
# f11557
364+
# These now return an object with all the data
363365
$publication->setData(
364366
'keywords',
365367
Repo::controlledVocab()->getBySymbolic(

classes/publication/Repository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ public function edit(Publication $publication, array $params): Publication
418418
}
419419
}
420420

421-
$publication = Repo::controlledVocab()->hydrateVocabsAsEntryData($publication);
422421
$newPublication = Repo::publication()->newDataObject(array_merge($publication->_data, $params));
423422
$newPublication->stampModified();
424423

classes/publication/maps/Schema.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public function summarizeMany(Enumerable $collection, bool $anonymize = false):
104104
*/
105105
protected function mapByProperties(array $props, Publication $publication, bool $anonymize): array
106106
{
107-
$publication = Repo::controlledVocab()->hydrateVocabsAsEntryData($publication);
108107
$this->anonymize = $anonymize;
109108

110109
$output = [];

plugins/importexport/native/filter/NativeXmlPKPPublicationFilter.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,19 @@ public function handleChildElement($n, $publication)
144144

145145
for ($nc = $n->firstChild; $nc !== null; $nc = $nc->nextSibling) {
146146
if ($nc instanceof \DOMElement) {
147-
$controlledVocabulary[] = $nc->textContent;
147+
$item = ['name' => $nc->getElementsByTagName('name')->item(0)->textContent];
148+
149+
$identifierNode = $nc->getElementsByTagName('identifier')->item(0);
150+
if ($identifierNode) {
151+
$item['identifier'] = $identifierNode->textContent;
152+
}
153+
154+
$sourceNode = $nc->getElementsByTagName('source')->item(0);
155+
if ($sourceNode) {
156+
$item['source'] = $sourceNode->textContent;
157+
}
158+
159+
$controlledVocabulary[] = $item;
148160
}
149161
}
150162

plugins/importexport/native/filter/PKPPublicationNativeXmlFilter.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ public function addMetadata($doc, $entityNode, $entity)
213213

214214
// add controlled vocabularies
215215
// get the supported locale keys
216+
# f11557
217+
# TODO native XML
216218
$controlledVocabulariesMapping = $this->_getControlledVocabulariesMappings();
217219
foreach ($controlledVocabulariesMapping as $controlledVocabulariesNodeName => $mappings) {
218220
$symbolic = $mappings[0];
@@ -239,12 +241,22 @@ public function addControlledVocabulary($doc, $entityNode, $controlledVocabulari
239241
{
240242
$deployment = $this->getDeployment();
241243
$locales = array_keys($controlledVocabulary);
244+
242245
foreach ($locales as $locale) {
243246
if (!empty($controlledVocabulary[$locale])) {
244247
$controlledVocabulariesNode = $doc->createElementNS($deployment->getNamespace(), $controlledVocabulariesNodeName);
245248
$controlledVocabulariesNode->setAttribute('locale', $locale);
246-
foreach ($controlledVocabulary[$locale] as $controlledVocabularyItem) {
247-
$controlledVocabulariesNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), $controlledVocabularyNodeName, htmlspecialchars($controlledVocabularyItem, ENT_COMPAT, 'UTF-8')));
249+
250+
foreach ($controlledVocabulary[$locale] as $item) {
251+
$node = $doc->createElementNS($deployment->getNamespace(), $controlledVocabularyNodeName);
252+
$node->appendChild($doc->createElementNS($deployment->getNamespace(), 'name', htmlspecialchars($item['name'], ENT_COMPAT, 'UTF-8')));
253+
if (!empty($item['identifier'])) {
254+
$node->appendChild($doc->createElementNS($deployment->getNamespace(), 'identifier', htmlspecialchars($item['identifier'], ENT_COMPAT, 'UTF-8')));
255+
}
256+
if (!empty($item['source'])) {
257+
$node->appendChild($doc->createElementNS($deployment->getNamespace(), 'source', htmlspecialchars($item['source'], ENT_COMPAT, 'UTF-8')));
258+
}
259+
$controlledVocabulariesNode->appendChild($node);
248260
}
249261

250262
$entityNode->appendChild($controlledVocabulariesNode);

plugins/importexport/native/pkp-native.xsd

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,27 @@
356356
<element name="pkppublication" type="pkp:pkppublication" />
357357

358358
<!-- Controlled vocabularies -->
359+
<complexType name="ControlledVocabEntryType">
360+
<sequence>
361+
<element name="name" type="string"/>
362+
<element name="identifier" type="string" minOccurs="0"/>
363+
<element name="source" type="string" minOccurs="0"/>
364+
</sequence>
365+
</complexType>
359366
<element name="keywords">
360367
<complexType>
361368
<sequence>
362-
<element name="keyword" type="string" minOccurs="1" maxOccurs="unbounded" />
369+
<element name="keyword" type="pkp:ControlledVocabEntryType" minOccurs="1" maxOccurs="unbounded"/>
363370
</sequence>
364-
<attribute name="locale" type="string" />
371+
<attribute name="locale" type="string"/>
365372
</complexType>
366373
</element>
367374
<element name="agencies">
368375
<complexType>
369376
<sequence>
370-
<element name="agency" type="string" minOccurs="1" maxOccurs="unbounded" />
377+
<element name="keyword" type="pkp:ControlledVocabEntryType" minOccurs="1" maxOccurs="unbounded"/>
371378
</sequence>
372-
<attribute name="locale" type="string" />
379+
<attribute name="locale" type="string"/>
373380
</complexType>
374381
</element>
375382
<element name="languages">
@@ -383,17 +390,17 @@
383390
<element name="disciplines">
384391
<complexType>
385392
<sequence>
386-
<element name="discipline" type="string" minOccurs="1" maxOccurs="unbounded" />
393+
<element name="keyword" type="pkp:ControlledVocabEntryType" minOccurs="1" maxOccurs="unbounded"/>
387394
</sequence>
388-
<attribute name="locale" type="string" />
395+
<attribute name="locale" type="string"/>
389396
</complexType>
390397
</element>
391398
<element name="subjects">
392399
<complexType>
393400
<sequence>
394-
<element name="subject" type="string" minOccurs="1" maxOccurs="unbounded" />
401+
<element name="keyword" type="pkp:ControlledVocabEntryType" minOccurs="1" maxOccurs="unbounded"/>
395402
</sequence>
396-
<attribute name="locale" type="string" />
403+
<attribute name="locale" type="string"/>
397404
</complexType>
398405
</element>
399406
<element name="citations">

0 commit comments

Comments
 (0)