Dear PKP Support Team,
I hope this message finds you well.
I am currently working with OJS 3.5.0.0 and would like to inquire about the best practices or recommended methods to display DOI , abstract view counts , and PDF download statistics directly on each article’s page (e.g., in article_summary.tpl). While I was able to achieve this customization in OJS 3.3.0.14 by editing IssueHandler.php and article_summary.tpl, I’ve found that the same approach no longer works in version 3.5.0.0.
For the DOI, I managed to resolve the issue by copying the relevant code from article_details.tpl into article_summary.tpl. However, I am unsure how to retrieve and display the number of abstract views and PDF downloads in the updated version. I would greatly appreciate any guidance, documentation, or code examples related to this.
Please note that I am not a professional developer or programmer. I have only learned a little bit about OJS customization through self-study and trial-and-error while managing our journal. Therefore, any explanation or solution in a simplified or step-by-step manner would be extremely helpful.
Thank you very much for your time and support.
Best regards,
deejournal
Screenshots
1 Like
Please share the code with the community? So we can look into the issue.
I used this code in version 3.3.0-14, and tried it in 3.5.0-0, but it produced no result.
for IssueHandler.php (DOI)
$pubIdPlugins = PluginRegistry::loadCategory(‘pubIds’, true);
$templateMgr->assign(‘pubIdPlugins’, $pubIdPlugins);
for article_summary.tpl (DOI, Abstact Views, PDF Downloads)
{foreach from=$pubIdPlugins item=pubIdPlugin}
{if $issue->getPublished()}
{assign var=pubId value=$article->getStoredPubId($pubIdPlugin->getPubIdType())}
{else}
{assign var=pubId value=$pubIdPlugin->getPubId($article)}{* Preview pubId *}
{/if}
{if $pubId}
{assign var=“doiUrl” value=$pubIdPlugin->getResolvingURL($currentJournal->getId(), $pubId)|escape}
{translate key=“plugins.pubIds.doi.readerDisplayName”} :
{$doiUrl}
{/if}
{/foreach}
{translate key=“article.abstract”} Views: {$article->getViews()} , {if is_a($article, ‘PublishedArticle’)}{assign var=galleys value=$article->getGalleys()}{/if}
{if $galleys}
{foreach from=$galleys item=galley name=galleyList}
{$galley->getGalleyLabel()} Downloads: {$galley->getViews()}
{/foreach}
{/if}
tried using this too:
<?php
$metricsDao = \DAORegistry::getDAO('MetricsDAO'); // or 'PKPMetricsDAO'
foreach ($issueSubmissions as $submission) {
$submissionId = $submission->getId();
$contextId = $submission->getData('contextId');
// Abstract views
$abstractViews = 0;
$result = $metricsDao->getMetrics(
'ojs::counter',
['metric'],
[
'assoc_type' => 1048585, // ASSOC_TYPE_SUBMISSION
'assoc_id' => $submissionId,
'context_id' => $contextId,
]
);
if ($result && isset($result[0]['metric'])) {
$abstractViews = (int)$result[0]['metric'];
}
// PDF downloads
$pdfDownloads = 0;
foreach ($submission->getGalleys() as $galley) {
if (method_exists($galley, 'isPdfGalley') && $galley->isPdfGalley()) {
$pdfResult = $metricsDao->getMetrics(
'ojs::counter',
['metric'],
[
'assoc_type' => 1048594, // ASSOC_TYPE_SUBMISSION_FILE
'assoc_id' => $galley->getId(),
'context_id' => $contextId,
]
);
if ($pdfResult && isset($pdfResult[0]['metric'])) {
$pdfDownloads += (int)$pdfResult[0]['metric'];
}
}
}
$submission->getCurrentPublication()->setData('abstractViews', $abstractViews);
$submission->getCurrentPublication()->setData('pdfDownloads', $pdfDownloads);
}
This resulted in an error while loading the page.
acahya
October 23, 2025, 8:20am
5
Any Update ? for displaying into the TOC
acahya
November 7, 2025, 2:05am
6
PHP message: PHP Fatal error: Uncaught Error: Call to undefined method APP\submission\Submission::getViews() in /home/www/jom.htp.ac.id/cache/t_compile/ecff5f98702ff1f13016ec56f91cc894676856e4^7cf1cd52b8ba8108de77f197078de34b733dd394_0.app.frontendobjectsarticle_summary.tpl.php:108
I have tried to create an abstract view and download count for OJS 3.5 by making a service plugin to display the data
//The code inserted to article_summary.tpl
{get_article_views id=$article->getId()}
{get_galley_views id=$galley->getId()}
/**
* Register Smarty functions
*/
public function registerSmartyFunctions(string $hookName, array $args): bool
{
$templateMgr = $args[0];
// Register {get_article_views id=...}
$templateMgr->registerPlugin('function', 'get_article_views', function($params, $smarty) {
if (!isset($params['id'])) return 0;
return $this->service->getArticleViews((int) $params['id']);
});
// Register {get_galley_views id=...}
$templateMgr->registerPlugin('function', 'get_galley_views', function($params, $smarty) {
if (!isset($params['id'])) return 0;
return $this->service->getGalleyViews((int) $params['id']);
});
return false;
}
/**
* Get Total Views for an Article
*/
public function getArticleViews($submissionId): int
{
// 1048585 = ASSOC_TYPE_SUBMISSION
return (int) DB::table('metrics_submission')
->where('submission_id', '=', $submissionId)
->where('assoc_type', '=', 1048585)
->sum('metric');
}
/**
* Get Total Views for a Galley
*/
public function getGalleyViews($galleyId): int
{
// Query representation_id for Galley (Galley ID = representation_id)
return (int) DB::table('metrics_submission')
->where('representation_id', '=', $galleyId)
->sum('metric');
}
the result preview
deejournal:
Dear PKP Support Team,
I hope this message finds you well.
I am currently working with OJS 3.5.0.0 and would like to inquire about the best practices or recommended methods to display DOI , abstract view counts , and PDF download statistics directly on each article’s page (e.g., in article_summary.tpl). While I was able to achieve this customization in OJS 3.3.0.14 by editing IssueHandler.php and article_summary.tpl, I’ve found that the same approach no longer works in version 3.5.0.0.
For the DOI, I managed to resolve the issue by copying the relevant code from article_details.tpl into article_summary.tpl. However, I am unsure how to retrieve and display the number of abstract views and PDF downloads in the updated version. I would greatly appreciate any guidance, documentation, or code examples related to this.
Please note that I am not a professional developer or programmer. I have only learned a little bit about OJS customization through self-study and trial-and-error while managing our journal. Therefore, any explanation or solution in a simplified or step-by-step manner would be extremely helpful.
Thank you very much for your time and support.
Best regards,
deejournal
Screenshots
hainug
February 13, 2026, 10:23am
9
Based on lib\pkp\classes\plugins\ThemePlugin.php
add this code inside YourThemePlugin.php
public function getDownloadsStats($submissionId) {
$downloadsStats = $this->getAllDownloadsStats($submissionId);
return $downloadsStats['total'];
}
public function getViewsStats($submissionId) {
$viewsStats = $this->getAllViewsStats($submissionId);
return $viewsStats['total'];
}
/**
* Retrieve abstract view metrics for the given submission
*/
protected function getAllViewsStats(int $submissionId): array
{
// Gunakan cache key yang berbeda agar tidak bentrok dengan stats download
$data = Cache::remember("viewStats-{$submissionId}", 60 * 60 * 24, fn () => $this->viewStatsCacheMiss($submissionId));
$statsByMonth = [];
$totalViews = 0;
foreach ($data as $monthlyViewStats) {
[$year, $month] = explode('-', $monthlyViewStats['date']);
$month = ltrim($month, '0');
$statsByMonth[$year][$month] = $monthlyViewStats['value'];
$totalViews += $monthlyViewStats['value'];
}
return [
'data' => $statsByMonth,
'label' => __('submission.abstractViews'),
'total' => $totalViews
];
}
/**
* Callback to fill cache with submission's download usage statistics data.
*/
public function viewStatsCacheMiss(int $submissionId): array
{
$request = Application::get()->getRequest();
$submission = Repo::submission()->get($submissionId);
$params = [
'contextIds' => [$request->getContext()->getId()],
'submissionIds' => [$submissionId],
'assocTypes' => [Application::ASSOC_TYPE_SUBMISSION],
'timelineInterval' => StatisticsHelper::STATISTICS_DIMENSION_MONTH,
];
$originalPublication = $submission->getOriginalPublication();
if (!$originalPublication) {
return [];
}
if ($earliestDatePublished = $originalPublication->getData('datePublished')) {
$params['dateStart'] = $earliestDatePublished;
}
$statsService = app()->get('publicationStats'); /** @var \App\services\StatsPublicationService $statsService */
$data = $statsService->getTimeline($params['timelineInterval'], $params);
return $data;
}
In your .tpl file
{if $activeTheme->getOption('displayStats') != 'none'}
{assign var=downloadsStats value=$activeTheme->getDownloadsStats($article->getId())}
{assign var=viewsStats value=$activeTheme->getViewsStats($article->getId())}
<div class="view_totals" style="margin: 9px 0;">
<p>Abstract Views: {$viewsStats}, File Views: {$downloadsStats}</p>
</div>
{/if}
You will see the difference
acahya
February 20, 2026, 2:45am
10
Tried the code but error in :
PHP Fatal error: Uncaught Error: Class "APP\plugins\themes\ChildTheme\Cache" not found in /home/www/xxx/plugins/themes/ChildTheme/ChildThemeThemePlugin.php:183
Stack trace:
#0 /home/www/xxx/plugins/themes/ChildTheme/ChildThemeThemePlugin.php(173): APP\plugins\themes\ChildTheme\ChildThemeThemePlugin->getAllViewsStats()
#1 /home/www/xxx/cache/t_compile/bf3e6126a855b39810dc65a926442515b03636b5^7cf1cd52b8ba8108de77f197078de34b733dd394_0.app.frontendobjectsarticle_summary.tpl.php(146): APP\plugins\themes\ChildTheme\ChildThemeThemePlugin->getViewsStats()
acahya
February 20, 2026, 7:36am
11
Terimakasih Bang. now its show the metric
one problem remain, is author institution not show