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

include annotation tags for /collections/:key/tags #163

Open
wants to merge 3 commits 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: 18 additions & 0 deletions model/Collection.inc.php
Original file line number Diff line number Diff line change
@@ -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 itemTags
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;
}

7 changes: 6 additions & 1 deletion model/Items.inc.php
Original file line number Diff line number Diff line change
@@ -431,7 +431,12 @@ public static function search($libraryID, $onlyTopLevel = false, array $params =

$tagIDs = array_unique($tagIDs);

$tmpSQL = "SELECT itemID FROM items JOIN itemTags USING (itemID) "
// If /top items are requested, fetch itemIDs of top level items whose
// children match the tag query
$tmpSelect = $onlyTopLevel ? "COALESCE(topLevelItemID, itemID)" : "itemID";
$tmpJoin = $onlyTopLevel ? "LEFT JOIN itemTopLevel USING (itemID) " : " ";
$tmpSQL = "SELECT $tmpSelect FROM items JOIN itemTags USING (itemID) "
. $tmpJoin
. "WHERE tagID IN (" . implode(',', array_fill(0, sizeOf($tagIDs), '?')) . ")";
$ids = Zotero_DB::columnQuery($tmpSQL, $tagIDs, $shardID);