File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
public/main/gradebook/lib/be Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -665,18 +665,23 @@ public function lock($locked)
665
665
*/
666
666
public static function getCurrentUserRanking ($ userId , $ studentList )
667
667
{
668
+ $ previousScore = null ;
668
669
$ ranking = null ;
670
+ $ position = null ;
669
671
$ currentUserId = $ userId ;
670
672
if (!empty ($ studentList ) && !empty ($ currentUserId )) {
671
673
$ 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 ;
676
682
if ($ currentUserId == $ userId ) {
677
683
break ;
678
684
}
679
- $ ranking --;
680
685
}
681
686
682
687
// If no ranking was detected.
You can’t perform that action at this time.
0 commit comments