Skip to content

Commit

Permalink
pkp#10292 removed extended vocab classes
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Oct 23, 2024
1 parent 5e2c9f3 commit e924fc3
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 456 deletions.
33 changes: 8 additions & 25 deletions api/v1/vocabs/PKPVocabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\controlledVocab\ControlledVocab;
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\SubmissionAgencyVocab;
use PKP\submission\SubmissionDisciplineVocab;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

class PKPVocabController extends PKPBaseController
{
Expand Down Expand Up @@ -113,26 +109,13 @@ public function getMany(Request $illuminateRequest): JsonResponse
], Response::HTTP_BAD_REQUEST);
}

switch ($vocab) {
case SubmissionKeywordVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD:
$submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO'); /** @var \PKP\submission\SubmissionKeywordEntryDAO $submissionKeywordEntryDao */
$entries = $submissionKeywordEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionSubjectVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT:
$submissionSubjectEntryDao = DAORegistry::getDAO('SubmissionSubjectEntryDAO'); /** @var \PKP\submission\SubmissionSubjectEntryDAO $submissionSubjectEntryDao */
$entries = $submissionSubjectEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionDisciplineVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE:
$submissionDisciplineEntryDao = DAORegistry::getDAO('SubmissionDisciplineEntryDAO'); /** @var \PKP\submission\SubmissionDisciplineEntryDAO $submissionDisciplineEntryDao */
$entries = $submissionDisciplineEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionAgencyVocab::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)) {
/** @var \PKP\controlledVocab\ControlledVocabEntryDAO $entryDao */
$entryDao = Repo::controlledVocab()->getEntryDaoBySymbolic($vocab);
$entries = $entryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
} else {
$entries = [];
Hook::call('API::vocabs::getMany', [$vocab, &$entries, $illuminateRequest, response(), $request]);
}

$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\SubmissionKeywordVocab;
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__', SubmissionKeywordVocab::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\SubmissionAgencyVocab;
use PKP\submission\SubmissionDisciplineVocab;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

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__', SubmissionKeywordVocab::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__', SubmissionSubjectVocab::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__', SubmissionDisciplineVocab::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__', SubmissionAgencyVocab::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
45 changes: 34 additions & 11 deletions classes/controlledVocab/ControlledVocab.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class ControlledVocab extends Model
{
use HasCamelCasing;

public const CONTROLLED_VOCAB_SUBMISSION_AGENCY = 'submissionAgency';
public const CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE = 'submissionDiscipline';
public const CONTROLLED_VOCAB_SUBMISSION_KEYWORD = 'submissionKeyword';
public const CONTROLLED_VOCAB_SUBMISSION_LANGUAGE = 'submissionLanguage';
public const CONTROLLED_VOCAB_SUBMISSION_SUBJECT = 'submissionSubject';

protected $table = 'controlled_vocabs';
protected $primaryKey = 'controlled_vocab_id';

Expand All @@ -40,6 +46,22 @@ class ControlledVocab extends Model
*/
public $timestamps = false;

public static function getDefinedVocabSymbolic(): array
{
return [
static::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
static::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
static::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
static::CONTROLLED_VOCAB_SUBMISSION_LANGUAGE,
static::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
];
}

public static function hasDefinedVocabSymbolic(string $vocab): bool
{
return in_array($vocab, static::getDefinedVocabSymbolic());
}

protected function casts(): array
{
return [
Expand All @@ -60,6 +82,17 @@ protected function id(): Attribute
);
}

public function getLocaleFieldNames(): array
{
if (!$this->symbolic) {
return [];
}

return static::hasDefinedVocabSymbolic($this->symbolic)
? [$this->symbolic]
: [];
}

/**
* Compatibility function for including note IDs in grids.
*
Expand All @@ -70,22 +103,12 @@ public function getId(): int
return $this->id;
}

/**
* Compatibility function for including notes in grids.
*
* @deprecated 3.5. Use $model or $model->$field instead. Can be removed once the DataObject pattern is removed.
*/
public function getData(?string $field): mixed
{
return $field ? $this->$field : $this;
}

/**
* Scope a query to only include notes with a specific user ID.
*/
public function scopeWithSymbolic(Builder $query, string $symbolic): Builder
{
return $query->where(DB::raw('LOWER(symbolic)'), strtolower($symbolic));
return $query->where('symbolic', $symbolic);
}

/**
Expand Down
84 changes: 68 additions & 16 deletions classes/publication/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
namespace PKP\publication;

use APP\facades\Repo;
use APP\core\Application;
use APP\publication\Publication;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\LazyCollection;
use PKP\citation\CitationDAO;
use PKP\controlledVocab\ControlledVocab;
use PKP\core\EntityDAO;
use PKP\core\traits\EntityWithParent;
use PKP\services\PKPSchemaService;
use PKP\submission\SubmissionAgencyVocab;
use PKP\submission\SubmissionDisciplineVocab;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

/**
* @template T of Publication
Expand Down Expand Up @@ -348,10 +346,41 @@ protected function deleteAuthors(int $publicationId)
*/
protected function setControlledVocab(Publication $publication)
{
$publication->setData('keywords', SubmissionKeywordVocab::getKeywords($publication->getId()));
$publication->setData('subjects', SubmissionSubjectVocab::getSubjects($publication->getId()));
$publication->setData('disciplines', SubmissionDisciplineVocab::getDisciplines($publication->getId()));
$publication->setData('supportingAgencies', SubmissionAgencyVocab::getAgencies($publication->getId()));
$publication->setData(
'keywords',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
)
);

$publication->setData(
'subjects',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
)
);

