Skip to content

Commit

Permalink
Course Progress: Fix sorting for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Mar 10, 2024
1 parent a8679cf commit b757dbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion public/main/course_progress/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ function update_done_thematic_advance(selected_value) {
['class' => 'btn btn--plain']
);
if (0 == api_get_session_id()) {
$currentOrder = $thematic->getResourceNode()->getDisplayOrder();
$link = $thematic->getResourceNode()->getResourceLinkByContext($course, $session);
$currentOrder = $link ? $link->getDisplayOrder() : 0;
$moveButtons = $thematicManager->getMoveActions($id, $currentOrder, count($thematic_data));
$toolbarThematic .= $moveButtons;
}
Expand Down
12 changes: 8 additions & 4 deletions public/main/inc/lib/thematic.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ public function moveThematic(string $direction, int $thematicId, Course $course,
return false;
}

$currentDisplayOrder = $resourceNode->getDisplayOrder();
$link = $resourceNode->getResourceLinkByContext($course, $session);

$newPosition = $currentDisplayOrder + ($direction === 'down' ? 1 : -1);
$newPosition = max(0, $newPosition);
if (!$link) {
return false;
}

$currentDisplayOrder = $link->getDisplayOrder();

$link->setDisplayOrder('down' === $direction ? $currentDisplayOrder + 1 : $currentDisplayOrder - 1);

$resourceNode->setDisplayOrder($newPosition);
$em->flush();

// update done advances with de current thematic list
Expand Down

0 comments on commit b757dbb

Please sign in to comment.