]> git.wh0rd.org Git - tt-rss.git/commitdiff
api: block real categories with 0 feeds to appear in getCategories
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 10 Feb 2013 07:40:03 +0000 (11:40 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 10 Feb 2013 07:40:03 +0000 (11:40 +0400)
classes/api.php

index a4294e026dad09e10277a7e3d609555382f917d1..4b24b01107c5f7f9447961b1ff4f4edd84d9e926 100644 (file)
@@ -131,24 +131,29 @@ class API extends Handler {
                        $nested_qpart = "true";
 
                $result = db_query($this->link, "SELECT
-                               id, title, order_id FROM ttrss_feed_categories
+                               id, title, order_id, (SELECT COUNT(id) FROM
+                               ttrss_feeds WHERE
+                               ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds
+                       FROM ttrss_feed_categories
                        WHERE $nested_qpart AND owner_uid = " .
                        $_SESSION["uid"]);
 
                $cats = array();
 
                while ($line = db_fetch_assoc($result)) {
-                       $unread = getFeedUnread($this->link, $line["id"], true);
+                       if ($line["num_feeds"] > 0) {
+                               $unread = getFeedUnread($this->link, $line["id"], true);
 
-                       if ($enable_nested)
-                               $unread += getCategoryChildrenUnread($this->link, $line["id"]);
+                               if ($enable_nested)
+                                       $unread += getCategoryChildrenUnread($this->link, $line["id"]);
 
-                       if ($unread || !$unread_only) {
-                               array_push($cats, array("id" => $line["id"],
-                                       "title" => $line["title"],
-                                       "unread" => $unread,
-                                       "order_id" => (int) $line["order_id"],
-                               ));
+                               if ($unread || !$unread_only) {
+                                       array_push($cats, array("id" => $line["id"],
+                                               "title" => $line["title"],
+                                               "unread" => $unread,
+                                               "order_id" => (int) $line["order_id"],
+                                       ));
+                               }
                        }
                }