$publication->setData(
'disciplines',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
)
);

$publication->setData(
'supportingAgencies',
Repo::controlledVocab()->getBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
Application::ASSOC_TYPE_PUBLICATION,
$publication->getId()
)
);
}

/**
Expand Down Expand Up @@ -389,10 +418,10 @@ protected function saveControlledVocab(array $values, int $publicationId)
// Update controlled vocabularly for which we have props
foreach ($values as $prop => $value) {
match ($prop) {
'keywords' => SubmissionKeywordVocab::insertKeywords($value, $publicationId),
'subjects' => SubmissionSubjectVocab::insertSubjects($value, $publicationId),
'disciplines' => SubmissionDisciplineVocab::insertDisciplines($value, $publicationId),
'supportingAgencies' => SubmissionAgencyVocab::insertAgencies($value, $publicationId),
'keywords' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId),
'subjects' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId),
'disciplines' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId),
'supportingAgencies' => Repo::controlledVocab()->insertBySymbolic(ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY, $value, Application::ASSOC_TYPE_PUBLICATION, $publicationId),
};
}
}
Expand All @@ -402,10 +431,33 @@ protected function saveControlledVocab(array $values, int $publicationId)
*/
protected function deleteControlledVocab(int $publicationId)
{
SubmissionKeywordVocab::insertKeywords([], $publicationId);
SubmissionSubjectVocab::insertSubjects([], $publicationId);
SubmissionDisciplineVocab::insertDisciplines([], $publicationId);
SubmissionAgencyVocab::insertAgencies([], $publicationId);
Repo::controlledVocab()->insertBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD,
[],
Application::ASSOC_TYPE_PUBLICATION,
$publicationId
);

Repo::controlledVocab()->insertBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT,
[],
Application::ASSOC_TYPE_PUBLICATION,
$publicationId
);

Repo::controlledVocab()->insertBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_DISCIPLINE,
[],
Application::ASSOC_TYPE_PUBLICATION,
$publicationId
);

Repo::controlledVocab()->insertBySymbolic(
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_AGENCY,
[],
Application::ASSOC_TYPE_PUBLICATION,
$publicationId
);
}

/**
Expand Down
Loading

0 comments on commit e924fc3

Please sign in to comment.