File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -633,18 +633,23 @@ public function lock($locked)
633
633
*/
634
634
public static function getCurrentUserRanking ($ userId , $ studentList )
635
635
{
636
+ $ previousScore = null ;
636
637
$ ranking = null ;
638
+ $ position = null ;
637
639
$ currentUserId = $ userId ;
638
640
if (!empty ($ studentList ) && !empty ($ currentUserId )) {
639
641
$ 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 ;
644
650
if ($ currentUserId == $ userId ) {
645
651
break ;
646
652
}
647
- $ ranking --;
648
653
}
649
654
650
655
// If no ranking was detected.
You can’t perform that action at this time.
0 commit comments