Skip to content

Commit

Permalink
pkp/pkp-lib#10292 WIP: Controlled Vocab DAO to Eloquent Model
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Aug 19, 2024
1 parent ae25aff commit 5db03d3
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9892_FloatToDecimalColumnTypeUpdate.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I10292_AddPrimaryKeyToUserInterestsTable
*
* @brief Add primary key column to `user_interests` table
*
* @see
*/

namespace APP\migration\upgrade\v3_5_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class I10292_AddPrimaryKeyToUserInterestsTable extends \PKP\migration\Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('user_interests', function (Blueprint $table) {
$table->bigIncrements('user_interest_id')->first();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('user_interests', function (Blueprint $table) {
$table->dropColumn('user_interest_id');
});
}
}
6 changes: 3 additions & 3 deletions classes/search/ArticleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PKP\plugins\Hook;
use PKP\search\SubmissionSearch;
use PKP\submission\PKPSubmission;
use PKP\submission\SubmissionKeywordVocab;

class ArticleSearch extends SubmissionSearch
{
Expand Down Expand Up @@ -199,7 +200,7 @@ public function getSearchFilters($request)
$context = $contextDao->getById($searchFilters['searchJournal']);
} elseif (array_key_exists('journalTitle', $request->getUserVars())) {
$contexts = $contextDao->getAll(true);
while ($context = $contexts->next()) {
while ($context = $contexts->next()) { /** @var \PKP\context\Context $context */
if (in_array(
$request->getUserVar('journalTitle'),
(array) $context->getName(null)
Expand Down Expand Up @@ -333,8 +334,7 @@ public function getSimilarityTerms($submissionId)
$article = Repo::submission()->get($submissionId);
if ($article->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
// Retrieve keywords (if any).
$submissionSubjectDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var \PKP\submission\SubmissionKeywordDAO $submissionSubjectDao */
$allSearchTerms = array_filter($submissionSubjectDao->getKeywords($article->getCurrentPublication()->getId(), [Locale::getLocale(), $article->getData('locale'), Locale::getPrimaryLocale()]));
$allSearchTerms = array_filter(SubmissionKeywordVocab::getKeywords($article->getCurrentPublication()->getId(), [Locale::getLocale(), $article->getData('locale'), Locale::getPrimaryLocale()]));
foreach ($allSearchTerms as $locale => $localeSearchTerms) {
$searchTerms += $localeSearchTerms;
}
Expand Down
7 changes: 2 additions & 5 deletions plugins/importexport/doaj/filter/DOAJJsonFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
use APP\plugins\importexport\doaj\DOAJExportDeployment;
use APP\plugins\importexport\doaj\DOAJExportPlugin;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\plugins\importexport\PKPImportExportFilter;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionKeywordVocab;

class DOAJJsonFilter extends PKPImportExportFilter
{
Expand Down Expand Up @@ -176,9 +175,7 @@ public function &process(&$pubObject)
$article['bibjson']['abstract'] = PKPString::html2text($abstract);
}
// Keywords
/** @var SubmissionKeywordDAO */
$dao = DAORegistry::getDAO('SubmissionKeywordDAO');
$keywords = $dao->getKeywords($publication->getId(), [$publicationLocale]);
$keywords = SubmissionKeywordVocab::getKeywords($publication->getId(), [$publicationLocale]);
$allowedNoOfKeywords = array_slice($keywords[$publicationLocale] ?? [], 0, 6);
if (!empty($keywords[$publicationLocale])) {
$article['bibjson']['keywords'] = $allowedNoOfKeywords;
Expand Down
10 changes: 5 additions & 5 deletions plugins/importexport/doaj/filter/DOAJXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
use APP\publication\Publication;
use APP\submission\Submission;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\i18n\LocaleConversion;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionKeywordVocab;

class DOAJXmlFilter extends \PKP\plugins\importexport\native\filter\NativeExportFilter
{
Expand Down Expand Up @@ -189,16 +188,17 @@ public function &process(&$pubObjects)
$request = Application::get()->getRequest();
$recordNode->appendChild($node = $doc->createElement('fullTextUrl', htmlspecialchars($request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'article', 'view', [$pubObject->getId()], urlLocaleForPage: ''), ENT_COMPAT, 'UTF-8')));
$node->setAttribute('format', 'html');

// Keywords
$supportedLocales = $context->getSupportedFormLocales();
/** @var SubmissionKeywordDAO */
$dao = DAORegistry::getDAO('SubmissionKeywordDAO');
$articleKeywords = $dao->getKeywords($publication->getId(), $supportedLocales);
$articleKeywords = SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales);

if (array_key_exists($publication->getData('locale'), $articleKeywords)) {
$keywordsInArticleLocale = $articleKeywords[$publication->getData('locale')];
unset($articleKeywords[$publication->getData('locale')]);
$articleKeywords = array_merge([$publication->getData('locale') => $keywordsInArticleLocale], $articleKeywords);
}

foreach ($articleKeywords as $locale => $keywords) {
$keywordsNode = $doc->createElement('keywords');
$keywordsNode->setAttribute('language', LocaleConversion::get3LetterIsoFromLocale($locale));
Expand Down
10 changes: 4 additions & 6 deletions plugins/metadata/dc11/filter/Dc11SchemaArticleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
use PKP\metadata\MetadataDescription;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

class Dc11SchemaArticleAdapter extends MetadataDataObjectAdapter
{
Expand Down Expand Up @@ -90,12 +90,10 @@ public function &extractMetadataFromDataObject(&$article)
}

// Subject
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */
$supportedLocales = $journal->getSupportedFormLocales();
$subjects = array_merge_recursive(
(array) $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales),
(array) $submissionSubjectDao->getSubjects($publication->getId(), $supportedLocales)
SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales),
SubmissionSubjectVocab::getSubjects($publication->getId(), $supportedLocales)
);
$this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects);

Expand Down
23 changes: 1 addition & 22 deletions plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
use PKP\galley\Collector as GalleyCollector;
use PKP\galley\Galley;
use PKP\oai\OAIRecord;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\tests\PKPTestCase;

#[CoversClass(OAIMetadataFormat_DC::class)]
Expand All @@ -58,7 +56,7 @@ class OAIMetadataFormat_DCTest extends PKPTestCase
*/
protected function getMockedDAOs(): array
{
return [...parent::getMockedDAOs(), 'OAIDAO', 'SubmissionSubjectDAO', 'SubmissionKeywordDAO'];
return [...parent::getMockedDAOs(), 'OAIDAO'];
}

/**
Expand Down Expand Up @@ -263,25 +261,6 @@ public function testToXml()
->willReturn(LazyCollection::wrap($galleys));
app()->instance(GalleyCollector::class, $mockGalleyCollector);

// Mocked DAO to return the subjects
$submissionSubjectDao = $this->getMockBuilder(SubmissionSubjectDAO::class)
->onlyMethods(['getSubjects'])
->getMock();
$submissionSubjectDao->expects($this->any())
->method('getSubjects')
->willReturn(['en' => ['article-subject', 'article-subject-class']]);
DAORegistry::registerDAO('SubmissionSubjectDAO', $submissionSubjectDao);

// Mocked DAO to return the keywords
$submissionKeywordDao = $this->getMockBuilder(SubmissionKeywordDAO::class)
->onlyMethods(['getKeywords'])
->getMock();
$submissionKeywordDao->expects($this->any())
->method('getKeywords')
->willReturn(['en' => ['article-keyword']]);
DAORegistry::registerDAO('SubmissionKeywordDAO', $submissionKeywordDao);


//
// Test
//
Expand Down
11 changes: 4 additions & 7 deletions plugins/oaiMetadataFormats/rfc1807/OAIMetadataFormat_RFC1807.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

use APP\core\Application;
use APP\issue\IssueAction;
use PKP\db\DAORegistry;
use PKP\oai\OAIMetadataFormat;
use PKP\oai\OAIUtils;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

class OAIMetadataFormat_RFC1807 extends OAIMetadataFormat
{
Expand Down Expand Up @@ -68,11 +67,9 @@ public function toXml($record, $format = null)

// Subject
$supportedLocales = $journal->getSupportedFormLocales();
$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */
$subjects = array_merge_recursive(
(array) $submissionKeywordDao->getKeywords($publication->getId(), $supportedLocales),
(array) $submissionSubjectDao->getSubjects($article->getCurrentPublication()->getId(), $supportedLocales)
SubmissionKeywordVocab::getKeywords($publication->getId(), $supportedLocales),
SubmissionSubjectVocab::getSubjects($article->getCurrentPublication()->getId(), $supportedLocales)
);
$subject = $subjects[$journal->getPrimaryLocale()] ?? '';

Expand Down
17 changes: 6 additions & 11 deletions plugins/reports/articles/ArticleReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@

use APP\decision\Decision;
use APP\facades\Repo;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\plugins\ReportPlugin;
use PKP\security\Role;
use PKP\stageAssignment\StageAssignment;
use PKP\submission\PKPSubmission;
use PKP\submission\SubmissionAgencyVocab;
use PKP\submission\SubmissionDisciplineDAO;
use PKP\submission\SubmissionKeywordDAO;
use PKP\submission\SubmissionSubjectDAO;
use PKP\submission\SubmissionDisciplineVocab;
use PKP\submission\SubmissionKeywordVocab;
use PKP\submission\SubmissionSubjectVocab;

class ArticleReportPlugin extends ReportPlugin
{
Expand Down Expand Up @@ -85,10 +84,6 @@ public function display($args, $request)
// Add BOM (byte order mark) to fix UTF-8 in Excel
fprintf($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));

$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); /** @var SubmissionKeywordDAO $submissionKeywordDao */
$submissionSubjectDao = DAORegistry::getDAO('SubmissionSubjectDAO'); /** @var SubmissionSubjectDAO $submissionSubjectDao */
$submissionDisciplineDao = DAORegistry::getDAO('SubmissionDisciplineDAO'); /** @var SubmissionDisciplineDAO $submissionDisciplineDao */

$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$context->getId()])
->getMany()
Expand Down Expand Up @@ -158,9 +153,9 @@ public function display($args, $request)
$sectionTitles[$sectionId] = $section->getLocalizedTitle();
}

