statsController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 firstAction() {
  54. if (!$this->view->loginOk) {
  55. Minz_Error::error(
  56. 403, array('error' => array(Minz_Translate::t('access_denied')))
  57. );
  58. }
  59. Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');
  60. }
  61. }