Skip to content

Commit

Permalink
When sorting achievements, make level achievements last.
Browse files Browse the repository at this point in the history
Level achievements need to be processed last, and currently an
instructor can edit achievement numbers which could place some
achievements after the level achievements.

Update the sortAchievements utility method to always place level
achievements at the end of the list.
  • Loading branch information
somiaj committed Dec 16, 2024
1 parent e9ef2fa commit 57a03ab
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,21 @@ sub sortAchievements (@achievements) {
# Next sort by number.
@achievements = sort { ($a->number || 0) <=> ($b->number || 0) } @achievements;

# Finally sort by category.
# Finally sort by category. Always place level achievements last.
@achievements = sort {
if ($a->number && $b->number) {
if ($a->{category} eq 'level' && $b->{category} eq 'level') {
return 0;
} elsif ($a->{category} eq 'level') {
return 1;
} elsif ($b->{category} eq 'level') {
return -1;
} elsif ($a->number && $b->number) {
return $a->number <=> $b->number;
} elsif ($a->{category} eq $b->{category}) {
return 0;
} elsif ($a->{category} eq 'secret' or $b->{category} eq 'level') {
} elsif ($a->{category} eq 'secret') {
return -1;
} elsif ($a->{category} eq 'level' or $b->{category} eq 'secret') {
} elsif ($b->{category} eq 'secret') {
return 1;
} else {
return $a->{category} cmp $b->{category};
Expand Down

0 comments on commit 57a03ab

Please sign in to comment.