summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2025-07-30 19:24:53 +0300
committerAndrew Dolgov <fox@fakecake.org>2025-07-30 19:24:53 +0300
commitbc312b1205612f5bd124bd6bf9f173a9b6d98792 (patch)
tree3ee93d7e0a6304d28b0795623fba614d571c1f86 /classes
parent8b07dc8453e0d029b000d8a73ebc059f95994400 (diff)
implement special counter display when viewing by published, similar to marked
Diffstat (limited to 'classes')
-rw-r--r--classes/Counters.php19
-rw-r--r--classes/Feeds.php25
2 files changed, 41 insertions, 3 deletions
diff --git a/classes/Counters.php b/classes/Counters.php
index 613210ecc..ec6e49b70 100644
--- a/classes/Counters.php
+++ b/classes/Counters.php
@@ -35,6 +35,7 @@ class Counters {
static private function get_cat_children(int $cat_id, int $owner_uid): array {
$unread = 0;
$marked = 0;
+ $published = 0;
$cats = ORM::for_table('ttrss_feed_categories')
->where('owner_uid', $owner_uid)
@@ -42,13 +43,14 @@ class Counters {
->find_many();
foreach ($cats as $cat) {
- list ($tmp_unread, $tmp_marked) = self::get_cat_children($cat->id, $owner_uid);
+ list ($tmp_unread, $tmp_marked, $tmp_published) = self::get_cat_children($cat->id, $owner_uid);
$unread += $tmp_unread + Feeds::_get_cat_unread($cat->id, $owner_uid);
$marked += $tmp_marked + Feeds::_get_cat_marked($cat->id, $owner_uid);
+ $published += $tmp_published + Feeds::_get_cat_published($cat->id, $owner_uid);
}
- return [$unread, $marked];
+ return [$unread, $marked, $published];
}
/**
@@ -99,6 +101,7 @@ class Counters {
$sth = $pdo->prepare("SELECT fc.id,
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
+ SUM(CASE WHEN published THEN 1 ELSE 0 END) AS count_published,
(SELECT COUNT(id) FROM ttrss_feed_categories fcc
WHERE fcc.parent_cat = fc.id) AS num_children
FROM ttrss_feed_categories fc
@@ -110,6 +113,7 @@ class Counters {
SELECT 0,
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
+ SUM(CASE WHEN published THEN 1 ELSE 0 END) AS count_published,
0
FROM ttrss_feeds f, ttrss_user_entries ue
WHERE f.cat_id IS NULL AND
@@ -121,16 +125,18 @@ class Counters {
while ($line = $sth->fetch()) {
if ($line["num_children"] > 0) {
- list ($child_counter, $child_marked_counter) = self::get_cat_children($line["id"], $_SESSION["uid"]);
+ list ($child_counter, $child_marked_counter, $child_published_counter) = self::get_cat_children($line["id"], $_SESSION["uid"]);
} else {
$child_counter = 0;
$child_marked_counter = 0;
+ $child_published_counter = 0;
}
$cv = [
"id" => (int)$line["id"],
"kind" => "cat",
"markedcounter" => (int) $line["count_marked"] + $child_marked_counter,
+ "publishedcounter" => (int) $line["count_published"] + $child_published_counter,
"counter" => (int) $line["count"] + $child_counter
];
@@ -173,6 +179,7 @@ class Counters {
'updated' => TimeHelper::make_local_datetime($feed->last_updated),
'counter' => (int) $feed->count,
'markedcounter' => (int) $feed->count_marked,
+ 'publishedcounter' => (int) $feed->count_published,
'ts' => Feeds::_has_icon($feed->id) ? (int) filemtime(Feeds::_get_icon_file($feed->id)) : 0,
];
}
@@ -228,6 +235,9 @@ class Counters {
if ($feed_id == Feeds::FEED_STARRED)
$cv["markedcounter"] = $auxctr;
+ if ($feed_id == Feeds::FEED_PUBLISHED)
+ $cv["publishedcounter"] = $auxctr;
+
array_push($ret, $cv);
}
@@ -270,6 +280,7 @@ class Counters {
caption,
SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS count_unread,
SUM(CASE WHEN u1.marked = true THEN 1 ELSE 0 END) AS count_marked,
+ SUM(CASE WHEN u1.published = true THEN 1 ELSE 0 END) AS count_published,
COUNT(u1.unread) AS total
FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
(ttrss_labels2.id = label_id)
@@ -282,6 +293,7 @@ class Counters {
caption,
SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS count_unread,
SUM(CASE WHEN u1.marked = true THEN 1 ELSE 0 END) AS count_marked,
+ SUM(CASE WHEN u1.published = true THEN 1 ELSE 0 END) AS count_published,
COUNT(u1.unread) AS total
FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
(ttrss_labels2.id = label_id)
@@ -300,6 +312,7 @@ class Counters {
"counter" => (int) $line["count_unread"],
"auxcounter" => (int) $line["total"],
"markedcounter" => (int) $line["count_marked"],
+ "publishedcounter" => (int) $line["count_published"],
"description" => $line["caption"]
];
diff --git a/classes/Feeds.php b/classes/Feeds.php
index e76044060..7781d748f 100644
--- a/classes/Feeds.php
+++ b/classes/Feeds.php
@@ -1248,6 +1248,31 @@ class Feeds extends Handler_Protected {
return 0;
}
+ // only real cats
+ static function _get_cat_published(int $cat, int $owner_uid = 0): int {
+
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $pdo = Db::pdo();
+
+ if ($cat >= 0) {
+
+ $sth = $pdo->prepare("SELECT SUM(CASE WHEN published THEN 1 ELSE 0 END) AS marked
+ FROM ttrss_user_entries
+ WHERE feed_id IN (SELECT id FROM ttrss_feeds
+ WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
+ AND owner_uid = :uid)
+ AND owner_uid = :uid");
+
+ $sth->execute(["cat" => $cat ? $cat : null, "uid" => $owner_uid]);
+
+ if ($row = $sth->fetch()) {
+ return (int) $row["marked"];
+ }
+ }
+ return 0;
+ }
+
static function _get_cat_unread(int $cat, int $owner_uid = 0): int {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];