Skip to content

Commit

Permalink
unfiled items api calls
Browse files Browse the repository at this point in the history
/users/XXX/items/unfiled lists all items without collection
/users/XXX/items/unfiled/tags lists all tags or items without collection

Fixes: zotero#11
  • Loading branch information
abaevbog committed Jun 20, 2023
1 parent 2cf66c3 commit e96a237
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ public function items() {
$this->permissions
);
}
// Unfiled items
else if ($this->subset == 'unfiled') {
$this->allowMethods(array('GET'));

$title = "Unfiled items";
$itemIDs = Zotero_Items::getItemsWithoutCollection(
$this->objectLibraryID
);
}
else if ($this->subset == 'children') {
$item = Zotero_Items::getByLibraryAndKey($this->objectLibraryID, $this->objectKey);
if (!$item) {
Expand Down
7 changes: 7 additions & 0 deletions controllers/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public function tags() {
$results = Zotero_Tags::search($this->objectLibraryID, $tagParams);
}
}
// Unfiled
else if($this->scopeObjectKey == 'unfiled') {
$title = "Unfiled tags";
$items = Zotero_Items::getItemsWithoutCollection($this->objectLibraryID);
$this->queryParams['itemIDs'] = $items;
$results = Zotero_Tags::search($this->objectLibraryID, $this->queryParams);
}
// Tags within a collection or item
else if ($this->scopeObjectKey) {
switch ($this->scopeObject) {
Expand Down
4 changes: 4 additions & 0 deletions include/config/routes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
$router->map('/users/i:objectUserID/publications/items/:objectKey/children', ['controller' => 'Items', 'extra' => ['publications' => true, 'subset' => 'children']]);
$router->map('/users/i:objectUserID/publications/items/:objectKey', ['controller' => 'Items', 'extra' => ['publications' => true]]);

// 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')));

// Other top-level URLs, with an optional key and subset
$router->map('/users/i:objectUserID/:controller/:objectKey/:subset');
$router->map('/groups/i:objectGroupID/:controller/:objectKey/:subset');
Expand Down
10 changes: 10 additions & 0 deletions model/Items.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,16 @@ private static function loadItems($libraryID, $itemIDs=array()) {
}
}
}

public static function getItemsWithoutCollection($libraryID) {
$sql = "SELECT items.itemID
FROM items
LEFT JOIN collectionItems ON items.itemID = collectionItems.itemID
WHERE collectionItems.collectionID IS NULL
AND items.libraryID = ?;";
$items = Zotero_DB::columnQuery($sql, $libraryID, Zotero_Shards::getByLibraryID($libraryID));
return $items;
}


public static function getSortTitle($title) {
Expand Down

0 comments on commit e96a237

Please sign in to comment.