Most read article plugin for OJS 3.1.1.2

Hi @ajnyga, thank you for this plugin, we’ve been using it in our 3.1 installation since last year.

I was trying to make it compatible with the 3.2, but since I am only an OJS enthusiast without any coding background probably the modification below will need more works. Nevertheless, I can confirm that the modification of your codes below are working in our local installation.

// Start Most read
public function loadTemplateData($hookName, $args) {
$templateMgr = $args[0];
$request = Application::get()->getRequest();
$context = $request->getContext();
$metricsDao = DAORegistry::getDAO(‘MetricsDAO’);
$cacheManager = CacheManager::getManager();
$cache = $cacheManager->getCache(‘mostread’, $context->getId(), array($this, ‘_cacheMiss’));
$daysToStale = 1;
$cachedMetrics = false;
if (time() - $cache->getCacheTime() > 60 * 60 * 24 * $daysToStale) {
$cachedMetrics = $cache->getContents();
$cache->flush();
}
$resultMetrics = $cache->getContents();
if (!$resultMetrics && $cachedMetrics) {
$resultMetrics = $cachedMetrics;
$cache->setEntireCache($cachedMetrics);
} elseif (!$resultMetrics) {
$cache->flush();
}
$templateMgr->assign(‘resultMetrics’, $resultMetrics);
}
// End Most read
/**
* Set cache
* @param $cache object
/
function _cacheMiss($cache) {
$metricsDao = DAORegistry::getDAO(‘MetricsDAO’);
$submissionDao = DAORegistry::getDAO(‘SubmissionDAO’); /
@var $submissionDao SubmissionDAO */
$publishedArticles = Services::get(‘submission’)->getMany([
‘status’ => STATUS_PUBLISHED,
‘count’ => 5000, // large upper limit
]);
//
$journalDao = DAORegistry::getDAO(‘JournalDAO’);
$request = Application::get()->getRequest();
$context = $request->getContext();
$mostReadDays = (int) $this->getSetting($context->getId(), ‘mostReadDays’);
if (empty($mostReadDays)){
$mostReadDays = 30;
}
$dayString = “-” . $mostReadDays . " days";
$daysAgo = date(‘Ymd’, strtotime($dayString));
$currentDate = date(‘Ymd’);
$filter = array(
STATISTICS_DIMENSION_CONTEXT_ID => $context->getId(),
STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_SUBMISSION_FILE,
);
$filter[STATISTICS_DIMENSION_DAY][‘from’] = $daysAgo;
$filter[STATISTICS_DIMENSION_DAY][‘to’] = $currentDate;
$orderBy = array(STATISTICS_METRIC => STATISTICS_ORDER_DESC);
$column = array(
STATISTICS_DIMENSION_SUBMISSION_ID,
);
import(‘lib.pkp.classes.db.DBResultRange’);
$dbResultRange = new DBResultRange(7);
$metricsDao = DAORegistry::getDAO(‘MetricsDAO’);
$result = $metricsDao->getMetrics(OJS_METRIC_TYPE_COUNTER, $column, $filter, $orderBy, $dbResultRange);
foreach ($result as $resultRecord) {
$submissionId = $resultRecord[STATISTICS_DIMENSION_SUBMISSION_ID];
$article = $submissionDao->getById($submissionId);
$request = $this->getRequest(); /ok/
$journal = $request->getJournal(); /ok/
$journalId = $journal->getId(); /ok/
$articles[$submissionId][‘journalPath’] = $journal->getPath();
$articles[$submissionId][‘articleId’] = $article->getId();
$articles[$submissionId][‘articleTitle’] = $article->getLocalizedTitle();
$articles[$submissionId][‘metric’] = $resultRecord[STATISTICS_METRIC];
}
$cache->setEntireCache($articles);
return $result;
}

Request in the template

  <ul class="most_read">
  	{foreach from=$resultMetrics item=submission}
  		<li class="most_read_submission">
  		<div class="most_read_submission_title"><a href="{url >journal=$submission.journalPath page="article" op="view" path=$submission.articleId}">>{$submission.articleTitle}{if !empty($submission.articleSubTitle)} {$submission.articleSubTitle}{/if}</a></div>
  			<div class="most_read_submission_journal"><span class="fa fa-eye"></span> {$submission.metric}</div>
  		</li>
  	{/foreach}
  	</ul>

Nice, thank you!

I will try to find time to make a new release. The plugin has not been among the ones I maintain officially (have in the plugin gallery) but I think I could make an official release for the gallery.

Also worth checking is this plugin GitHub - RBoelter/mostViewed: Most Viewed Articles Plugin for OJS 3.x: Show the most-viewed and downloaded articles on the journal's homepage

2 Likes

Hi,

This plugin that makes mention @ajnyga , works perfectly in OJS version 3.1.2. I have it installed and configured to show me the most viewed articles from the last 30 days and it shows very well.

image

Unfortunately, this plugin is not block :frowning: It is not suitable for our tasks, we need a block plugin.
We continue to hope that @ajnyga can release a new version…

Hi @rkhalikov

The Most Read Articles Block by @ajnyga is definitely a block plugin. You may install it by downloading the appropriate version for your ojs version (3.1 or 3.2 version) and then, via upload a new plugin link in Website Settings → Plugins → Installed Plugins page. You also should enable it on the Website Settings → Appearance → Setup page. I use it on a journal without any problem. As far as I see, it shows download count of pdf files in a certain period of time.
Regards,

Screen Shot 2021-01-09 at 11.36.03

Screen Shot 2021-01-09 at 11.42.43

Hmm, @drugurkocak, I don’t understand where exactly I was arguing that mostRead is not a block plugin? My post was about an alternative mostViewed plugin. I know mostRead perfectly and we use it. But it is not multilingual. This problem has been confirmed by @ajnyga, but I’ve already lost all hope of a fix.

Generally speaking, the situation with plugins for different OJS lines is depressing :frowning: Well, I understand that there are official plugins from the gallery, and there are third-party solutions. Nevertheless, we, for example, cannot raise the production OJS version precisely because of the problems with numerous important and “tasty” plugins. This seems to me to be a huge strategic problem for the PKP. There are two options: either we offer an up-to-date version of a balanced platform (core + plugins), or we are talking about handicraft. Yes, with a certain popularity, but still artisanal. Perhaps @asmecher has a different point of view, but there’s little left of my past OJS-optimism today. And now it is very difficult for me to justify OJS as a strategically correct choice for scientific publishing houses…

1 Like

Hi @rkhalikov

I see It was my misunderstanding. Actually, since you haven’t told name of any plugin, I thought the discussion was about Most Read Plugin by looking at the topic.

While Most Read Articles plugin displays “pdf download count”, Most Viewed Plugin displays sum of “article read count” and “pdf download count”.
After dealing with the article statistics for a while, I decided that they weren’t so much important :slight_smile:
Regards,
Screen Shot 2021-01-09 at 22.42.05

I have a question, can we call this most read block plugin in places other than side bar?

I do in my home page as you did in TsvSite, but its not working for me.

@ drugurkocak, @ajnyga

I am using health science theme, (I modified the theme for appearance)

shareit.joinjet.org/ojs

I found a solution my self,

By calling the hook, and enable only the most read plugin - and with some css, i got this,

shareit.joinjet.org/ojs

{call_hook name=“Templates::Common::Sidebar”}

1 Like