Skip to content

Commit

Permalink
Merge branch 'emptyKeywords_3_3_0-902' into 'stable-3_3_0'
Browse files Browse the repository at this point in the history
Exibe palavras chave do idioma principal quando as palavras chave do idioma atual estiverem vazias

See merge request softwares-pkp/plugins_ojs/keywordCloud!7
  • Loading branch information
thiagolepidus committed Oct 14, 2024
2 parents 33ee9eb + 086d035 commit c31aaa5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
- 'templates/groups/ojs/cypress_tests.yml'
44 changes: 31 additions & 13 deletions KeywordCloudBlockPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,49 +51,67 @@ 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(),
'keywords_' . $locale,
[$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]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<version>
<application>keywordCloud</application>
<type>plugins.blocks</type>
<release>1.1.1.0</release>
<date>2023-08-10</date>
<release>1.2.0.0</release>
<date>2024-10-14</date>
<lazy-load>1</lazy-load>
<class>KeywordCloudBlockPlugin</class>
</version>

0 comments on commit c31aaa5

Please sign in to comment.