Skip to content

Commit

Permalink
include annotation tags for /collections/:key/tags
Browse files Browse the repository at this point in the history
Fixes: zotero#162
  • Loading branch information
abaevbog committed Aug 21, 2023
1 parent 8836501 commit 3be75e0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions model/Collection.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ public function getTagItemCounts() {
foreach ($rows as $row) {
$counts[$row['tagID']] = $row['numItems'];
}
// Fetch the tags of annotations as well
$annotationsSql = "SELECT tagID, COUNT(*) AS numItems FROM tags JOIN itemTags USING (tagID)
JOIN itemAnnotations USING (itemID)
JOIN itemAttachments ON itemAttachments.itemID = itemAnnotations.parentItemID
JOIN collectionItems ON collectionItems.itemID = itemAttachments.sourceItemID
WHERE collectionID=? GROUP BY tagID;";

$rows = Zotero_DB::query($annotationsSql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
if (!$rows) {
return $counts;
}
// Add numItems into the same array.
foreach ($rows as $row) {
if (!array_key_exists($row['tagID'], $counts)) {
$counts[$row['tagID']] = 0;
}
$counts[$row['tagID']] += $row['numItems'];
}
return $counts;
}

Expand Down

0 comments on commit 3be75e0

Please sign in to comment.