Skip to content

Commit

Permalink
Merge pull request #1737 from kaitlinnewson/6088-3_3_0
Browse files Browse the repository at this point in the history
pkp/pkp-lib#6088 set sequence for featured monographs
  • Loading branch information
bozana authored Oct 23, 2024
2 parents d14c709 + 6ba854c commit a8b4597
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
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

0 comments on commit a8b4597

Please sign in to comment.