diff --git a/api/v1/_submissions/BackendSubmissionsHandler.inc.php b/api/v1/_submissions/BackendSubmissionsHandler.inc.php index a3dd6cea028..4b5c8498f78 100644 --- a/api/v1/_submissions/BackendSubmissionsHandler.inc.php +++ b/api/v1/_submissions/BackendSubmissionsHandler.inc.php @@ -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']); } } @@ -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']); } } diff --git a/classes/press/FeatureDAO.inc.php b/classes/press/FeatureDAO.inc.php index 8aed73c3f0c..2dc7c90accb 100644 --- a/classes/press/FeatureDAO.inc.php +++ b/classes/press/FeatureDAO.inc.php @@ -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) { @@ -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; }