From e5fbbe24cd4826bd70d9265b0cfb9841a7eccb7a Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sun, 15 Dec 2024 17:41:26 -0700 Subject: [PATCH 1/2] When sorting achievements, make level achievements last. 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. --- lib/WeBWorK/Utils.pm | 14 ++++++++++---- .../HelpFiles/InstructorAchievementList.html.ep | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/WeBWorK/Utils.pm b/lib/WeBWorK/Utils.pm index e4aa20694d..86c7b892ea 100644 --- a/lib/WeBWorK/Utils.pm +++ b/lib/WeBWorK/Utils.pm @@ -225,15 +225,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}; diff --git a/templates/HelpFiles/InstructorAchievementList.html.ep b/templates/HelpFiles/InstructorAchievementList.html.ep index dc3db86284..078a882a5d 100644 --- a/templates/HelpFiles/InstructorAchievementList.html.ep +++ b/templates/HelpFiles/InstructorAchievementList.html.ep @@ -24,7 +24,7 @@

<%= 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.') =%>

From 555cb4ec7f7816bd4e871c1ef68f462afd692041 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Mon, 17 Feb 2025 17:32:14 -0700 Subject: [PATCH 2/2] Clarify that level achievements are listed and evaluated last. --- templates/HelpFiles/InstructorAchievementList.html.ep | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/HelpFiles/InstructorAchievementList.html.ep b/templates/HelpFiles/InstructorAchievementList.html.ep index 078a882a5d..b6ce1e7b5c 100644 --- a/templates/HelpFiles/InstructorAchievementList.html.ep +++ b/templates/HelpFiles/InstructorAchievementList.html.ep @@ -20,7 +20,7 @@ <%= maketext('Manage achievements for the course. The actions allow one to edit, assign, import, export, score, ' . 'create, or delete achievements. The action form is at the top to select the desired action and options to ' . 'perform when the submit button is pressed. Below the action form is the list of all the ' - . 'achievements, ordered by their achievement "Number".') =%> + . 'achievements, ordered by their achievement "Number", with "level" achievements listed last.') =%>

<%= maketext('Achievements are evaluated in the order shown below, with the exception of "level" achievements. ' @@ -52,7 +52,8 @@

  • <%= maketext('Number:') %> - <%= maketext('Sets the order in which achievements are listed and evaluated.') =%> + <%= maketext('Sets the order in which achievements are listed and evaluated. Achievements in the "level" ' + . 'category are always listed and evaluated after all other achievements.') =%>
  • <%= maketext('Enabled:') %>