summaryrefslogtreecommitdiff
path: root/app/Models/StatsDAO.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-31 14:45:37 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-31 14:45:37 +0100
commita97bbd9bd54c5fa56d54b3c214cf4e8af96af8b2 (patch)
tree6e83890bc1b3814a12c3b7bedc0d5944f30f507b /app/Models/StatsDAO.php
parent42fd539a1b14f883077048a35864b4294b6efe94 (diff)
parente91b72b63cd11ae3c4f59e48439e93955242c673 (diff)
Merge branch 'dev'
Conflicts: CHANGELOG README.fr.md README.md app/Controllers/feedController.php app/Controllers/indexController.php app/i18n/en.php app/i18n/fr.php app/views/helpers/view/normal_view.phtml app/views/stats/index.phtml app/views/stats/repartition.phtml constants.php p/scripts/main.js
Diffstat (limited to 'app/Models/StatsDAO.php')
-rw-r--r--app/Models/StatsDAO.php60
1 files changed, 31 insertions, 29 deletions
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
index 08dd4cd5c..80caccc49 100644
--- a/app/Models/StatsDAO.php
+++ b/app/Models/StatsDAO.php
@@ -6,18 +6,36 @@ class FreshRSS_StatsDAO extends Minz_ModelPdo {
/**
* Calculates entry repartition for all feeds and for main stream.
+ *
+ * @return array
+ */
+ public function calculateEntryRepartition() {
+ return array(
+ 'main_stream' => $this->calculateEntryRepartitionPerFeed(null, true),
+ 'all_feeds' => $this->calculateEntryRepartitionPerFeed(null, false),
+ );
+ }
+
+ /**
+ * Calculates entry repartition for the selection.
* The repartition includes:
* - total entries
* - read entries
* - unread entries
* - favorite entries
*
- * @return type
+ * @param null|integer $feed feed id
+ * @param boolean $only_main
+ * @return array
*/
- public function calculateEntryRepartition() {
- $repartition = array();
-
- // Generates the repartition for the main stream of entry
+ public function calculateEntryRepartitionPerFeed($feed = null, $only_main = false) {
+ $filter = '';
+ if ($only_main) {
+ $filter .= 'AND f.priority = 10';
+ }
+ if (!is_null($feed)) {
+ $filter .= "AND e.id_feed = {$feed}";
+ }
$sql = <<<SQL
SELECT COUNT(1) AS `total`,
COUNT(1) - SUM(e.is_read) AS `unread`,
@@ -26,27 +44,13 @@ SUM(e.is_favorite) AS `favorite`
FROM {$this->prefix}entry AS e
, {$this->prefix}feed AS f
WHERE e.id_feed = f.id
-AND f.priority = 10
-SQL;
- $stm = $this->bd->prepare($sql);
- $stm->execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $repartition['main_stream'] = $res[0];
-
- // Generates the repartition for all entries
- $sql = <<<SQL
-SELECT COUNT(1) AS `total`,
-COUNT(1) - SUM(e.is_read) AS `unread`,
-SUM(e.is_read) AS `read`,
-SUM(e.is_favorite) AS `favorite`
-FROM {$this->prefix}entry AS e
+{$filter}
SQL;
$stm = $this->bd->prepare($sql);
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $repartition['all_feeds'] = $res[0];
- return $repartition;
+ return $res[0];
}
/**
@@ -147,10 +151,9 @@ SQL;
* @return string
*/
protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) {
+ $restrict = '';
if ($feed) {
$restrict = "WHERE e.id_feed = {$feed}";
- } else {
- $restrict = '';
}
$sql = <<<SQL
SELECT DATE_FORMAT(FROM_UNIXTIME(e.date), '{$period}') AS period
@@ -179,7 +182,7 @@ SQL;
* @return integer
*/
public function calculateEntryAveragePerFeedPerHour($feed = null) {
- return $this->calculateEntryAveragePerFeedPerPeriod(1/24, $feed);
+ return $this->calculateEntryAveragePerFeedPerPeriod(1 / 24, $feed);
}
/**
@@ -210,10 +213,9 @@ SQL;
* @return integer
*/
protected function calculateEntryAveragePerFeedPerPeriod($period, $feed = null) {
+ $restrict = '';
if ($feed) {
$restrict = "WHERE e.id_feed = {$feed}";
- } else {
- $restrict = '';
}
$sql = <<<SQL
SELECT COUNT(1) AS count
@@ -237,7 +239,7 @@ SQL;
$interval_in_days = $period;
}
- return round($res['count'] / ($interval_in_days / $period), 2);
+ return $res['count'] / ($interval_in_days / $period);
}
/**
@@ -415,8 +417,8 @@ SQL;
* @return string
*/
private function convertToTranslatedJson($data = array()) {
- $translated = array_map(function ($a) {
- return Minz_Translate::t($a);
+ $translated = array_map(function($a) {
+ return _t('gen.date.' . $a);
}, $data);
return json_encode($translated);