Retrieving Most Viewed Articles and Their Author Names


#1

Hello,

Following this block plugin as an example I was able to retrieve a list of most view articles:

However, my requirements include displaying the author’s name instead of the journalName. This is where my difficulty starts.
The array $resultMetrics returned by the block component only contains [journalPath, journalName, articleId, articleTitle, metric].
I’m aware that I can use the articleId to find the authorId and name by searching through the DB, but I’m not clear on how to do so. I’m still very new to the OJS system.

Any advice would be appreciated.


#2

You have access to the Article object courtesy of:

Because an Article is a Submission, you also have access to super handy methods like getFirstAuthor(), getAuthorString(), getShortAuthorString():

Choose your favorite and add it into the $articles[] array.


#3

Thanks. I was stuck at attempting to get the author string and was using getAuthors():
$articles[$resultRow['submission_id']]['articleAuthors'] = $article->getAuthors();

instead of getAuthorString().
I’m able to display the journal author now.