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

unfiled items api calls #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ public function items() {
$this->permissions
);
}
// Unfiled items
else if ($this->subset == 'unfiled') {
$this->allowMethods(['GET']);

$title = "Unfiled items";
$results = Zotero_Items::search(
$this->objectLibraryID,
true,
$this->queryParams,
$this->permissions,
true
);
}
else if ($this->subset == 'children') {
$item = Zotero_Items::getByLibraryAndKey($this->objectLibraryID, $this->objectKey);
if (!$item) {
Expand Down
13 changes: 12 additions & 1 deletion controllers/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function tags() {
$this->allowMethods(array('GET'));

// Tags within items
if (($this->scopeObject == 'items' && !$this->scopeObjectKey) || $this->scopeObject == 'collection-items') {
if (($this->scopeObject == 'items' && (!$this->scopeObjectKey || $this->scopeObjectKey == 'unfiled')) || $this->scopeObject == 'collection-items') {
// Proxy certain query parameters to items search
$validItemParams = [
'itemQ' => 'q',
Expand Down Expand Up @@ -127,6 +127,17 @@ public function tags() {
$this->permissions
);
}
// Unfiled
else if($this->scopeObjectKey == 'unfiled') {
$title = "Unfiled tags";
$itemResults = Zotero_Items::search(
$this->objectLibraryID,
true,
$itemParams,
$this->permissions,
true
);
}
else {
$itemResults = Zotero_Items::search(
$this->objectLibraryID,
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',['controller' => 'Items', 'extra' => ['subset' => 'unfiled']]);
$router->map('/users/i:objectUserID/items/unfiled/tags', ['controller' => 'Tags', 'extra' => ['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
12 changes: 10 additions & 2 deletions model/Items.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function getDeleted($libraryID, $asIDs) {
}


public static function search($libraryID, $onlyTopLevel = false, array $params = [], Zotero_Permissions $permissions = null) {
public static function search($libraryID, $onlyTopLevel = false, array $params = [], Zotero_Permissions $permissions = null, $unfiled = false ) {
$rnd = "_" . uniqid($libraryID . "_");

$results = array('results' => array(), 'total' => 0);
Expand Down Expand Up @@ -154,6 +154,10 @@ public static function search($libraryID, $onlyTopLevel = false, array $params =
&& ($params['format'] == 'keys' || $params['format'] == 'versions' || $topLevelItemSort)) {
$sql .= "LEFT JOIN items ITLI ON (ITLI.itemID=$itemIDSelector) ";
}

if ($unfiled) {
$sql .= "LEFT JOIN collectionItems CI ON (CI.itemID=I.itemID) ";
}
}

// For 'q' we need the note; for sorting by title, we need the note title
Expand Down Expand Up @@ -490,6 +494,10 @@ public static function search($libraryID, $onlyTopLevel = false, array $params =
if ($skipITLI) {
$sql .= "AND ITL.itemID IS NULL ";
}

if ($unfiled) {
$sql .= "AND CI.collectionID IS NULL ";
}

$sql .= "ORDER BY ";

Expand Down Expand Up @@ -2574,7 +2582,7 @@ private static function loadItems($libraryID, $itemIDs=array()) {
}
}
}


public static function getSortTitle($title) {
if (!$title) {
Expand Down