mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-14 00:07:51 -05:00
* PDO refactor * Automatic prefix when using the syntax `_tableName` * Uniformity: MySQL is now PDO::ATTR_EMULATE_PREPARES = false just like SQLite and PostgreSQL, with consequences such as only one statement per query * Use PDO methods exec(), query(), prepare() + execute() in a more efficient way * Remove auto-update SQL code for versions older than FreshRSS 1.5 (3 years old) * The name of the default category is set in PHP instead of in the DB (simplies SQL and allows changing the name according to the FreshRSS language) * Rename `->bd` to `->pdo` (less of a frenshism, and more informative) * Fix some requests, which were not compatible with MySQL prepared statements * Whitespace * Fix syntax for PostgreSQL sequences + MySQL install * Minor formatting * Fix lastInsertId for PostgreSQL * Use PHP 5.6+ const Take advantage of https://github.com/FreshRSS/FreshRSS/pull/2527 https://www.php.net/manual/en/migration56.new-features.php * A bit of forgotten PHP 5.6 simplification for cURL * Forgotten $s * Mini fix custom user config https://github.com/FreshRSS/FreshRSS/pull/2490/files#r326290346 * More work on install.php but not finished * install.php working * More cleaning of PDO in install * Even more simplification Take advantage of PDO->exec() to run multiple statements * Disallow changing the name of the default category https://github.com/FreshRSS/FreshRSS/pull/2522#discussion_r326967724
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO {
|
|
|
|
/**
|
|
* Calculates the number of article per hour of the day per feed
|
|
*
|
|
* @param integer $feed id
|
|
* @return string
|
|
*/
|
|
public function calculateEntryRepartitionPerFeedPerHour($feed = null) {
|
|
return $this->calculateEntryRepartitionPerFeedPerPeriod('hour', $feed);
|
|
}
|
|
|
|
/**
|
|
* Calculates the number of article per day of week per feed
|
|
*
|
|
* @param integer $feed id
|
|
* @return string
|
|
*/
|
|
public function calculateEntryRepartitionPerFeedPerDayOfWeek($feed = null) {
|
|
return $this->calculateEntryRepartitionPerFeedPerPeriod('day', $feed);
|
|
}
|
|
|
|
/**
|
|
* Calculates the number of article per month per feed
|
|
*
|
|
* @param integer $feed
|
|
* @return string
|
|
*/
|
|
public function calculateEntryRepartitionPerFeedPerMonth($feed = null) {
|
|
return $this->calculateEntryRepartitionPerFeedPerPeriod('month', $feed);
|
|
}
|
|
|
|
/**
|
|
* Calculates the number of article per period per feed
|
|
*
|
|
* @param string $period format string to use for grouping
|
|
* @param integer $feed id
|
|
* @return string
|
|
*/
|
|
protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) {
|
|
$restrict = '';
|
|
if ($feed) {
|
|
$restrict = "WHERE e.id_feed = {$feed}";
|
|
}
|
|
$sql = <<<SQL
|
|
SELECT extract( {$period} from to_timestamp(e.date)) AS period
|
|
, COUNT(1) AS count
|
|
FROM `_entry` AS e
|
|
{$restrict}
|
|
GROUP BY period
|
|
ORDER BY period ASC
|
|
SQL;
|
|
|
|
$stm = $this->pdo->query($sql);
|
|
$res = $stm->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
foreach ($res as $value) {
|
|
$repartition[(int) $value['period']] = (int) $value['count'];
|
|
}
|
|
|
|
return $repartition;
|
|
}
|
|
|
|
}
|