Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When sorting achievements, make level achievements last. #2643

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion templates/HelpFiles/InstructorAchievementList.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</p>
<p>
<%= maketext('Achievements are evaluated in the order shown below, with the exception of "level" achievements. '
. 'Achievements in the "level" category are evaluated first and control the XP thresholds and rewards '
. 'Achievements in the "level" category are evaluated last and control the XP thresholds and rewards '
. '(achievement items) for reaching each level. Achievements in the "secret" category are not shown to '
. 'students until they earn the achievement, and is used for fun/surprise achievements.') =%>
</p>
Expand Down