How to add most read topics in ojs 3.1?

In OJS 3.1 that function is called getPublishedArticleById (in 3.0.2 it was getPublishedArticleByArticleId)

Hello! @ajnyga, @dennisbr and @varshilmehta

I would like to be able to install this plugins in one of the boostrap child themas for OJS 3.1.0-1

Could someone make it work properly?

Can you guide me in the files that I have to modify and the codes that I should include?

Regards!

It didnt work for me.

1 Like

The code is from our site level theme plugin so the problem is probably connected to that, but without hands-on testing hard to say what the problem is. It does work fine in our case of course and is used in our production server.

I can not promise anything but I will see if I have time to do a child theme of the bootstrap theme with this addition at some point.

yo estoy tratando de crear uno a nivel de journal, para el tema bootstrap, pero me da errores 500 con algunas funciones del php, en cuanto lo solucione lo publico

1 Like

para que version de OJS tienes ese plugins.?

The code above was for 3.0.2 and the current version we use is for 3.1.0.1, but it is almost the same

puedes publicar el codigo…? para probarlo, porque el que estaba modificando para el tema bootstrap me da muchos errores en el php

It is available here: GitHub - ajnyga/tsvSite: Journal.fi site theme for OJS3
edit: but as I said, this is not a theme for a journal but for the front page of https://journal.fi

1 Like

Just fyi that I created this simple block plugin that uses the same code as my site theme.

It shows the most dowloaded articles for the last 7 days. Should be fairly easy to edit. If someone wants to make it more versatile (add some settings for the time limits, include abstract views etc.) you are of course welcome to copy the code.

1 Like

Hi @ajnyga
Instead of a block plugin, can the codes to call the most read articles in the plugin be implemented in indexJournal.tpl for example? If it can, which codes?

I want to change the range of the time, e.g. 30 days. I initially guessed to do it why changing the

		$currentDate = date('Ymd');
		$weekAgo = date('Ymd', strtotime("-1 week")); --> to "-4 week"

Is it a right method?

1 Like

It is a standard strtotime function. That should work I think. Also “4 weeks ago” should work (strtotime is a funny function) (see http://php.net/manual/en/function.strtotime.php)

1 Like

The code from getContents goes to the init function in your theme plugin. How exactly this happens depends on the theme (I can not promise that I have time to give more detailed instructions)

The _cacheMiss function you just copy to the theme plugin file.

And finally you add the code form block.tpl to the template you want. Not the exact same code of course, but at least this https://github.com/ajnyga/mostRead/blob/master/block.tpl#L12-L20

Before changing the time limit to 16 weeks, the metrics looks normal (below 50 reads) for one week. After setting to 16 weeks and back to one week, the metrics are not change. https://jurnalbeta.ac.id
How to change the number of articles shown?

The plugin creates a file cache. You have to delete the cache file to reflect the changes you make to the code.

The number of articles is in the SQL, “limit 5”

1 Like

Sorry, but is this cache stored in the server or the client?

in the server, in cache folder. The same place where all OJS file cache files are stored.

Okay I found the cache file and was able to apply the changes to the function and see the difference

Now I’m sure that my problem is failing to retrieve the author’s name for each article:
I’m editting _cacheMiss():

while (!$result->EOF) {
    $resultRow = $result->GetRowAssoc(false);
    $article = $publishedArticleDao->getById($resultRow['submission_id']);
    $journal = $journalDao->getById($article->getJournalId());
    $articles[$resultRow['submission_id']]['journalPath'] = $journal->getPath();
    $articles[$resultRow['submission_id']]['articleId'] = $article->getBestArticleId();
    $articles[$resultRow['submission_id']]['articleTitle'] = $article->getLocalizedTitle();
    $articles[$resultRow['submission_id']]['metric'] = $resultRow['metric'];
    //$articles[$resultRow['submission_id']]['articleAuthors'] = $article->getAuthors();
    $result->MoveNext();
}

… but $article->getAuthors() seems to be incorrect despite $article being a PublishedArticle.

Do you know if there’s an API reference for OJS 3 to find the function I need? I’m currently refering to OJS 2.4.8 by Doxygen.

The function is correct, but it does not return a string.

Maybe this example helps: https://github.com/pkp/ojs/blob/master/plugins/generic/googleScholar/GoogleScholarPlugin.inc.php#L65