]> git.wh0rd.org - tt-rss.git/commitdiff
api: do not return Labels category when there are no labels (closes #651)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 1 Apr 2013 10:04:56 +0000 (14:04 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 1 Apr 2013 10:04:56 +0000 (14:04 +0400)
classes/api.php

index 0e56e58f9ae97b2a6b48d0dd8c4b696fd5110e59..d3b61c15a7ede98e66f7a1d5d8e0de9ad9e0126e 100644 (file)
@@ -165,12 +165,14 @@ class API extends Handler {
                }
 
                foreach (array(-2,-1,0) as $cat_id) {
-                       $unread = getFeedUnread($this->link, $cat_id, true);
+                       if ($include_empty || !$this->isCategoryEmpty($cat_id)) {
+                               $unread = getFeedUnread($this->link, $cat_id, true);
 
-                       if ($unread || !$unread_only) {
-                               array_push($cats, array("id" => $cat_id,
-                                       "title" => getCategoryTitle($this->link, $cat_id),
-                                       "unread" => $unread));
+                               if ($unread || !$unread_only) {
+                                       array_push($cats, array("id" => $cat_id,
+                                               "title" => getCategoryTitle($this->link, $cat_id),
+                                               "unread" => $unread));
+                               }
                        }
                }
 
@@ -724,6 +726,22 @@ class API extends Handler {
                }
 
        }
+
+       // only works for labels for the time being
+       private function isCategoryEmpty($id) {
+
+               if ($id == -2) {
+                       $result = db_query($this->link, "SELECT COUNT(*) AS count FROM ttrss_labels2
+                               WHERE owner_uid = " . $_SESSION["uid"]);
+
+                       return db_fetch_result($result, 0, "count") == 0;
+
+               }
+
+               return false;
+       }
+
+
 }
 
 ?>