1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00
freshrss_ynh/sources/app/Models/StatsDAOSQLite.php

65 lines
1.5 KiB
PHP
Raw Normal View History

2014-07-23 15:52:50 +02:00
<?php
class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
/**
* Calculates entry count per day on a 30 days period.
* Returns the result as a JSON string.
*
* @return string
*/
public function calculateEntryCount() {
$count = $this->initEntryCountArray();
$period = parent::ENTRY_COUNT_PERIOD;
// Get stats per day for the last 30 days
$sql = <<<SQL
SELECT round(julianday(e.date, 'unixepoch') - julianday('now')) AS day,
COUNT(1) AS count
FROM {$this->prefix}entry AS e
WHERE strftime('%Y%m%d', e.date, 'unixepoch')
BETWEEN strftime('%Y%m%d', 'now', '-{$period} days')
AND strftime('%Y%m%d', 'now', '-1 day')
GROUP BY day
ORDER BY day ASC
SQL;
$stm = $this->bd->prepare($sql);
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
foreach ($res as $value) {
2014-09-21 12:12:35 +02:00
$count[(int) $value['day']] = (int) $value['count'];
2014-07-23 15:52:50 +02:00
}
return $this->convertToSerie($count);
}
2014-09-21 12:12:35 +02:00
protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) {
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 {$this->prefix}entry AS e
{$restrict}
GROUP BY period
ORDER BY period ASC
SQL;
$stm = $this->bd->prepare($sql);
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_NAMED);
2014-09-27 10:10:43 +02:00
$repartition = array();
2014-09-21 12:12:35 +02:00
foreach ($res as $value) {
$repartition[(int) $value['period']] = (int) $value['count'];
}
return $this->convertToSerie($repartition);
}
2014-07-23 15:52:50 +02:00
}