statsController.php 3.0 KB

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