diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 6066c23bd..4fed9aa39 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -27,6 +27,7 @@ Zotero.Items = new function() { // Privileged methods this.get = get; + this.getByKey = getByKey; this.exist = exist; this.getAll = getAll; this.getUpdated = getUpdated; @@ -101,6 +102,22 @@ Zotero.Items = new function() { } + /** + * Retrieves an item by its secondary lookup key + * + * @param string key Secondary lookup key + * @return object Zotero.Item object, or FALSE if not found + */ + function getByKey(key) { + var sql = "SELECT itemID FROM items WHERE key=?"; + var itemID = Zotero.DB.valueQuery(sql, key); + if (!itemID) { + return false; + } + return Zotero.Items.get(itemID); + } + + function exist(itemIDs) { var sql = "SELECT itemID FROM items WHERE itemID IN (" + itemIDs.map(function () '?').join() + ")";