|
|
@ -11,13 +11,14 @@ class Counters {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static function get_for_feeds($feed_ids) {
|
|
|
|
static function get_conditional(array $feed_ids = null, array $label_ids = null) {
|
|
|
|
return array_merge(
|
|
|
|
return array_merge(
|
|
|
|
self::get_global(),
|
|
|
|
self::get_global(),
|
|
|
|
self::get_virt(),
|
|
|
|
self::get_virt(),
|
|
|
|
self::get_labels(),
|
|
|
|
self::get_labels($label_ids),
|
|
|
|
self::get_feeds($feed_ids),
|
|
|
|
self::get_feeds($feed_ids),
|
|
|
|
self::get_cats(Feeds::_cats_of($feed_ids, $_SESSION["uid"], true)));
|
|
|
|
self::get_cats(is_array($feed_ids) ? Feeds::_cats_of($feed_ids, $_SESSION["uid"], true) : null)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static private function get_cat_children($cat_id, $owner_uid) {
|
|
|
|
static private function get_cat_children($cat_id, $owner_uid) {
|
|
|
@ -40,7 +41,7 @@ class Counters {
|
|
|
|
return [$unread, $marked];
|
|
|
|
return [$unread, $marked];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static function get_cats(array $cat_ids = []) {
|
|
|
|
private static function get_cats(array $cat_ids = null) {
|
|
|
|
$ret = [];
|
|
|
|
$ret = [];
|
|
|
|
|
|
|
|
|
|
|
|
/* Labels category */
|
|
|
|
/* Labels category */
|
|
|
@ -52,7 +53,12 @@ class Counters {
|
|
|
|
|
|
|
|
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
|
|
|
|
if (count($cat_ids) == 0) {
|
|
|
|
if (is_array($cat_ids)) {
|
|
|
|
|
|
|
|
if (count($cat_ids) == 0)
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$cat_ids_qmarks = arr_qmarks($cat_ids);
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("SELECT fc.id,
|
|
|
|
$sth = $pdo->prepare("SELECT fc.id,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
|
|
@ -61,7 +67,7 @@ class Counters {
|
|
|
|
FROM ttrss_feed_categories fc
|
|
|
|
FROM ttrss_feed_categories fc
|
|
|
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
|
|
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
|
|
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
|
|
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
|
|
|
WHERE fc.owner_uid = :uid
|
|
|
|
WHERE fc.owner_uid = ? AND fc.id IN ($cat_ids_qmarks)
|
|
|
|
GROUP BY fc.id
|
|
|
|
GROUP BY fc.id
|
|
|
|
UNION
|
|
|
|
UNION
|
|
|
|
SELECT 0,
|
|
|
|
SELECT 0,
|
|
|
@ -71,12 +77,15 @@ class Counters {
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
WHERE f.cat_id IS NULL AND
|
|
|
|
WHERE f.cat_id IS NULL AND
|
|
|
|
ue.feed_id = f.id AND
|
|
|
|
ue.feed_id = f.id AND
|
|
|
|
ue.owner_uid = :uid");
|
|
|
|
ue.owner_uid = ?");
|
|
|
|
|
|
|
|
|
|
|
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
|
|
|
$sth->execute(array_merge(
|
|
|
|
} else {
|
|
|
|
[$_SESSION['uid']],
|
|
|
|
$cat_ids_qmarks = arr_qmarks($cat_ids);
|
|
|
|
$cat_ids,
|
|
|
|
|
|
|
|
[$_SESSION['uid']]
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$sth = $pdo->prepare("SELECT fc.id,
|
|
|
|
$sth = $pdo->prepare("SELECT fc.id,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked,
|
|
|
@ -85,7 +94,7 @@ class Counters {
|
|
|
|
FROM ttrss_feed_categories fc
|
|
|
|
FROM ttrss_feed_categories fc
|
|
|
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
|
|
|
LEFT JOIN ttrss_feeds f ON (f.cat_id = fc.id)
|
|
|
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
|
|
|
LEFT JOIN ttrss_user_entries ue ON (ue.feed_id = f.id)
|
|
|
|
WHERE fc.owner_uid = ? AND fc.id IN ($cat_ids_qmarks)
|
|
|
|
WHERE fc.owner_uid = :uid
|
|
|
|
GROUP BY fc.id
|
|
|
|
GROUP BY fc.id
|
|
|
|
UNION
|
|
|
|
UNION
|
|
|
|
SELECT 0,
|
|
|
|
SELECT 0,
|
|
|
@ -95,13 +104,9 @@ class Counters {
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
WHERE f.cat_id IS NULL AND
|
|
|
|
WHERE f.cat_id IS NULL AND
|
|
|
|
ue.feed_id = f.id AND
|
|
|
|
ue.feed_id = f.id AND
|
|
|
|
ue.owner_uid = ?");
|
|
|
|
ue.owner_uid = :uid");
|
|
|
|
|
|
|
|
|
|
|
|
$sth->execute(array_merge(
|
|
|
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
|
|
|
[$_SESSION['uid']],
|
|
|
|
|
|
|
|
$cat_ids,
|
|
|
|
|
|
|
|
[$_SESSION['uid']]
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
@ -125,13 +130,18 @@ class Counters {
|
|
|
|
return $ret;
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static function get_feeds(array $feed_ids = []) {
|
|
|
|
private static function get_feeds(array $feed_ids = null) {
|
|
|
|
|
|
|
|
|
|
|
|
$ret = [];
|
|
|
|
$ret = [];
|
|
|
|
|
|
|
|
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
|
|
|
|
if (count($feed_ids) == 0) {
|
|
|
|
if (is_array($feed_ids)) {
|
|
|
|
|
|
|
|
if (count($feed_ids) == 0)
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$feed_ids_qmarks = arr_qmarks($feed_ids);
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("SELECT f.id,
|
|
|
|
$sth = $pdo->prepare("SELECT f.id,
|
|
|
|
f.title,
|
|
|
|
f.title,
|
|
|
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
|
|
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
|
|
@ -139,13 +149,11 @@ class Counters {
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
WHERE f.id = ue.feed_id AND ue.owner_uid = :uid
|
|
|
|
WHERE f.id = ue.feed_id AND ue.owner_uid = ? AND f.id IN ($feed_ids_qmarks)
|
|
|
|
GROUP BY f.id");
|
|
|
|
GROUP BY f.id");
|
|
|
|
|
|
|
|
|
|
|
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
|
|
|
$sth->execute(array_merge([$_SESSION['uid']], $feed_ids));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$feed_ids_qmarks = arr_qmarks($feed_ids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("SELECT f.id,
|
|
|
|
$sth = $pdo->prepare("SELECT f.id,
|
|
|
|
f.title,
|
|
|
|
f.title,
|
|
|
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
|
|
|
".SUBSTRING_FOR_DATE."(f.last_updated,1,19) AS last_updated,
|
|
|
@ -153,10 +161,10 @@ class Counters {
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS count,
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
|
|
|
SUM(CASE WHEN marked THEN 1 ELSE 0 END) AS count_marked
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
FROM ttrss_feeds f, ttrss_user_entries ue
|
|
|
|
WHERE f.id = ue.feed_id AND ue.owner_uid = ? AND f.id IN ($feed_ids_qmarks)
|
|
|
|
WHERE f.id = ue.feed_id AND ue.owner_uid = :uid
|
|
|
|
GROUP BY f.id");
|
|
|
|
GROUP BY f.id");
|
|
|
|
|
|
|
|
|
|
|
|
$sth->execute(array_merge([$_SESSION['uid']], $feed_ids));
|
|
|
|
$sth->execute(["uid" => $_SESSION['uid']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
@ -269,23 +277,42 @@ class Counters {
|
|
|
|
return $ret;
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static function get_labels($descriptions = false) {
|
|
|
|
static function get_labels(array $label_ids = null) {
|
|
|
|
|
|
|
|
|
|
|
|
$ret = [];
|
|
|
|
$ret = [];
|
|
|
|
|
|
|
|
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("SELECT id,
|
|
|
|
if (is_array($label_ids)) {
|
|
|
|
caption,
|
|
|
|
if (count($label_ids) == 0)
|
|
|
|
SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS count_unread,
|
|
|
|
return [];
|
|
|
|
SUM(CASE WHEN u1.marked = true THEN 1 ELSE 0 END) AS count_marked,
|
|
|
|
|
|
|
|
COUNT(u1.unread) AS total
|
|
|
|
$label_ids_qmarks = arr_qmarks($label_ids);
|
|
|
|
FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
|
|
|
|
|
|
|
|
(ttrss_labels2.id = label_id)
|
|
|
|
$sth = $pdo->prepare("SELECT id,
|
|
|
|
LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id AND u1.owner_uid = :uid
|
|
|
|
caption,
|
|
|
|
WHERE ttrss_labels2.owner_uid = :uid
|
|
|
|
SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS count_unread,
|
|
|
|
GROUP BY ttrss_labels2.id, ttrss_labels2.caption");
|
|
|
|
SUM(CASE WHEN u1.marked = true THEN 1 ELSE 0 END) AS count_marked,
|
|
|
|
$sth->execute([":uid" => $_SESSION['uid']]);
|
|
|
|
COUNT(u1.unread) AS total
|
|
|
|
|
|
|
|
FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
|
|
|
|
|
|
|
|
(ttrss_labels2.id = label_id)
|
|
|
|
|
|
|
|
LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id AND u1.owner_uid = ?
|
|
|
|
|
|
|
|
WHERE ttrss_labels2.owner_uid = ? AND ttrss_labels2.id IN ($label_ids_qmarks)
|
|
|
|
|
|
|
|
GROUP BY ttrss_labels2.id, ttrss_labels2.caption");
|
|
|
|
|
|
|
|
$sth->execute(array_merge([$_SESSION["uid"], $_SESSION["uid"]], $label_ids));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("SELECT id,
|
|
|
|
|
|
|
|
caption,
|
|
|
|
|
|
|
|
SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS count_unread,
|
|
|
|
|
|
|
|
SUM(CASE WHEN u1.marked = true THEN 1 ELSE 0 END) AS count_marked,
|
|
|
|
|
|
|
|
COUNT(u1.unread) AS total
|
|
|
|
|
|
|
|
FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
|
|
|
|
|
|
|
|
(ttrss_labels2.id = label_id)
|
|
|
|
|
|
|
|
LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id AND u1.owner_uid = :uid
|
|
|
|
|
|
|
|
WHERE ttrss_labels2.owner_uid = :uid
|
|
|
|
|
|
|
|
GROUP BY ttrss_labels2.id, ttrss_labels2.caption");
|
|
|
|
|
|
|
|
$sth->execute([":uid" => $_SESSION['uid']]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
|
|
|
|
|
|
|
|
@ -295,12 +322,10 @@ class Counters {
|
|
|
|
"id" => $id,
|
|
|
|
"id" => $id,
|
|
|
|
"counter" => (int) $line["count_unread"],
|
|
|
|
"counter" => (int) $line["count_unread"],
|
|
|
|
"auxcounter" => (int) $line["total"],
|
|
|
|
"auxcounter" => (int) $line["total"],
|
|
|
|
"markedcounter" => (int) $line["count_marked"]
|
|
|
|
"markedcounter" => (int) $line["count_marked"],
|
|
|
|
|
|
|
|
"description" => $line["caption"]
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if ($descriptions)
|
|
|
|
|
|
|
|
$cv["description"] = $line["caption"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array_push($ret, $cv);
|
|
|
|
array_push($ret, $cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|