[SOLVED] Get total journals, articles counts from database

Hi,

Our installation will be hosting a couple of journals.
We’ll want the best way to get a quick count (total for all journals) of the following, to display on our homepage to visitors.

  1. total journals hosted.
  2. total articles (submitted/published).
    etc. (we’d probably figure out the rest, if we can get the first two).

I checked the Stats & Reports page, JournalStatisticsDAO.inc.php, and StatisticsHandler.inc.php. It seems, I think (I might be 100% wrong on this one), that what’s being implemented is just for a single journal (not a net sum of all the journals).

please how do we go about getting these numbers from the database?
…or, is there a plugin already handling this, that we should know of?

Thanks

Sam

Hi @samice,

Those numbers would be easy and quick to fetch from the database with a couple of simple queries:

SELECT COUNT(*) FROM journals;
SELECT COUNT(*) FROM articles; # For total article count
SELECT COUNT(*) FROM published_articles; # For published article count (ROUGHLY, depending on your publishing process)

I would suggest adding those queries to JournalStatisticsDAO, and adding a bit of code e.g. to pages/index/IndexHandler.inc.php to assign the results to the homepage template. Then, somewhere in templates/index/, add the mark-up to display the numbers.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Thank you @asmecher for the detailed reply. I’ll give this a shot asap.

Thank you @asmecher! what you suggested worked. I created small methods in JournalStatisticsDAO to handle the queries, and assigned my variables in the display method of the template manager (I finally decided to display all the information site-wide in footer.tpl), like so:

$allJournalStatsDAO =& DAORegistry::getDAO('JournalStatisticsDAO');
$this->assign('totalJournalsCount', $allJournalStatsDAO->getTotalJournalsHosted());
$this->assign('totalArticlesCount', $allJournalStatsDAO->getTotalArticlesSubmitted());

everything works fine, for now :slight_smile:

thanks again.