statsController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class FreshRSS_stats_Controller extends Minz_ActionController {
  3. public function mainAction() {
  4. $this->initAction();
  5. $statsDAO = new FreshRSS_StatsDAO ();
  6. Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
  7. $this->view->repartition = $statsDAO->calculateEntryRepartition();
  8. $this->view->count = ($statsDAO->calculateEntryCount());
  9. $this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
  10. $this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
  11. $this->view->topFeed = $statsDAO->calculateTopFeed();
  12. }
  13. public function idleAction() {
  14. $this->initAction();
  15. $statsDAO = new FreshRSS_StatsDAO ();
  16. $feeds = $statsDAO->calculateFeedLastDate();
  17. $idleFeeds = array();
  18. $now = new \DateTime();
  19. $feedDate = clone $now;
  20. $lastWeek = clone $now;
  21. $lastWeek->modify('-1 week');
  22. $lastMonth = clone $now;
  23. $lastMonth->modify('-1 month');
  24. $last3Month = clone $now;
  25. $last3Month->modify('-3 month');
  26. $last6Month = clone $now;
  27. $last6Month->modify('-6 month');
  28. $lastYear = clone $now;
  29. $lastYear->modify('-1 year');
  30. foreach ($feeds as $feed) {
  31. $feedDate->setTimestamp($feed['last_date']);
  32. if ($feedDate >= $lastWeek) {
  33. continue;
  34. }
  35. if ($feedDate < $lastWeek) {
  36. $idleFeeds['last_week'][] = $feed['name'];
  37. }
  38. if ($feedDate < $lastMonth) {
  39. $idleFeeds['last_month'][] = $feed['name'];
  40. }
  41. if ($feedDate < $last3Month) {
  42. $idleFeeds['last_3_month'][] = $feed['name'];
  43. }
  44. if ($feedDate < $last6Month) {
  45. $idleFeeds['last_6_month'][] = $feed['name'];
  46. }
  47. if ($feedDate < $lastYear) {
  48. $idleFeeds['last_year'][] = $feed['name'];
  49. }
  50. }
  51. $this->view->idleFeeds = array_reverse($idleFeeds);
  52. }
  53. private function initAction() {
  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. }