-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkp/pkp-lib#1550 Controlled vocabulary support #10833
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
class Repository | ||
{ | ||
const AS_ENTRY_DATA = true; | ||
|
||
/** | ||
* Fetch a Controlled Vocab by symbolic info, building it if needed. | ||
*/ | ||
|
@@ -46,7 +48,8 @@ public function getBySymbolic( | |
string $symbolic, | ||
int $assocType, | ||
?int $assocId, | ||
?array $locales = [] | ||
?array $locales = [], | ||
bool $asEntryData = !Repository::AS_ENTRY_DATA | ||
): array | ||
{ | ||
$result = []; | ||
|
@@ -58,9 +61,9 @@ public function getBySymbolic( | |
) | ||
->when(!empty($locales), fn ($query) => $query->withLocales($locales)) | ||
->get() | ||
->each(function ($entry) use (&$result) { | ||
->each(function ($entry) use (&$result, $asEntryData) { | ||
foreach ($entry->name as $locale => $value) { | ||
$result[$locale][] = $value; | ||
$result[$locale][] = $asEntryData ? $entry->getEntryData($locale) : $value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, what are the chances to standardise the output to one single format , so with
and
if we try to standardise it as
what about that ? or perhaps that will be too much changes as I guess need to port that changes to a lot of places . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}); | ||
|
||
|
@@ -80,6 +83,11 @@ public function insertBySymbolic( | |
{ | ||
$controlledVocab = $this->build($symbolic, $assocType, $assocId); | ||
$controlledVocab->load('controlledVocabEntries'); | ||
$controlledVocabEntry = new ControlledVocabEntry; | ||
$controlledVocabEntrySettings = $controlledVocabEntry->getSettings(); | ||
$multilingualProps = array_flip($controlledVocabEntry->getMultilingualProps()); | ||
$idKey = ControlledVocabEntry::CONTROLLED_VOCAB_ENTRY_IDENTIFIER; | ||
$srcKey = ControlledVocabEntry::CONTROLLED_VOCAB_ENTRY_SOURCE; | ||
|
||
if ($deleteFirst) { | ||
ControlledVocabEntry::query() | ||
|
@@ -93,17 +101,28 @@ public function insertBySymbolic( | |
collect($vocabs) | ||
->each( | ||
fn (array|string $entries, string $locale) => collect(array_values(Arr::wrap($entries))) | ||
->reject(fn (string|array $vocab) => is_array($vocab) && isset($vocab[$idKey]) && !isset($vocab[$srcKey])) // Remove vocabs that have id but not source | ||
->unique(fn (string|array $vocab): string => ($vocab[$idKey] ?? '') . ($vocab[$srcKey] ?? '') . ($vocab['name'] ?? $vocab)) | ||
->each( | ||
fn (string $vocab, int $index) => | ||
fn (array|string $vocab, int $index) => | ||
ControlledVocabEntry::create([ | ||
'controlledVocabId' => $controlledVocab->id, | ||
'seq' => $index + 1, | ||
'name' => [ | ||
$locale => $vocab | ||
], | ||
...is_array($vocab) | ||
? collect($vocab) | ||
->only($controlledVocabEntrySettings) | ||
->whereNotNull() | ||
->map(fn ($prop, string $propName) => isset($multilingualProps[$propName]) | ||
? [$locale => $prop] | ||
: $prop | ||
) | ||
->toArray() | ||
: ['name' => [$locale => $vocab]], | ||
]) | ||
) | ||
); | ||
|
||
$this->resequence($controlledVocab->id); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,24 @@ | |
"nullable" | ||
], | ||
"items": { | ||
"type": "string" | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above as if |
||
}, | ||
"source": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
}, | ||
"identifier": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"doiObject": { | ||
|
@@ -180,7 +197,24 @@ | |
"nullable" | ||
], | ||
"items": { | ||
"type": "string" | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"source": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
}, | ||
"identifier": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"lastModified": { | ||
|
@@ -256,7 +290,24 @@ | |
"nullable" | ||
], | ||
"items": { | ||
"type": "string" | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"source": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
}, | ||
"identifier": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"submissionId": { | ||
|
@@ -281,7 +332,24 @@ | |
"nullable" | ||
], | ||
"items": { | ||
"type": "string" | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"source": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
}, | ||
"identifier": { | ||
"type": "string", | ||
"validation": [ | ||
"nullable" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"status": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason we are defining these core settings columns as const here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, where would be a better place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking that just use these as settings columns in the
getSettings
method and not define these as const . Just wondering is there any chance to specifically use the fields by any plugin or have any special use later ? Better to use const when each of that information need to be specifically use for special purpose multiple time .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugins should use these when creating suggestions for the fields. Downstream services may use 'identifier' (e.g. when it's url) but probably don't have use for 'service'. Also at some point in the future there could be more data added than just 'name', 'identifier', and 'source'. Currently core doesn't use identifier and source separately but that may change in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we can leave it as it is for now .