]> git.wh0rd.org - tt-rss.git/commitdiff
API: support nested categories
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 18 Sep 2012 05:58:01 +0000 (09:58 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 18 Sep 2012 06:03:26 +0000 (10:03 +0400)
classes/api.php
include/functions.php

index cce1d2a78d6837f2ce3adab5b5a744c48695abf1..801f99566f4e050277e787d5fafb20eee2b743e9 100644 (file)
@@ -114,20 +114,27 @@ class API extends Handler {
                $unread_only = (bool)db_escape_string($_REQUEST["unread_only"]);
                $limit = (int) db_escape_string($_REQUEST["limit"]);
                $offset = (int) db_escape_string($_REQUEST["offset"]);
+               $include_nested = (bool)db_escape_string($_REQUEST["include_nested"]);
 
-               $feeds = api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset);
+               $feeds = api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset, $include_nested);
 
                print $this->wrap(self::STATUS_OK, $feeds);
        }
 
        function getCategories() {
                $unread_only = (bool)db_escape_string($_REQUEST["unread_only"]);
+               $enable_nested = (bool)db_escape_string($_REQUEST["enable_nested"]);
 
                // TODO do not return empty categories, return Uncategorized and standard virtual cats
 
+               if ($enable_nested)
+                       $nested_qpart = "parent_cat IS NULL";
+               else
+                       $nested_qpart = "true";
+
                $result = db_query($this->link, "SELECT
                                id, title, order_id FROM ttrss_feed_categories
-                       WHERE owner_uid = " .
+                       WHERE $nested_qpart AND owner_uid = " .
                        $_SESSION["uid"]);
 
                $cats = array();
@@ -135,6 +142,9 @@ class API extends Handler {
                while ($line = db_fetch_assoc($result)) {
                        $unread = getFeedUnread($this->link, $line["id"], true);
 
+                       if ($enable_nested)
+                               $unread += getCategoryChildrenUnread($this->link, $line["id"]);
+
                        if ($unread || !$unread_only) {
                                array_push($cats, array("id" => $line["id"],
                                        "title" => $line["title"],
@@ -174,6 +184,7 @@ class API extends Handler {
                        $view_mode = db_escape_string($_REQUEST["view_mode"]);
                        $include_attachments = (bool)db_escape_string($_REQUEST["include_attachments"]);
                        $since_id = (int)db_escape_string($_REQUEST["since_id"]);
+                       $include_nested = (bool)db_escape_string($_REQUEST["include_nested"]);
 
                        /* do not rely on params below */
 
@@ -183,7 +194,8 @@ class API extends Handler {
 
                        $headlines = api_get_headlines($this->link, $feed_id, $limit, $offset,
                                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, false,
-                               $include_attachments, $since_id, $search, $search_mode, $match_on);
+                               $include_attachments, $since_id, $search, $search_mode, $match_on,
+                               $include_nested);
 
                        print $this->wrap(self::STATUS_OK, $headlines);
                } else {
index 5af4cb667b439d2202efee471011cc97f88f0c8d..2b0b3a40c49a90b98e9b31dd62e6a5eeaddf6ee3 100644 (file)
                return $rv;
        }
 
-       function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset) {
+       function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) {
 
                        $feeds = array();
 
                                }
                        }
 
+                       /* Child cats */
+
+                       if ($include_nested && $cat_id) {
+                               $result = db_query($link, "SELECT
+                                       id, title FROM ttrss_feed_categories
+                                       WHERE parent_cat = '$cat_id' AND owner_uid = " . $_SESSION["uid"] .
+                                       "ORDER BY id, title");
+
+                               while ($line = db_fetch_assoc($result)) {
+                                       $unread = getFeedUnread($link, $line["id"], true) +
+                                               getCategoryChildrenUnread($link, $line["id"]);
+
+                                       if ($unread || !$unread_only) {
+                                               $row = array(
+                                                               "id" => $line["id"],
+                                                               "title" => $line["title"],
+                                                               "unread" => $unread,
+                                                               "is_cat" => true,
+                                                       );
+                                               array_push($feeds, $row);
+                                       }
+                               }
+                       }
+
                        /* Real feeds */
 
                        if ($limit) {
        function api_get_headlines($link, $feed_id, $limit, $offset,
                                $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
                                $include_attachments, $since_id,
-                               $search = "", $search_mode = "", $match_on = "") {
+                               $search = "", $search_mode = "", $match_on = "", $include_nested = false) {
 
                        $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
                                $view_mode, $is_cat, $search, $search_mode, $match_on,
-                               $order, $offset, 0, false, $since_id);
+                               $order, $offset, 0, false, $since_id, $include_nested);
 
                        $result = $qfh_ret[0];
                        $feed_title = $qfh_ret[1];