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ā.
Also note that @ajnyga has done relevant work here as it relates to 3.x:
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