statsController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class FreshRSS_stats_Controller extends Minz_ActionController {
  3. public function indexAction() {
  4. $statsDAO = FreshRSS_Factory::createStatsDAO();
  5. Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
  6. $this->view->repartition = $statsDAO->calculateEntryRepartition();
  7. $this->view->count = $statsDAO->calculateEntryCount();
  8. $this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
  9. $this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
  10. $this->view->topFeed = $statsDAO->calculateTopFeed();
  11. }
  12. public function idleAction() {
  13. $statsDAO = FreshRSS_Factory::createStatsDAO();
  14. $feeds = $statsDAO->calculateFeedLastDate();
  15. $idleFeeds = array(
  16. 'last_year' => array(),
  17. 'last_6_month' => array(),
  18. 'last_3_month' => array(),
  19. 'last_month' => array(),
  20. 'last_week' => array(),
  21. );
  22. $now = new \DateTime();
  23. $feedDate = clone $now;
  24. $lastWeek = clone $now;
  25. $lastWeek->modify('-1 week');
  26. $lastMonth = clone $now;
  27. $lastMonth->modify('-1 month');
  28. $last3Month = clone $now;
  29. $last3Month->modify('-3 month');
  30. $last6Month = clone $now;
  31. $last6Month->modify('-6 month');
  32. $lastYear = clone $now;
  33. $lastYear->modify('-1 year');
  34. foreach ($feeds as $feed) {
  35. $feedDate->setTimestamp($feed['last_date']);
  36. if ($feedDate >= $lastWeek) {
  37. continue;
  38. }
  39. if ($feedDate < $lastYear) {
  40. $idleFeeds['last_year'][] = $feed;
  41. } elseif ($feedDate < $last6Month) {
  42. $idleFeeds['last_6_month'][] = $feed;
  43. } elseif ($feedDate < $last3Month) {
  44. $idleFeeds['last_3_month'][] = $feed;
  45. } elseif ($feedDate < $lastMonth) {
  46. $idleFeeds['last_month'][] = $feed;
  47. } elseif ($feedDate < $lastWeek) {
  48. $idleFeeds['last_week'][] = $feed;
  49. }
  50. }
  51. $this->view->idleFeeds = $idleFeeds;
  52. }
  53. public function repartitionAction() {
  54. $statsDAO = FreshRSS_Factory::createStatsDAO();
  55. $categoryDAO = new FreshRSS_CategoryDAO();
  56. $feedDAO = FreshRSS_Factory::createFeedDao();
  57. Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
  58. $id = Minz_Request::param ('id', null);
  59. $this->view->categories = $categoryDAO->listCategories();
  60. $this->view->feed = $feedDAO->searchById($id);
  61. $this->view->days = $statsDAO->getDays();
  62. $this->view->months = $statsDAO->getMonths();
  63. $this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id);
  64. $this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id);
  65. $this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id);
  66. $this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id);
  67. $this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id);
  68. $this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id);
  69. }
  70. public function firstAction() {
  71. if (!$this->view->loginOk) {
  72. Minz_Error::error(
  73. 403, array('error' => array(Minz_Translate::t('access_denied')))
  74. );
  75. }
  76. Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');
  77. }
  78. }