statsController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $now = new \DateTime();
  17. $feedDate = clone $now;
  18. $lastWeek = clone $now;
  19. $lastWeek->modify('-1 week');
  20. $lastMonth = clone $now;
  21. $lastMonth->modify('-1 month');
  22. $last3Month = clone $now;
  23. $last3Month->modify('-3 month');
  24. $last6Month = clone $now;
  25. $last6Month->modify('-6 month');
  26. $lastYear = clone $now;
  27. $lastYear->modify('-1 year');
  28. foreach ($feeds as $feed) {
  29. $feedDate->setTimestamp($feed['last_date']);
  30. if ($feedDate >= $lastWeek) {
  31. continue;
  32. }
  33. if ($feedDate < $lastWeek) {
  34. $idleFeeds['last_week'][] = $feed['name'];
  35. }
  36. if ($feedDate < $lastMonth) {
  37. $idleFeeds['last_month'][] = $feed['name'];
  38. }
  39. if ($feedDate < $last3Month) {
  40. $idleFeeds['last_3_month'][] = $feed['name'];
  41. }
  42. if ($feedDate < $last6Month) {
  43. $idleFeeds['last_6_month'][] = $feed['name'];
  44. }
  45. if ($feedDate < $lastYear) {
  46. $idleFeeds['last_year'][] = $feed['name'];
  47. }
  48. }
  49. $this->view->idleFeeds = array_reverse($idleFeeds);
  50. }
  51. public function firstAction() {
  52. if (!$this->view->loginOk) {
  53. Minz_Error::error(
  54. 403, array('error' => array(Minz_Translate::t('access_denied')))
  55. );
  56. }
  57. Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');
  58. }
  59. }