]> git.wh0rd.org Git - tt-rss.git/commitdiff
print_feed_cat_select: display nested category structure
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 14 Aug 2012 19:18:40 +0000 (23:18 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 14 Aug 2012 19:19:20 +0000 (23:19 +0400)
fix empty sub-sub-categories never being shown

classes/pref_feeds.php
include/functions.php

index d292319cbf11814ff6c5baf0a616fe663507d708..381330da0c2b6c1ecf3a68003313acc50cf83cee 100644 (file)
@@ -33,6 +33,8 @@ class Pref_Feeds extends Protected_Handler {
        }
 
        private function get_category_items($cat_id) {
+               $show_empty_cats = $_REQUEST['mode'] != 2 &&
+                       get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
 
                $items = array();
 
index cb24cb877782066a87466ac4e8dff28fc0da10b4..ac9c5372ce6e567c55d1bd11b9d2c5906b6066b2 100644 (file)
                print "</select>";
        }
 
-       function print_feed_cat_select($link, $id, $default_id = "",
-               $attributes = "", $include_all_cats = true) {
+       function print_feed_cat_select($link, $id, $default_id,
+               $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) {
 
-               print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" onchange=\"catSelectOnChange(this)\" $attributes>";
+                       if (!$root_id) {
+                                       print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" onchange=\"catSelectOnChange(this)\" $attributes>";
+                       }
 
-               if ($include_all_cats) {
-                       print "<option value=\"0\">".__('Uncategorized')."</option>";
-               }
+                       if ($root_id)
+                               $parent_qpart = "parent_cat = '$root_id'";
+                       else
+                               $parent_qpart = "parent_cat IS NULL";
 
-               $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
-                       WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
+                       $result = db_query($link, "SELECT id,title,
+                               (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
+                                       c2.parent_cat = ttrss_feed_categories.id) AS num_children
+                               FROM ttrss_feed_categories
+                               WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title");
 
-               if (db_num_rows($result) > 0 && $include_all_cats) {
-                       print "<option disabled=\"1\">--------</option>";
-               }
+                       while ($line = db_fetch_assoc($result)) {
+                               if ($line["id"] == $default_id) {
+                                       $is_selected = "selected=\"1\"";
+                               } else {
+                                       $is_selected = "";
+                               }
 
-               while ($line = db_fetch_assoc($result)) {
-                       if ($line["id"] == $default_id) {
-                               $is_selected = "selected=\"1\"";
-                       } else {
-                               $is_selected = "";
-                       }
+                               for ($i = 0; $i < $nest_level; $i++)
+                                       $line["title"] = " - " . $line["title"];
 
-                       if ($line["title"])
-                               printf("<option $is_selected value='%d'>%s</option>",
-                                       $line["id"], htmlspecialchars($line["title"]));
-               }
+                               if ($line["title"])
+                                       printf("<option $is_selected value='%d'>%s</option>",
+                                               $line["id"], htmlspecialchars($line["title"]));
 
-#              print "<option value=\"ADD_CAT\">" .__("Add category...") . "</option>";
+                               if ($line["num_children"] > 0)
+                                       print_feed_cat_select($link, $id, $default_id, $attributes,
+                                               $include_all_cats, $line["id"], $nest_level+1);
+                       }
 
-               print "</select>";
-       }
+                       if (!$root_id) {
+                               if ($include_all_cats) {
+                                       if (db_num_rows($result) > 0) {
+                                               print "<option disabled=\"1\">--------</option>";
+                                       }
+                                               print "<option value=\"0\">".__('Uncategorized')."</option>";
+                               }
+                               print "</select>";
+                       }
+               }
 
        function checkbox_to_sql_bool($val) {
                return ($val == "on") ? "true" : "false";