diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a7dfcf2..59ef3c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ variables: include: - project: 'documentacao-e-tarefas/modelosparaintegracaocontinua' - ref: main + ref: stable-3_3_0 file: - 'templates/groups/pkp_plugin.yml' - - 'templates/groups/ojs_plugins_cypress_tests_model.yml' \ No newline at end of file + - 'templates/groups/ojs/cypress_tests.yml' \ No newline at end of file diff --git a/KeywordCloudBlockPlugin.inc.php b/KeywordCloudBlockPlugin.inc.php index 58def49..6c98211 100644 --- a/KeywordCloudBlockPlugin.inc.php +++ b/KeywordCloudBlockPlugin.inc.php @@ -51,6 +51,22 @@ public function getContents($templateMgr, $request = null) } $locale = AppLocale::getLocale(); + $primaryLocale = AppLocale::getPrimaryLocale(); + + $keywords = $this->getCachedKeywords($context, $locale); + if ($keywords == '[]') { + $keywords = $this->getCachedKeywords($context, $primaryLocale); + } + + $templateMgr->addJavaScript('d3', 'https://d3js.org/d3.v4.js'); + $templateMgr->addJavaScript('d3-cloud', 'https://cdn.jsdelivr.net/gh/holtzy/D3-graph-gallery@master/LIB/d3.layout.cloud.js'); + + $templateMgr->assign('keywords', $keywords); + return parent::getContents($templateMgr, $request); + } + + private function getCachedKeywords($context, $locale) + { $cacheManager = CacheManager::getManager(); $cache = $cacheManager->getFileCache( $context->getId(), @@ -58,42 +74,44 @@ public function getContents($templateMgr, $request = null) [$this, 'cacheDismiss'] ); - $keywords =& $cache->getContents(); + $keywords = & $cache->getContents(); $currentCacheTime = time() - $cache->getCacheTime(); + if ( + ($keywords && $keywords != '[]') + && $currentCacheTime < TWO_DAYS_SECONDS + ) { + return $keywords; + } + if ($currentCacheTime > TWO_DAYS_SECONDS) { $cache->flush(); - $cache->setEntireCache($this->getKeywordsJournal($context->getId())); - } elseif ($keywords == "[]") { - $cache->setEntireCache($this->getKeywordsJournal($context->getId())); } - $templateMgr->addJavaScript('d3', 'https://d3js.org/d3.v4.js'); - $templateMgr->addJavaScript('d3-cloud', 'https://cdn.jsdelivr.net/gh/holtzy/D3-graph-gallery@master/LIB/d3.layout.cloud.js'); + $cache->setEntireCache($this->getContextKeywords($context->getId(), $locale)); + $keywords = & $cache->getContents(); - $templateMgr->assign('keywords', $keywords); - return parent::getContents($templateMgr, $request); + return $keywords; } - public function getKeywordsJournal($journalId) + private function getContextKeywords($contextId, $locale) { $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); $submissionsIterator = Services::get('submission')->getMany([ - 'contextId' => $journalId, + 'contextId' => $contextId, 'status' => STATUS_PUBLISHED, ]); $allKeywords = array(); - $currentLocale = AppLocale::getLocale(); foreach ($submissionsIterator as $submission) { $publications = $submission->getPublishedPublications(); foreach ($publications as $publication) { - $publicationKeywords = $submissionKeywordDao->getKeywords($publication->getId(), array($currentLocale)); + $publicationKeywords = $submissionKeywordDao->getKeywords($publication->getId(), array($locale)); if (count($publicationKeywords) > 0) { - $allKeywords = array_merge($allKeywords, $publicationKeywords[$currentLocale]); + $allKeywords = array_merge($allKeywords, $publicationKeywords[$locale]); } } } diff --git a/version.xml b/version.xml index cc25405..1f9fbc5 100644 --- a/version.xml +++ b/version.xml @@ -13,8 +13,8 @@ keywordCloud plugins.blocks - 1.1.1.0 - 2023-08-10 + 1.2.0.0 + 2024-10-14 1 KeywordCloudBlockPlugin