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

pkp/pkp-lib#6088 set sequence for featured monographs #1737

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions api/v1/_submissions/BackendSubmissionsHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function saveDisplayFlags($slimRequest, $response, $args) {
if (!empty($params['featured'])) {
foreach($params['featured'] as $feature) {
$featureDao->insertFeature($submissionId, $feature['assoc_type'], $feature['assoc_id'], $feature['seq']);
$featureDao->resequenceByAssoc($feature['assoc_type'], $feature['assoc_id']);
}
}

Expand Down Expand Up @@ -183,10 +184,9 @@ public function saveFeaturedOrder($slimRequest, $response, $args) {
}

$featureDao = \DAORegistry::getDAO('FeatureDAO');
$featureDao->deleteByAssoc($assocType, $assocId);
if (!empty($params['featured'])) {
foreach($params['featured'] as $feature) {
$featureDao->insertFeature($feature['id'], $assocType, $assocId, $feature['seq']);
$featureDao->setSequencePosition($feature['id'], $assocType, $assocId, $feature['seq']);
}
}

Expand Down
11 changes: 4 additions & 7 deletions classes/press/FeatureDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function setSequencePosition($monographId, $assocType, $assocId, $sequencePositi
* Resequence features by association.
* @param $assocType int ASSOC_TYPE_...
* @param $assocId int per $assocType
* @param $seqMonographId if specified, sequence of monograph to return
* @return array Associative array of id => seq for resequenced set
*/
function resequenceByAssoc($assocType, $assocId) {
Expand All @@ -188,19 +187,17 @@ function resequenceByAssoc($assocType, $assocId) {
);

$returner = [];
$i=2;
foreach ($result as $row) {
foreach ($result as $key => $value) {
$this->update(
'UPDATE features SET seq = ? WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
[
$i,
$row->submission_id,
$key + 1,
$value->submission_id,
(int) $assocType,
(int) $assocId
]
);
$returner[$row->submission_id] = $i;
$i += 2;
$returner[$value->submission_id] = $key;
}
return $returner;
}
Expand Down