Skip to content
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#10292 Controlled Vocab DAO to Eloquent Model #10324

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
54bf6b4
pkp/pkp-lib#10292 Controlled Vocab DAO to Eloquent Model
touhidurabir Aug 16, 2024
e4d5ee3
pkp/pkp-lib#10292 WIP: Controlled Vocab DAO to Eloquent Model
touhidurabir Aug 19, 2024
ed09b59
pkp/pkp-lib#10292 typo fixed
touhidurabir Aug 19, 2024
e5b161c
pkp/pkp-lib#10292 proper model import for native xml
touhidurabir Aug 20, 2024
55f43a9
pkp/pkp-lib#10292 fixing unit tests
touhidurabir Aug 20, 2024
5e2c9f3
pkp/pkp-lib#10292 Refactored user interest to model and repository
touhidurabir Aug 26, 2024
e924fc3
pkp/pkp-lib#10292 removed extended vocab classes
touhidurabir Aug 26, 2024
dd5959d
pkp/pkp-lib#10292 fixing issue with vocab storing and some doc blocks…
touhidurabir Aug 27, 2024
2a0a379
pkp/pkp-lib#10292 added TODO to investigate the impact of merged issu…
touhidurabir Oct 3, 2024
9ad4168
pkp/pkp-lib#10292 refactored entry dao to model class
touhidurabir Oct 7, 2024
b321612
pkp/pkp-lib#10292 removed setting_type column
touhidurabir Oct 7, 2024
a827948
pkp/pkp-lib#10292 fixed vocab setting issue
touhidurabir Oct 8, 2024
f192d62
pkp/pkp-lib#10292 refactored interest manager to repo and removed it
touhidurabir Oct 8, 2024
6642ae9
pkp/pkp-lib#10292 resolved all but one TODO
touhidurabir Oct 8, 2024
c89621a
pkp/pkp-lib#10292 fixed issue the settings builder to retrieve specif…
touhidurabir Oct 18, 2024
ce24986
pkp/pkp-lib#10292 added ability to add setting and multilingual colum…
touhidurabir Oct 20, 2024
f12139c
pkp/pkp-lib#10292 fixed issue when guarded attribute defined
touhidurabir Oct 21, 2024
c4644ba
pkp/pkp-lib#10292 updated implementation of updating with multilingua…
touhidurabir Oct 22, 2024
b9d8651
pkp/pkp-lib#10292 added multilingual casting as part of #10476
touhidurabir Oct 22, 2024
6c94c9d
pkp/pkp-lib#10292 fixed issue the data building with settings attrs
touhidurabir Oct 23, 2024
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
48 changes: 21 additions & 27 deletions api/v1/vocabs/PKPVocabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\controlledVocab\ControlledVocab;
use PKP\controlledVocab\ControlledVocabEntry;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\plugins\Hook;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\submission\SubmissionAgencyDAO;
use PKP\submission\SubmissionDisciplineDAO;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;

