/**
* @param Journal $journal
* @return array
*/
public function journalsArticlesStats(Journal $journal)
{
$object_view = $this->dm->getRepository('OjsAnalyticsBundle:ObjectViews');
$stats = [];
$affetted_articles = [];
foreach ($journal->getArticles() as $article) {
$articleStats = $object_view->findBy(['entity' => 'article', 'objectId' => $article->getId()]);
if (!$articleStats) {
continue;
}
foreach ($articleStats as $stat) {
$dateKey = $stat->getLogDate()->format("d-M-Y");
$stats[$dateKey][$article->getId()] = ['hit' => isset($stats[$dateKey][$article->getId()]['hit']) ? $stats[$dateKey][$article->getId()]['hit'] + 1 : 1, 'title' => $article->getTitle()];
}
$affetted_articles[] = ['id' => $article->getId(), 'title' => $article->getTitle()];
}
foreach ($stats as $date => $stat) {
foreach ($affetted_articles as $article) {
if (!isset($stats[$date][$article['id']])) {
$stats[$date][$article['id']] = ['hit' => 0, 'title' => $article['title']];
}
}
}
ksort($stats);
return ['stats' => $stats, 'articles' => $affetted_articles];
}