diff --git a/controllers/ApiController.php b/controllers/ApiController.php index b02bb4e0..4e343bf0 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -482,7 +482,7 @@ public function init($extra) { // Sorting by Item Type or Added By currently require writing to shard tables, so don't // send those to the read replicas - if ($this->queryParams['sort'] == 'itemType' || $this->queryParams['sort'] == 'addedBy') { + if ($this->queryParams['sort'] == 'itemType' || $this->queryParams['sort'] == 'addedBy' || $this->queryParams['sort'] == 'editedBy') { Zotero_DB::readOnly(false); } diff --git a/model/API.inc.php b/model/API.inc.php index 863104a3..0a015394 100644 --- a/model/API.inc.php +++ b/model/API.inc.php @@ -397,6 +397,7 @@ public static function parseQueryParams($queryString, $action, $singleObject, $a //case 'numChildren': case 'addedBy': + case 'editedBy': case 'numItems': case 'serverDateModified': diff --git a/model/Items.inc.php b/model/Items.inc.php index df08d0c6..9ab05e95 100644 --- a/model/Items.inc.php +++ b/model/Items.inc.php @@ -274,13 +274,15 @@ public static function search($libraryID, $onlyTopLevel = false, array $params = // Join temp table to query $sql .= "JOIN tmpItemTypeNames TITN ON (TITN.itemTypeID=$itemTypeIDSelector) "; break; - + + case 'editedBy': case 'addedBy': $isGroup = Zotero_Libraries::getType($libraryID) == 'group'; + $userParameter = $params['sort'] == "editedBy" ? 'lastModifiedByUserID' : 'createdByUserID'; if ($isGroup) { - $sql2 = "SELECT DISTINCT createdByUserID FROM items + $sql2 = "SELECT DISTINCT $userParameter FROM items JOIN groupItems USING (itemID) WHERE - createdByUserID IS NOT NULL AND "; + $userParameter IS NOT NULL AND "; if ($itemIDs) { $sql2 .= "itemID IN (" . implode(', ', array_fill(0, sizeOf($itemIDs), '?')) @@ -307,7 +309,7 @@ public static function search($libraryID, $onlyTopLevel = false, array $params = // Join temp table to query $sql .= "LEFT JOIN groupItems GI ON (GI.itemID=I.itemID) - LEFT JOIN tmpCreatedByUsers TCBU ON (TCBU.userID=GI.createdByUserID) "; + LEFT JOIN tmpCreatedByUsers TCBU ON (TCBU.userID=GI.$userParameter) "; } } break; @@ -550,6 +552,7 @@ public static function search($libraryID, $onlyTopLevel = false, array $params = $orderSQL = "$sortTable.value"; break; + case 'editedBy': case 'addedBy': if ($isGroup && $createdByUserIDs) { $orderSQL = "TCBU.username"; @@ -2574,6 +2577,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) {