From 07634b072885aded8f1ecd7a4883e2a2b8169b72 Mon Sep 17 00:00:00 2001 From: Kaitlin Newson Date: Tue, 22 Oct 2024 15:35:44 -0300 Subject: [PATCH] pkp/pkp-lib#6088 set sequence for featured monographs --- api/v1/_submissions/BackendSubmissionsHandler.php | 4 ++-- classes/press/FeatureDAO.php | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/api/v1/_submissions/BackendSubmissionsHandler.php b/api/v1/_submissions/BackendSubmissionsHandler.php index 137f3314a03..22594bfcd97 100644 --- a/api/v1/_submissions/BackendSubmissionsHandler.php +++ b/api/v1/_submissions/BackendSubmissionsHandler.php @@ -129,6 +129,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']); } } /** @var NewReleaseDAO */ @@ -179,10 +180,9 @@ public function saveFeaturedOrder($slimRequest, $response, $args) } /** @var FeatureDAO */ $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']); } } diff --git a/classes/press/FeatureDAO.php b/classes/press/FeatureDAO.php index 0b479399965..33bd301407a 100644 --- a/classes/press/FeatureDAO.php +++ b/classes/press/FeatureDAO.php @@ -216,19 +216,17 @@ public 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; }