Can some upgrade this plugin for 3.0.2 OJS?
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).
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”.
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…