4
0

StatsDAOSQLite.php 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
  3. protected function sqlFloor($s) {
  4. return "CAST(($s) AS INT)";
  5. }
  6. protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) {
  7. if ($feed) {
  8. $restrict = "WHERE e.id_feed = {$feed}";
  9. } else {
  10. $restrict = '';
  11. }
  12. $sql = <<<SQL
  13. SELECT strftime('{$period}', e.date, 'unixepoch') AS period
  14. , COUNT(1) AS count
  15. FROM `{$this->prefix}entry` AS e
  16. {$restrict}
  17. GROUP BY period
  18. ORDER BY period ASC
  19. SQL;
  20. $stm = $this->bd->prepare($sql);
  21. $stm->execute();
  22. $res = $stm->fetchAll(PDO::FETCH_NAMED);
  23. $repartition = array();
  24. foreach ($res as $value) {
  25. $repartition[(int) $value['period']] = (int) $value['count'];
  26. }
  27. return $repartition;
  28. }
  29. }