StatsDAOSQLite.php 1023 B

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