Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collections/:key/tags includes tags of children of items #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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