Skip to content

Commit d1dcf0b

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

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,23 @@ public function lock($locked)
633633
*/
634634
public static function getCurrentUserRanking($userId, $studentList)
635635
{
636+
$previousScore = null;
636637
$ranking = null;
638+
$position = null;
637639
$currentUserId = $userId;
638640
if (!empty($studentList) && !empty($currentUserId)) {
639641
$studentList = array_map('floatval', $studentList);
640-
asort($studentList);
641-
$ranking = $count = count($studentList);
642-
643-
foreach ($studentList as $userId => $position) {
642+
arsort($studentList);
643+
$count = count($studentList);
644+
foreach ($studentList as $userId => $score) {
645+
$position++;
646+
if ($previousScore === null || $score < $previousScore) {
647+
$ranking = $position;
648+
}
649+
$previousScore = $score;
644650
if ($currentUserId == $userId) {
645651
break;
646652
}
647-
$ranking--;
648653
}
649654

650655
// If no ranking was detected.

0 commit comments

Comments
 (0)