unfiled items api calls#152
Conversation
/users/XXX/items/unfiled lists all items without collection /users/XXX/items/unfiled/tags lists all tags or items without collection Fixes: zotero#11
| } | ||
| // Unfiled items | ||
| else if ($this->subset == 'unfiled') { | ||
| $this->allowMethods(array('GET')); |
There was a problem hiding this comment.
Can always use […] instead of array(…) for new code
|
|
||
| $title = "Unfiled items"; | ||
| $itemIDs = Zotero_Items::getItemsWithoutCollection( | ||
| $this->objectLibraryID |
There was a problem hiding this comment.
This will need to use Zotero_Items::search() like trash above, since otherwise other query parameters don't work. (E.g., people still need to be able to use the search bar, which uses q.) Zotero_Items::search() is quite convoluted, for complicated reasons, so let me know if something is unclear.
/unfiled also implies /top, but I think just setting $onlyTopLevel = true (the second parameter to search()) won't work, since that matches parent items of matching items, and all child items are technically unfiled, so it would match all items with children. So instead of that, the actual unfiled JOIN condition in search() should probably include a negative match on itemTopLevel.itemID, which contains child items mapped to top-level items, so that the actual matches are only top-level items. You can test, but I think this would be the unincorporated version of the SQL:
SELECT * FROM items I
LEFT JOIN itemTopLevel ITL USING (itemID)
LEFT JOIN collectionItems CI USING (itemID)
WHERE libraryID=?
AND ITL.itemID IS NULL
AND CI.collectionID IS NULLThere was a problem hiding this comment.
Makes sense. I added another parameter to search function to tell if it's an unfiled request, and a few conditionals to construct the query above. It seems to give us exactly what we want. I added a small commit with a few tests to check
|
|
||
| // Unfiled items | ||
| $router->map('/users/i:objectUserID/items/unfiled', array('controller' => 'Items', 'extra' => array('subset' => 'unfiled'))); | ||
| $router->map('/users/i:objectUserID/items/unfiled/tags', array('controller' => 'Tags', 'extra' => array('subset' => 'unfiled'))); |
/users/XXX/items/unfiled lists all items without collection
/users/XXX/items/unfiled/tags lists all tags or items without collection
Fixes #11