mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-06 04:17:51 -05:00
* revert Fix code indentation Fix code Upgrade code to php 8.1 * fix remarques * code review * code review * code review * Apply suggestions from code review * code review * Fixes * Many remainging updates of array syntax * Lost case 'reading-list' * Uneeded PHPDoc --------- Co-authored-by: Luc Sanchez <l.sanchez-prestataire@alptis.fr> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
50 lines
956 B
PHP
50 lines
956 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
|
|
|
|
#[\Override]
|
|
protected function sqlFloor(string $s): string {
|
|
return "CAST(($s) AS INT)";
|
|
}
|
|
|
|
/**
|
|
* @return array<int,int>
|
|
*/
|
|
#[\Override]
|
|
protected function calculateEntryRepartitionPerFeedPerPeriod(string $period, ?int $feed = null): array {
|
|
if ($feed) {
|
|
$restrict = "WHERE e.id_feed = {$feed}";
|
|
} else {
|
|
$restrict = '';
|
|
}
|
|
$sql = <<<SQL
|
|
SELECT strftime('{$period}', e.date, 'unixepoch') AS period
|
|
, COUNT(1) AS count
|
|
FROM `_entry` AS e
|
|
{$restrict}
|
|
GROUP BY period
|
|
ORDER BY period ASC
|
|
SQL;
|
|
|
|
$res = $this->fetchAssoc($sql);
|
|
if ($res == null) {
|
|
return [];
|
|
}
|
|
|
|
$periodMax = match ($period) {
|
|
'%H' => 24,
|
|
'%w' => 7,
|
|
'%m' => 12,
|
|
default => 30,
|
|
};
|
|
|
|
$repartition = array_fill(0, $periodMax, 0);
|
|
foreach ($res as $value) {
|
|
$repartition[(int)$value['period']] = (int)$value['count'];
|
|
}
|
|
|
|
return $repartition;
|
|
}
|
|
}
|