$subjects = $submissionSubjectDao->getSubjects($submission->getCurrentPublication()->getId());
$disciplines = $submissionDisciplineDao->getDisciplines($submission->getCurrentPublication()->getId());
$keywords = $submissionKeywordDao->getKeywords($submission->getCurrentPublication()->getId());
$subjects = SubmissionSubjectVocab::getSubjects($submission->getCurrentPublication()->getId());
$disciplines = SubmissionDisciplineVocab::getDisciplines($submission->getCurrentPublication()->getId());
$keywords = SubmissionKeywordVocab::getKeywords($submission->getCurrentPublication()->getId());
$agencies = SubmissionAgencyVocab::getAgencies($submission->getCurrentPublication()->getId());

// Store the submission results
Expand Down
40 changes: 15 additions & 25 deletions tools/cleanReviewerInterests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file tools/cleanReviewerInterests.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ReviewerInterestsDeletionTool
Expand All @@ -17,10 +17,10 @@
require(dirname(__FILE__) . '/bootstrap.php');

use PKP\cliTool\CommandLineTool;
use PKP\controlledVocab\ControlledVocabDAO;
use PKP\controlledVocab\ControlledVocab;
use PKP\controlledVocab\ControlledVocabEntryDAO;
use PKP\db\DAORegistry;
use PKP\user\InterestDAO;
use PKP\user\UserInterest;

