summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-08-13 19:52:34 +0400
committerAndrew Dolgov <[email protected]>2012-08-13 19:52:34 +0400
commit2c5f231e439dac3fc68422fbb1c8ec57e9d8b35d (patch)
treec86b2221340be229995caf799ea45afeac441fff /include
parentbe514d00c9df66392e85529d2df78d4de1601a98 (diff)
add special indication for categories having unread items in child categories
Diffstat (limited to 'include')
-rw-r--r--include/functions.php28
1 files changed, 27 insertions, 1 deletions
diff --git a/include/functions.php b/include/functions.php
index 009955c99..b2319e6e1 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1501,7 +1501,9 @@
array_push($ret_arr, $cv);
- $result = db_query($link, "SELECT id AS cat_id, value AS unread
+ $result = db_query($link, "SELECT id AS cat_id, value AS unread,
+ (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
+ WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
FROM ttrss_feed_categories, ttrss_cat_counters_cache
WHERE ttrss_cat_counters_cache.feed_id = id AND
ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
@@ -1509,7 +1511,14 @@
while ($line = db_fetch_assoc($result)) {
$line["cat_id"] = (int) $line["cat_id"];
+ if ($line["num_children"] > 0) {
+ $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]);
+ } else {
+ $child_counter = 0;
+ }
+
$cv = array("id" => $line["cat_id"], "kind" => "cat",
+ "child_counter" => $child_counter,
"counter" => $line["unread"]);
array_push($ret_arr, $cv);
@@ -1525,6 +1534,23 @@
return $ret_arr;
}
+ // only accepts real cats (>= 0)
+ function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) {
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat'
+ AND owner_uid = $owner_uid");
+
+ $unread = 0;
+
+ while ($line = db_fetch_assoc($result)) {
+ $unread += getCategoryUnread($link, $line["id"], $owner_uid);
+ $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid);
+ }
+
+ return $unread;
+ }
+
function getCategoryUnread($link, $cat, $owner_uid = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];