Skip to content
Open
Changes from 1 commit
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
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JOIN on next line, but I guess we technically don't need tags here or above, so could just remove that.

JOIN itemAnnotations USING (itemID)
JOIN itemAttachments ON itemAttachments.itemID = itemAnnotations.parentItemID
JOIN collectionItems ON collectionItems.itemID = itemAttachments.sourceItemID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

House style: parens around the expression for consistency with USING, even though it's not required for ON

WHERE collectionID=? GROUP BY tagID;";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No semicolon needed


$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