class PKPVocabController extends PKPBaseController
{
Expand Down Expand Up @@ -105,39 +102,36 @@ public function getMany(Request $illuminateRequest): JsonResponse
$vocab = $requestParams['vocab'] ?? '';
$locale = $requestParams['locale'] ?? Locale::getLocale();
$term = $requestParams['term'] ?? null;
$locales = array_merge($context->getSupportedSubmissionMetadataLocales(), isset($requestParams['submissionId']) ? Repo::submission()->get((int) $requestParams['submissionId'])?->getPublicationLanguages() ?? [] : []);
$locales = array_merge(
$context->getSupportedSubmissionMetadataLocales(),
isset($requestParams['submissionId'])
? (Repo::submission()->get((int) $requestParams['submissionId'])?->getPublicationLanguages() ?? [])
: []
);

if (!in_array($locale, $locales)) {
return response()->json([
'error' => __('api.vocabs.400.localeNotSupported', ['locale' => $locale]),
], Response::HTTP_BAD_REQUEST);
}

switch ($vocab) {
case SubmissionKeywordDAO::CONTROLLED_VOCAB_SUBMISSION_KEYWORD:
$submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO'); /** @var \PKP\submission\SubmissionKeywordEntryDAO $submissionKeywordEntryDao */
$entries = $submissionKeywordEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionSubjectDAO::CONTROLLED_VOCAB_SUBMISSION_SUBJECT:
$submissionSubjectEntryDao = DAORegistry::getDAO('SubmissionSubjectEntryDAO'); /** @var \PKP\submission\SubmissionSubjectEntryDAO $submissionSubjectEntryDao */
$entries = $submissionSubjectEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionDisciplineDAO::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE:
$submissionDisciplineEntryDao = DAORegistry::getDAO('SubmissionDisciplineEntryDAO'); /** @var \PKP\submission\SubmissionDisciplineEntryDAO $submissionDisciplineEntryDao */
$entries = $submissionDisciplineEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionAgencyDAO::CONTROLLED_VOCAB_SUBMISSION_AGENCY:
$submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO'); /** @var \PKP\submission\SubmissionAgencyEntryDAO $submissionAgencyEntryDao */
$entries = $submissionAgencyEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
default:
$entries = [];
Hook::call('API::vocabs::getMany', [$vocab, &$entries, $illuminateRequest, response(), $request]);
if (ControlledVocab::hasDefinedVocabSymbolic($vocab)) {
$entries = ControlledVocabEntry::query()
->whereHas(
"controlledVocab",
fn($query) => $query->withSymbolic($vocab)->withContextId($context->getId())
)
->withLocale($locale)
->when($term, fn ($query) => $query->withSetting($vocab, $term))
->get();
} else {
$entries = [];
Hook::call('API::vocabs::getMany', [$vocab, &$entries, $illuminateRequest, response(), $request]);
}

$data = [];
foreach ($entries as $entry) {
$data[] = $entry->getData($vocab, $locale);
$data[] = $entry->getLocalizedData($vocab, $locale);
}

$data = array_values(array_unique($data));
Expand Down
4 changes: 2 additions & 2 deletions classes/components/forms/publication/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use APP\publication\Publication;
use PKP\components\forms\FieldControlledVocab;
use PKP\context\Context;
use PKP\submission\SubmissionKeywordDAO;
use PKP\controlledVocab\ControlledVocab;

class Details extends TitleAbstractForm
{
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __construct(
'label' => __('common.keywords'),
'description' => __('manager.setup.metadata.keywords.description'),
'isMultilingual' => true,
'apiUrl' => str_replace('__vocab__', SubmissionKeywordDAO::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase),
'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase),
'locales' => $this->locales,
'value' => (array) $publication->getData('keywords'),
'isRequired' => $context->getData('keywords') === Context::METADATA_REQUIRE ? true : false,
Expand Down
13 changes: 5 additions & 8 deletions classes/components/forms/publication/PKPMetadataForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
namespace PKP\components\forms\publication;

use APP\publication\Publication;
use PKP\controlledVocab\ControlledVocab;
use PKP\components\forms\FieldControlledVocab;
use PKP\components\forms\FieldRichTextarea;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use PKP\context\Context;
use PKP\submission\SubmissionAgencyDAO;
use PKP\submission\SubmissionDisciplineDAO;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;

class PKPMetadataForm extends FormComponent
{
Expand Down Expand Up @@ -55,7 +52,7 @@ public function __construct(string $action, array $locales, Publication $publica
'label' => __('common.keywords'),
'tooltip' => __('manager.setup.metadata.keywords.description'),
'isMultilingual' => true,
'apiUrl' => str_replace('__vocab__', SubmissionKeywordDAO::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase),
'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $suggestionUrlBase),
'locales' => $this->locales,
'value' => (array) $publication->getData('keywords'),
]));
Expand All @@ -66,7 +63,7 @@ public function __construct(string $action, array $locales, Publication $publica
'label' => __('common.subjects'),
'tooltip' => __('manager.setup.metadata.subjects.description'),
'isMultilingual' => true,
'apiUrl' => str_replace('__vocab__', SubmissionSubjectDAO::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $suggestionUrlBase),
'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $suggestionUrlBase),
'locales' => $this->locales,
'value' => (array) $publication->getData('subjects'),
]));
Expand All @@ -77,7 +74,7 @@ public function __construct(string $action, array $locales, Publication $publica
'label' => __('search.discipline'),
'tooltip' => __('manager.setup.metadata.disciplines.description'),
'isMultilingual' => true,
'apiUrl' => str_replace('__vocab__', SubmissionDisciplineDAO::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $suggestionUrlBase),
'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $suggestionUrlBase),
'locales' => $this->locales,
'value' => (array) $publication->getData('disciplines'),
]));
Expand All @@ -88,7 +85,7 @@ public function __construct(string $action, array $locales, Publication $publica
'label' => __('submission.supportingAgencies'),
'tooltip' => __('manager.setup.metadata.agencies.description'),
'isMultilingual' => true,
'apiUrl' => str_replace('__vocab__', SubmissionAgencyDAO::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $suggestionUrlBase),
'apiUrl' => str_replace('__vocab__', ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $suggestionUrlBase),
'locales' => $this->locales,
'value' => (array) $publication->getData('supportingAgencies'),
]));
Expand Down
Loading