File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -614,12 +614,24 @@ public function getTags($asIDs=false) {
614614
615615
616616 /*
617- * Returns an array keyed by tagID with the number of linked items for each tag
617+ * Returns an array keyed by tagID with the number of linked items, including their children, for each tag
618618 * in this collection
619619 */
620620 public function getTagItemCounts () {
621- $ sql = "SELECT tagID, COUNT(*) AS numItems FROM tags JOIN itemTags USING (tagID)
622- JOIN collectionItems USING (itemID) WHERE collectionID=? GROUP BY tagID " ;
621+ $ sql = 'SELECT tagID, COUNT(*) AS numItems
622+ FROM tags
623+ JOIN (
624+ SELECT itemID, tagID FROM itemTags
625+ UNION ALL
626+ SELECT sourceItemID AS itemID, tagID FROM itemTags
627+ JOIN itemAttachments ON itemTags.itemID = itemAttachments.itemID
628+ UNION ALL
629+ SELECT sourceItemID AS itemID, tagID FROM itemTags
630+ JOIN itemNotes ON itemTags.itemID = itemNotes.itemID
631+ ) combinedTags USING (tagID)
632+ JOIN collectionItems USING (itemID)
633+ WHERE collectionID = ?
634+ GROUP BY tagID ' ;
623635 $ rows = Zotero_DB::query ($ sql , $ this ->id , Zotero_Shards::getByLibraryID ($ this ->libraryID ));
624636 if (!$ rows ) {
625637 return false ;
You can’t perform that action at this time.
0 commit comments