public function generateArticleViewsData($dates = null, Journal $journal = null) { $whereDate = ''; if ($dates) { $today = $dates[0]; $lastMonthToday = end($dates); $whereDate = "AND statistic.date BETWEEN '" . $lastMonthToday . "' AND '" . $today . "' "; } $journalWhereQuery = ' '; if ($journal) { $journalWhereQuery = 'AND article.journal_id = ' . $journal->getId() . ' '; } $sql = "SELECT article_translations.title, SUM(statistic.view) as sum_view,journal.slug,statistic.article_id FROM statistic " . "join article on statistic.article_id = article.id " . "join journal on article.id = journal.id " . "join article_translations on article.id = article_translations.translatable_id " . "and article_translations.locale = '" . $this->locale . "' " . "WHERE article_id IS NOT NULL " . $whereDate . $journalWhereQuery . "group by article_id,article_translations.title,journal.slug " . "ORDER BY sum_view DESC " . "LIMIT 20; "; $rsm = new ResultSetMapping(); $rsm->addScalarResult('title', 'title'); $rsm->addScalarResult('sum_view', 'view'); $rsm->addScalarResult('slug', 'slug'); $rsm->addScalarResult('article_id', 'id'); $query = $this->manager->createNativeQuery($sql, $rsm); $results = $query->getResult(); return $results; }
/** * Arranges statistics * @return array */ private function createStats() { $generator = new GraphDataGenerator($this->getDoctrine()->getManager()); $journal = $this->get('ojs.journal_service')->getSelectedJournal(); $lastMonth = ['x']; for ($i = 0; $i < 30; $i++) { $lastMonth[] = date($this::DATE_FORMAT, strtotime('-' . $i . ' days')); } $slicedLastMonth = array_slice($lastMonth, 1); $articles = $this->getDoctrine()->getRepository('OjsJournalBundle:Article')->findAll(); $issues = $this->getDoctrine()->getRepository('OjsJournalBundle:Issue')->findAll(); $json = ['dates' => $lastMonth, 'articleViews' => $generator->generateArticleBarChartData($articles, $slicedLastMonth), 'issueFileDownloads' => $generator->generateIssueFilePieChartData($issues, $slicedLastMonth), 'articleFileDownloads' => $generator->generateArticleFilePieChartData($articles, $slicedLastMonth)]; $data = ['stats' => json_encode($json), 'articles' => $generator->generateArticleViewsData($articles), 'issueFiles' => $generator->generateIssueFileDownloadsData($issues), 'articleFiles' => $generator->generateArticleFileDownloadsData($articles), 'articlesMonthly' => $generator->generateArticleViewsData($articles, $slicedLastMonth), 'issueFilesMonthly' => $generator->generateIssueFileDownloadsData($issues, $slicedLastMonth), 'articleFilesMonthly' => $generator->generateArticleFileDownloadsData($articles, $slicedLastMonth)]; return $data; }