Can someone upgrade this Most Popular articles plugin for 3.0.2

Can some upgrade this plugin for 3.0.2 OJS?

Hi @ctgraham

Iā€™m trying to create a new plugin, using this one as a baseline. Iā€™ll called as PopularArticlesWithFiles.

At this time, trying to understand how the PouplarArticles works and maybe in a near future, Iā€™ll try to implement it in 3.x versionā€¦

I already identified how to get the info in OJS. They are in article_galleys, in my case when label = ā€˜FILESā€™.

The query behind the PopularArticles plugin is:

SELECT submission_id, SUM(metric) AS metric FROM metrics WHERE context_id = ā€˜1ā€™ AND assoc_type = 257 AND metric_type IN (ā€˜ojs::counterā€™, ā€˜ojs::legacyDefaultā€™) GROUP BY submission_id ORDER BY metric DESC LIMIT 0,10

My goal at this time is to retrieve a result like this:

SELECT submission_id, SUM(metric) AS metric FROM metrics LEFT JOIN article_galleys ON (submission_id = article_id) WHERE context_id = ā€˜1ā€™ AND assoc_type = 257 AND metric_type IN (ā€˜ojs::counterā€™, ā€˜ojs::legacyDefaultā€™) and label = ā€˜FILESā€™ GROUP BY submission_id ORDER BY metric DESC LIMIT 0,10

What do you recommend to achieve that goal? Do you think it would be necessary to change any core code or can I get the info I need by just adjust it in the plugin?

Any help Iā€™ll appreciate.

The code responsible for generating that current query is here:

The way that the statistics framework is currently setup, there isnā€™t really a way to identify this kind of ā€œcustom dimensionā€ without a lot of customization in the core statistics framework. There ought to be, and I think @bozana and @NateWr might have interest in helping to think though the implications for future work in 3.x.

For your immediate goal, if the journal is small enough, I would probably implement this within the iteration across each statistics record:

In the call to getMetrics() we are fetching all article metrics, order by the metric (in descending order).

In the foreach iteration weā€™re fetching the article object for each of these. You could further inspect the $article to decide whether or not to add it to the $articles[] array (only adding the ones which an article galley with the ā€œFILESā€ label).

This would not scale well for large numbers of articles, though, which is why I prefaced this with ā€œif your journal is small enoughā€.

1 Like

Also note that @ajnyga has done relevant work here as it relates to 3.x:

1 Like

Hi @sergiobm and @ctgraham,

Maybe this way would work too:
ā€“ first get the wished article IDs i.e. those having label ā€œFILESā€ in their galleys and put them in an array (lets say $arrayOfArticleIds).
ā€“ then use the additional filter element (STATISTICS_DIMENSION_SUBMISSION_ID => $arrayOfArticleIds) i.e. the 3rd parameter for the function getMetrics would be:

array(STATISTICS_DIMENSION_CONTEXT_ID => $journalId, STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_ARTICLE, STATISTICS_DIMENSION_SUBMISSION_ID => $arrayOfArticleIds),

I havenā€™t tried it yet, but looking into the code I believe it should workā€¦

Best,
Bozana

2 Likes