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

editedBy item sort option for group libraries #154

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
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 (in_array($this->queryParams['sort'], ['itemType', 'addedBy', '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
15 changes: 9 additions & 6 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 'addedBy':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editedBy goes second, here and below

case 'editedBy':
$isGroup = Zotero_Libraries::getType($libraryID) == 'group';
$userParameter = $params['sort'] == "addedBy" ? 'createdByUserID' : 'lastModifiedByUserID';
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 @@ -302,12 +304,12 @@ public static function search($libraryID, $onlyTopLevel = false, array $params =
);
}

$sql2 = "INSERT IGNORE INTO tmpCreatedByUsers VALUES ";
$sql2 = "REPLACE INTO tmpCreatedByUsers VALUES ";
Zotero_DB::bulkInsert($sql2, $toAdd, 50, false, $shardID);

// 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 @@ -549,8 +551,9 @@ public static function search($libraryID, $onlyTopLevel = false, array $params =
case 'date':
$orderSQL = "$sortTable.value";
break;

case 'addedBy':
case 'editedBy':
if ($isGroup && $createdByUserIDs) {
$orderSQL = "TCBU.username";
}
Expand Down