Skip to content

Commit

Permalink
collections/:key/tags endpoint includes tags of items' children
Browse files Browse the repository at this point in the history
Fixes: #103
  • Loading branch information
abaevbog committed Jun 14, 2023
1 parent 2cf66c3 commit dcf9d85
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions model/Collection.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,24 @@ public function getTags($asIDs=false) {


/*
* Returns an array keyed by tagID with the number of linked items for each tag
* Returns an array keyed by tagID with the number of linked items, including their children, for each tag
* in this collection
*/
public function getTagItemCounts() {
$sql = "SELECT tagID, COUNT(*) AS numItems FROM tags JOIN itemTags USING (tagID)
JOIN collectionItems USING (itemID) WHERE collectionID=? GROUP BY tagID";
$sql = 'SELECT tagID, COUNT(*) AS numItems
FROM tags
JOIN (
SELECT itemID, tagID FROM itemTags
UNION ALL
SELECT sourceItemID AS itemID, tagID FROM itemTags
JOIN itemAttachments ON itemTags.itemID = itemAttachments.itemID
UNION ALL
SELECT sourceItemID AS itemID, tagID FROM itemTags
JOIN itemNotes ON itemTags.itemID = itemNotes.itemID
) combinedTags USING (tagID)
JOIN collectionItems USING (itemID)
WHERE collectionID = ?
GROUP BY tagID';
$rows = Zotero_DB::query($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
if (!$rows) {
return false;
Expand Down

0 comments on commit dcf9d85

Please sign in to comment.