/** * Imports the given article's statistics * @param int $oldId Old ID of the article * @param int $newId New ID of the article * @throws \Doctrine\DBAL\DBALException */ public function importArticleStatistic($oldId, $newId) { $article = $this->em->getRepository('OjsJournalBundle:Article')->find($newId); if (!$article) { $this->consoleOutput->writeln("Couldn't find #" . $newId . " on the new database."); return; } $this->consoleOutput->writeln("Reading view statistics for #" . $oldId . "..."); $viewStatsSql = "SELECT DATE(view_time) AS date, COUNT(*) as view FROM " . "article_view_stats WHERE article_id = :id GROUP BY DATE(view_time)"; $viewStatsStatement = $this->dbalConnection->prepare($viewStatsSql); $viewStatsStatement->bindValue('id', $oldId); $viewStatsStatement->execute(); $this->consoleOutput->writeln("Reading download statistics for #" . $oldId . "..."); $downloadStatsSql = "SELECT DATE(download_time) AS date, COUNT(*) as download FROM " . "article_download_stats WHERE article_id = :id GROUP BY DATE(download_time)"; $downloadStatsStatement = $this->dbalConnection->prepare($downloadStatsSql); $downloadStatsStatement->bindValue('id', $oldId); $downloadStatsStatement->execute(); $pkpViewStats = $viewStatsStatement->fetchAll(); $pkpDownloadStats = $downloadStatsStatement->fetchAll(); foreach ($pkpViewStats as $stat) { $articleFileStatistic = new ArticleStatistic(); $articleFileStatistic->setArticle($article); $articleFileStatistic->setDate(DateTime::createFromFormat('Y-m-d', $stat['date'])); $articleFileStatistic->setView($stat['view']); $this->em->persist($articleFileStatistic); } if (!$article->getArticleFiles()->isEmpty()) { foreach ($pkpDownloadStats as $stat) { $articleFileStatistic = new ArticleFileStatistic(); $articleFileStatistic->setArticleFile($article->getArticleFiles()->first()); $articleFileStatistic->setDate(DateTime::createFromFormat('Y-m-d', $stat['date'])); $articleFileStatistic->setDownload($stat['download']); $this->em->persist($articleFileStatistic); } } $this->em->flush(); }
public function onArticleFileDownload(DownloadArticleFileEvent $event) { $stat = $this->em->getRepository('OjsAnalyticsBundle:ArticleFileStatistic')->findOneBy(['date' => new \DateTime(), 'articleFile' => $event->getArticleFile()]); if (!$stat) { $stat = new ArticleFileStatistic(); $stat->setDate(new \DateTime()); $stat->setArticleFile($event->getArticleFile()); $stat->setDownload(1); } else { $stat->setDownload($stat->getDownload() + 1); } $this->em->persist($stat); $this->em->flush($stat); }
public function onArticleFileDownload(DownloadArticleFileEvent $event) { $articleFile = $event->getArticleFile(); $article = $event->getArticleFile()->getArticle(); $journal = $article->getJournal(); $stat = $this->em->getRepository('OjsAnalyticsBundle:ArticleFileStatistic')->findOneBy(['date' => new \DateTime(), 'articleFile' => $articleFile]); if (!$stat) { $stat = new ArticleFileStatistic(); $stat->setDate(new \DateTime()); $stat->setArticleFile($articleFile); $stat->setDownload(1); } else { $stat->setDownload($stat->getDownload() + 1); } $article->increaseDownloadCount(); $journal->increaseDownloadCount(); $this->em->persist($journal); $this->em->persist($stat); $this->em->flush(); }
public function onArticleFileDownload(DownloadArticleFileEvent $event) { $request = $this->requestStack->getMasterRequest(); $session = $request->getSession(); $articleFile = $event->getArticleFile(); $sessionKey = 'download_article_file_' . $articleFile->getId(); if ($session->has($sessionKey)) { return; } else { $session->set($sessionKey, 1); } $article = $event->getArticleFile()->getArticle(); $journal = $article->getJournal(); $stat = $this->em->getRepository('OjsAnalyticsBundle:ArticleFileStatistic')->findOneBy(['date' => new \DateTime(), 'articleFile' => $articleFile]); if (!$stat) { $stat = new ArticleFileStatistic(); $stat->setDate(new \DateTime()); $stat->setArticleFile($articleFile); $stat->setDownload(1); } else { $stat->setDownload($stat->getDownload() + 1); } $article->increaseDownloadCount(); $journal->increaseDownloadCount(); $this->em->persist($journal); $this->em->persist($stat); $this->em->flush(); }