class ReviewerInterestsDeletionTool extends CommandLineTool
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public function usage()
/**
* Remove user interests that are not referenced by any user account
*/
public function execute()
public function execute(): void
{
$orphans = $this->_getOrphanVocabInterests();
if (!count($orphans)) {
Expand All @@ -69,7 +69,7 @@ public function execute()
switch ($command) {
case '--show':
$interests = array_map(function ($entry) {
return $entry->getData(InterestDAO::CONTROLLED_VOCAB_INTEREST);
return $entry->getData(UserInterest::CONTROLLED_VOCAB_INTEREST);
}, $orphans);
echo "Below are the user interests that are not referenced by any user account.\n";
echo "\t" . join("\n\t", $interests) . "\n";
Expand All @@ -96,33 +96,23 @@ public function execute()
*
* @return array array of ControlledVocabEntry object
*/
protected function _getOrphanVocabInterests()
protected function _getOrphanVocabInterests(): array
{
/** @var InterestDAO */
$interestDao = DAORegistry::getDAO('InterestDAO');
/** @var ControlledVocabDAO */
$vocabDao = DAORegistry::getDAO('ControlledVocabDAO');
/** @var ControlledVocabEntryDAO */
/** @var ControlledVocabEntryDAO $vocabEntryDao */
$vocabEntryDao = DAORegistry::getDAO('ControlledVocabEntryDAO');

$interestVocab = $vocabDao->getBySymbolic(InterestDAO::CONTROLLED_VOCAB_INTEREST);
$vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->getId());
$interestVocab = ControlledVocab::withSymbolic(UserInterest::CONTROLLED_VOCAB_INTEREST)
->withAssoc(0, 0)
->first();
$vocabEntryIterator = $vocabEntryDao->getByControlledVocabId($interestVocab->id);
$vocabEntryList = $vocabEntryIterator->toArray();

// list of vocab interests in db
$allInterestVocabIds = array_map(
function ($entry) {
return $entry->getId();
},
$vocabEntryList
);
$allInterestVocabIds = array_map(fn ($entry) => $entry->getId(), $vocabEntryList);

// list of vocabs associated to users
$interests = $interestDao->getAllInterests();
$interests = UserInterest::getAllInterests();
$userInterestVocabIds = array_map(
function ($interest) {
return $interest->getId();
},
fn ($interest) => $interest->getId(),
$interests->toArray()
);

Expand Down

0 comments on commit 5db03d3

Please sign in to comment.