Skip to content

Commit

Permalink
editedBy item sort option for group libraries
Browse files Browse the repository at this point in the history
Fixes: zotero#153
  • Loading branch information
abaevbog committed Jun 22, 2023
1 parent 2cf66c3 commit 99579e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions model/API.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ public static function parseQueryParams($queryString, $action, $singleObject, $a
//case 'numChildren':

case 'addedBy':
case 'editedBy':
case 'numItems':
case 'serverDateModified':

Expand Down
11 changes: 7 additions & 4 deletions model/Items.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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), '?'))
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 99579e2

Please sign in to comment.