Skip to content

Commit 64b3aa1

Browse files
committed
Gradebook: #fix ranking calculation to show same position for users with the same score - refs BT#22990
1 parent e324b42 commit 64b3aa1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

public/main/gradebook/lib/be/abstractlink.class.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,18 +665,23 @@ public function lock($locked)
665665
*/
666666
public static function getCurrentUserRanking($userId, $studentList)
667667
{
668+
$previousScore = null;
668669
$ranking = null;
670+
$position = null;
669671
$currentUserId = $userId;
670672
if (!empty($studentList) && !empty($currentUserId)) {
671673
$studentList = array_map('floatval', $studentList);
672-
asort($studentList);
673-
$ranking = $count = count($studentList);
674-
675-
foreach ($studentList as $userId => $position) {
674+
arsort($studentList);
675+
$count = count($studentList);
676+
foreach ($studentList as $userId => $score) {
677+
$position++;
678+
if ($previousScore === null || $score < $previousScore) {
679+
$ranking = $position;
680+
}
681+
$previousScore = $score;
676682
if ($currentUserId == $userId) {
677683
break;
678684
}
679-
$ranking--;
680685
}
681686

682687
// If no ranking was detected.

0 commit comments

Comments
 (0)