StatsDAOSQLite.php 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 `_entry` AS e
  16. {$restrict}
  17. GROUP BY period
  18. ORDER BY period ASC
  19. SQL;
  20. $stm = $this->pdo->query($sql);
  21. $res = $stm->fetchAll(PDO::FETCH_NAMED);
  22. switch ($period) {
  23. case '%H':
  24. $periodMax = 24;
  25. break;
  26. case '%w':
  27. $periodMax = 7;
  28. break;
  29. case '%m':
  30. $periodMax = 12;
  31. break;
  32. default:
  33. $periodMax = 30;
  34. }
  35. $repartition = array_fill(0, $periodMax, 0);
  36. foreach ($res as $value) {
  37. $repartition[(int) $value['period']] = (int) $value['count'];
  38. }
  39. return $repartition;
  40. }
  41. }