4
0

StatsDAOSQLite.php 909 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
  3. /**
  4. * Calculates entry count per day on a 30 days period.
  5. * Returns the result as a JSON string.
  6. *
  7. * @return string
  8. */
  9. public function calculateEntryCount() {
  10. $count = $this->initEntryCountArray();
  11. $period = parent::ENTRY_COUNT_PERIOD;
  12. // Get stats per day for the last 30 days
  13. $sql = <<<SQL
  14. SELECT round(julianday(e.date, 'unixepoch') - julianday('now')) AS day,
  15. COUNT(1) AS count
  16. FROM {$this->prefix}entry AS e
  17. WHERE strftime('%Y%m%d', e.date, 'unixepoch')
  18. BETWEEN strftime('%Y%m%d', 'now', '-{$period} days')
  19. AND strftime('%Y%m%d', 'now', '-1 day')
  20. GROUP BY day
  21. ORDER BY day ASC
  22. SQL;
  23. $stm = $this->bd->prepare($sql);
  24. $stm->execute();
  25. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  26. foreach ($res as $value) {
  27. $count[(int)$value['day']] = (int) $value['count'];
  28. }
  29. return $this->convertToSerie($count);
  30. }
  31. }