StatsDAOSQLite.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
  4. #[\Override]
  5. protected function sqlFloor(string $s): string {
  6. return "CAST(($s) AS INT)";
  7. }
  8. /**
  9. * @return array<int,int>
  10. */
  11. #[\Override]
  12. protected function calculateEntryRepartitionPerFeedPerPeriod(string $period, ?int $feed = null): array {
  13. if ($feed) {
  14. $restrict = "WHERE e.id_feed = {$feed}";
  15. } else {
  16. $restrict = '';
  17. }
  18. $sql = <<<SQL
  19. SELECT strftime('{$period}', e.date, 'unixepoch') AS period
  20. , COUNT(1) AS count
  21. FROM `_entry` AS e
  22. {$restrict}
  23. GROUP BY period
  24. ORDER BY period ASC
  25. SQL;
  26. $res = $this->fetchAssoc($sql);
  27. if ($res == null) {
  28. return [];
  29. }
  30. switch ($period) {
  31. case '%H':
  32. $periodMax = 24;
  33. break;
  34. case '%w':
  35. $periodMax = 7;
  36. break;
  37. case '%m':
  38. $periodMax = 12;
  39. break;
  40. default:
  41. $periodMax = 30;
  42. }
  43. $repartition = array_fill(0, $periodMax, 0);
  44. foreach ($res as $value) {
  45. $repartition[(int)$value['period']] = (int)$value['count'];
  46. }
  47. return $repartition;
  48. }
  49. }