diff --git a/classes/counters.php b/classes/counters.php index 63143a503..d8ed27621 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -12,6 +12,26 @@ class Counters { return $data; } + static private function getCategoryChildrenCounters($cat_id, $owner_uid) { + $pdo = Db::pdo(); + + $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ? + AND owner_uid = ?"); + $sth->execute([$cat_id, $owner_uid]); + + $unread = 0; + $marked = 0; + + while ($line = $sth->fetch()) { + list ($tmp_unread, $tmp_marked) = Counters::getCategoryChildrenCounters($line["id"], $owner_uid); + + $unread += $tmp_unread + Feeds::getCategoryUnread($line["id"], $owner_uid); + $marked += $tmp_marked + Feeds::getCategoryMarked($line["id"], $owner_uid); + } + + return [$unread, $marked]; + } + static function getCategoryCounters() { $ret = []; @@ -48,15 +68,16 @@ class Counters { while ($line = $sth->fetch()) { if ($line["num_children"] > 0) { - $child_counter = Feeds::getCategoryChildrenUnread($line["id"], $_SESSION["uid"]); + list ($child_counter, $child_marked_counter) = Counters::getCategoryChildrenCounters($line["id"], $_SESSION["uid"]); } else { $child_counter = 0; + $child_marked_counter = 0; } $cv = [ "id" => (int)$line["id"], "kind" => "cat", - "markedcounter" => (int) $line["count_marked"], + "markedcounter" => (int) $line["count_marked"] + $child_marked_counter, "counter" => (int) $line["count"] + $child_counter ]; diff --git a/classes/feeds.php b/classes/feeds.php index 8ef4f1f1c..77add790e 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -1290,6 +1290,30 @@ class Feeds extends Handler_Protected { } } + // only real cats + static function getCategoryMarked($cat, $owner_uid = false) { + + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + + $pdo = Db::pdo(); + + if ($cat >= 0) { + + $sth = $pdo->prepare("SELECT SUM(CASE WHEN marked 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]); + $row = $sth->fetch(); + + return $row["marked"]; + } else { + return 0; + } + } + static function getCategoryUnread($cat, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"];